mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-14 02:57:47 +01:00
Problem: test_term_endpoint not yet using unity
Solution: migrate to unity
This commit is contained in:
parent
dce77fda68
commit
0fc2f0f073
@ -517,7 +517,8 @@ tests_test_last_endpoint_LDADD = src/libzmq.la ${UNITY_LIBS}
|
|||||||
tests_test_last_endpoint_CPPFLAGS = ${UNITY_CPPFLAGS}
|
tests_test_last_endpoint_CPPFLAGS = ${UNITY_CPPFLAGS}
|
||||||
|
|
||||||
tests_test_term_endpoint_SOURCES = tests/test_term_endpoint.cpp
|
tests_test_term_endpoint_SOURCES = tests/test_term_endpoint.cpp
|
||||||
tests_test_term_endpoint_LDADD = src/libzmq.la
|
tests_test_term_endpoint_LDADD = src/libzmq.la ${UNITY_LIBS}
|
||||||
|
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
|
||||||
|
@ -27,200 +27,165 @@
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "testutil.hpp"
|
#include "testutil.hpp"
|
||||||
|
#include "testutil_unity.hpp"
|
||||||
|
|
||||||
/* Use the worst case filename size for the buffer (+1 for trailing NUL) */
|
void setUp ()
|
||||||
|
{
|
||||||
|
setup_test_context ();
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDown ()
|
||||||
|
{
|
||||||
|
teardown_test_context ();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Use the worst case filename size for the buffer (+1 for trailing NUL), this
|
||||||
|
* is larger than MAX_SOCKET_STRING, which is not large enough for IPC */
|
||||||
#define BUF_SIZE (FILENAME_MAX + 1)
|
#define BUF_SIZE (FILENAME_MAX + 1)
|
||||||
|
|
||||||
int main (void)
|
const char *ep_wc_tcp = "tcp://127.0.0.1:*";
|
||||||
{
|
|
||||||
setup_test_environment ();
|
|
||||||
int rc;
|
|
||||||
char buf[BUF_SIZE];
|
|
||||||
size_t buf_size;
|
|
||||||
const char *ep_wc_tcp = "tcp://127.0.0.1:*";
|
|
||||||
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
|
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
|
||||||
const char *ep_wc_ipc = "ipc://*";
|
const char *ep_wc_ipc = "ipc://*";
|
||||||
#endif
|
#endif
|
||||||
#if defined ZMQ_HAVE_VMCI
|
#if defined ZMQ_HAVE_VMCI
|
||||||
const char *ep_wc_vmci = "vmci://*:*";
|
const char *ep_wc_vmci = "vmci://*:*";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void test_send_after_unbind_fails ()
|
||||||
|
{
|
||||||
|
char my_endpoint[BUF_SIZE];
|
||||||
|
|
||||||
// Create infrastructure.
|
// Create infrastructure.
|
||||||
void *ctx = zmq_ctx_new ();
|
void *push = test_context_socket (ZMQ_PUSH);
|
||||||
assert (ctx);
|
bind_loopback_ipv4 (push, my_endpoint, BUF_SIZE);
|
||||||
void *push = zmq_socket (ctx, ZMQ_PUSH);
|
|
||||||
assert (push);
|
void *pull = test_context_socket (ZMQ_PULL);
|
||||||
rc = zmq_bind (push, ep_wc_tcp);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (pull, my_endpoint));
|
||||||
assert (rc == 0);
|
|
||||||
buf_size = sizeof (buf);
|
|
||||||
rc = zmq_getsockopt (push, ZMQ_LAST_ENDPOINT, buf, &buf_size);
|
|
||||||
assert (rc == 0);
|
|
||||||
void *pull = zmq_socket (ctx, ZMQ_PULL);
|
|
||||||
assert (pull);
|
|
||||||
rc = zmq_connect (pull, buf);
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
// Pass one message through to ensure the connection is established
|
// Pass one message through to ensure the connection is established
|
||||||
rc = zmq_send (push, "ABC", 3, 0);
|
send_string_expect_success (push, "ABC", 0);
|
||||||
assert (rc == 3);
|
recv_string_expect_success (pull, "ABC", 0);
|
||||||
rc = zmq_recv (pull, buf, sizeof (buf), 0);
|
|
||||||
assert (rc == 3);
|
|
||||||
|
|
||||||
// Unbind the listening endpoint
|
// Unbind the listening endpoint
|
||||||
buf_size = sizeof (buf);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (push, my_endpoint));
|
||||||
rc = zmq_getsockopt (push, ZMQ_LAST_ENDPOINT, buf, &buf_size);
|
|
||||||
assert (rc == 0);
|
|
||||||
rc = zmq_unbind (push, buf);
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
// Allow unbind to settle
|
// Allow unbind to settle
|
||||||
msleep (SETTLE_TIME);
|
msleep (SETTLE_TIME);
|
||||||
|
|
||||||
// Check that sending would block (there's no outbound connection)
|
// Check that sending would block (there's no outbound connection)
|
||||||
rc = zmq_send (push, "ABC", 3, ZMQ_DONTWAIT);
|
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_send (push, "ABC", 3, ZMQ_DONTWAIT));
|
||||||
assert (rc == -1 && zmq_errno () == EAGAIN);
|
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
rc = zmq_close (pull);
|
test_context_socket_close (pull);
|
||||||
assert (rc == 0);
|
test_context_socket_close (push);
|
||||||
rc = zmq_close (push);
|
}
|
||||||
assert (rc == 0);
|
|
||||||
rc = zmq_ctx_term (ctx);
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
|
void test_send_after_disconnect_fails ()
|
||||||
|
{
|
||||||
// Create infrastructure
|
// Create infrastructure
|
||||||
ctx = zmq_ctx_new ();
|
void *pull = test_context_socket (ZMQ_PULL);
|
||||||
assert (ctx);
|
char my_endpoint[BUF_SIZE];
|
||||||
pull = zmq_socket (ctx, ZMQ_PULL);
|
bind_loopback_ipv4 (pull, my_endpoint, BUF_SIZE);
|
||||||
assert (pull);
|
|
||||||
rc = zmq_bind (pull, ep_wc_tcp);
|
void *push = test_context_socket (ZMQ_PUSH);
|
||||||
assert (rc == 0);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (push, my_endpoint));
|
||||||
buf_size = sizeof (buf);
|
|
||||||
rc = zmq_getsockopt (pull, ZMQ_LAST_ENDPOINT, buf, &buf_size);
|
|
||||||
assert (rc == 0);
|
|
||||||
push = zmq_socket (ctx, ZMQ_PUSH);
|
|
||||||
assert (push);
|
|
||||||
rc = zmq_connect (push, buf);
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
// Pass one message through to ensure the connection is established.
|
// Pass one message through to ensure the connection is established.
|
||||||
rc = zmq_send (push, "ABC", 3, 0);
|
send_string_expect_success (push, "ABC", 0);
|
||||||
assert (rc == 3);
|
recv_string_expect_success (pull, "ABC", 0);
|
||||||
rc = zmq_recv (pull, buf, sizeof (buf), 0);
|
|
||||||
assert (rc == 3);
|
|
||||||
|
|
||||||
// Disconnect the bound endpoint
|
// Disconnect the bound endpoint
|
||||||
buf_size = sizeof (buf);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (push, my_endpoint));
|
||||||
rc = zmq_getsockopt (pull, ZMQ_LAST_ENDPOINT, buf, &buf_size);
|
|
||||||
assert (rc == 0);
|
|
||||||
rc = zmq_disconnect (push, buf);
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
// Allow disconnect to settle
|
// Allow disconnect to settle
|
||||||
msleep (SETTLE_TIME);
|
msleep (SETTLE_TIME);
|
||||||
|
|
||||||
// Check that sending would block (there's no inbound connections).
|
// Check that sending would block (there's no inbound connections).
|
||||||
rc = zmq_send (push, "ABC", 3, ZMQ_DONTWAIT);
|
TEST_ASSERT_FAILURE_ERRNO (EAGAIN, zmq_send (push, "ABC", 3, ZMQ_DONTWAIT));
|
||||||
assert (rc == -1 && zmq_errno () == EAGAIN);
|
|
||||||
|
|
||||||
// Clean up.
|
// Clean up
|
||||||
rc = zmq_close (pull);
|
test_context_socket_close (pull);
|
||||||
assert (rc == 0);
|
test_context_socket_close (push);
|
||||||
rc = zmq_close (push);
|
}
|
||||||
assert (rc == 0);
|
|
||||||
rc = zmq_ctx_term (ctx);
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
|
void test_unbind_via_last_endpoint ()
|
||||||
|
{
|
||||||
// Create infrastructure (wild-card binding)
|
// Create infrastructure (wild-card binding)
|
||||||
ctx = zmq_ctx_new ();
|
void *push = test_context_socket (ZMQ_PUSH);
|
||||||
assert (ctx);
|
char my_endpoint[BUF_SIZE];
|
||||||
push = zmq_socket (ctx, ZMQ_PUSH);
|
bind_loopback_ipv4 (push, my_endpoint, BUF_SIZE);
|
||||||
assert (push);
|
|
||||||
rc = zmq_bind (push, ep_wc_tcp);
|
void *pull = test_context_socket (ZMQ_PULL);
|
||||||
assert (rc == 0);
|
|
||||||
pull = zmq_socket (ctx, ZMQ_PULL);
|
|
||||||
assert (pull);
|
|
||||||
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
|
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
|
||||||
rc = zmq_bind (pull, ep_wc_ipc);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pull, ep_wc_ipc));
|
||||||
assert (rc == 0);
|
|
||||||
#endif
|
#endif
|
||||||
#if defined ZMQ_HAVE_VMCI
|
#if defined ZMQ_HAVE_VMCI
|
||||||
void *req = zmq_socket (ctx, ZMQ_REQ);
|
void *req = test_context_socket (ZMQ_REQ);
|
||||||
assert (req);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (req, ep_wc_vmci));
|
||||||
rc = zmq_bind (req, ep_wc_vmci);
|
|
||||||
assert (rc == 0);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Unbind sockets binded by wild-card address
|
// Unbind sockets binded by wild-card address
|
||||||
buf_size = sizeof (buf);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (push, my_endpoint));
|
||||||
rc = zmq_getsockopt (push, ZMQ_LAST_ENDPOINT, buf, &buf_size);
|
|
||||||
assert (rc == 0);
|
size_t buf_size = 0;
|
||||||
rc = zmq_unbind (push, buf);
|
(void) buf_size;
|
||||||
assert (rc == 0);
|
|
||||||
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
|
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
|
||||||
buf_size = sizeof (buf);
|
buf_size = sizeof (my_endpoint);
|
||||||
rc = zmq_getsockopt (pull, ZMQ_LAST_ENDPOINT, buf, &buf_size);
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
assert (rc == 0);
|
zmq_getsockopt (pull, ZMQ_LAST_ENDPOINT, my_endpoint, &buf_size));
|
||||||
rc = zmq_unbind (pull, buf);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (pull, my_endpoint));
|
||||||
assert (rc == 0);
|
|
||||||
#endif
|
#endif
|
||||||
#if defined ZMQ_HAVE_VMCI
|
#if defined ZMQ_HAVE_VMCI
|
||||||
buf_size = sizeof (buf);
|
buf_size = sizeof (my_endpoint);
|
||||||
rc = zmq_getsockopt (req, ZMQ_LAST_ENDPOINT, buf, &buf_size);
|
TEST_ASSERT_SUCCESS_ERRNO (
|
||||||
assert (rc == 0);
|
zmq_getsockopt (req, ZMQ_LAST_ENDPOINT, my_endpoint, &buf_size));
|
||||||
rc = zmq_unbind (req, buf);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (req, my_endpoint));
|
||||||
assert (rc == 0);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Clean up.
|
// Clean up
|
||||||
rc = zmq_close (pull);
|
test_context_socket_close (pull);
|
||||||
assert (rc == 0);
|
test_context_socket_close (push);
|
||||||
rc = zmq_close (push);
|
}
|
||||||
assert (rc == 0);
|
|
||||||
rc = zmq_ctx_term (ctx);
|
|
||||||
assert (rc == 0);
|
|
||||||
|
|
||||||
|
void test_wildcard_unbind_fails ()
|
||||||
|
{
|
||||||
// Create infrastructure (wild-card binding)
|
// Create infrastructure (wild-card binding)
|
||||||
ctx = zmq_ctx_new ();
|
void *push = test_context_socket (ZMQ_PUSH);
|
||||||
assert (ctx);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (push, ep_wc_tcp));
|
||||||
push = zmq_socket (ctx, ZMQ_PUSH);
|
void *pull = test_context_socket (ZMQ_PULL);
|
||||||
assert (push);
|
|
||||||
rc = zmq_bind (push, ep_wc_tcp);
|
|
||||||
assert (rc == 0);
|
|
||||||
pull = zmq_socket (ctx, ZMQ_PULL);
|
|
||||||
assert (pull);
|
|
||||||
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
|
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
|
||||||
rc = zmq_bind (pull, ep_wc_ipc);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (pull, ep_wc_ipc));
|
||||||
assert (rc == 0);
|
|
||||||
#endif
|
#endif
|
||||||
#if defined ZMQ_HAVE_VMCI
|
#if defined ZMQ_HAVE_VMCI
|
||||||
req = zmq_socket (ctx, ZMQ_REQ);
|
void *req = test_context_socket (ZMQ_REQ);
|
||||||
assert (req);
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (req, ep_wc_vmci));
|
||||||
rc = zmq_bind (req, ep_wc_vmci);
|
|
||||||
assert (rc == 0);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Sockets binded by wild-card address can't be unbinded by wild-card address
|
// Sockets binded by wild-card address can't be unbinded by wild-card address
|
||||||
rc = zmq_unbind (push, ep_wc_tcp);
|
TEST_ASSERT_FAILURE_ERRNO (ENOENT, zmq_unbind (push, ep_wc_tcp));
|
||||||
assert (rc == -1 && zmq_errno () == ENOENT);
|
|
||||||
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
|
#if !defined ZMQ_HAVE_WINDOWS && !defined ZMQ_HAVE_OPENVMS
|
||||||
rc = zmq_unbind (pull, ep_wc_ipc);
|
TEST_ASSERT_FAILURE_ERRNO (ENOENT, zmq_unbind (pull, ep_wc_ipc));
|
||||||
assert (rc == -1 && zmq_errno () == ENOENT);
|
|
||||||
#endif
|
#endif
|
||||||
#if defined ZMQ_HAVE_VMCI
|
#if defined ZMQ_HAVE_VMCI
|
||||||
rc = zmq_unbind (req, ep_wc_vmci);
|
TEST_ASSERT_FAILURE_ERRNO (ENOENT, zmq_unbind (req, ep_wc_vmci));
|
||||||
assert (rc == -1 && zmq_errno () == ENOENT);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Clean up.
|
// Clean up
|
||||||
rc = zmq_close (pull);
|
test_context_socket_close (pull);
|
||||||
assert (rc == 0);
|
test_context_socket_close (push);
|
||||||
rc = zmq_close (push);
|
}
|
||||||
assert (rc == 0);
|
|
||||||
rc = zmq_ctx_term (ctx);
|
int main ()
|
||||||
assert (rc == 0);
|
{
|
||||||
|
setup_test_environment ();
|
||||||
return 0;
|
|
||||||
|
UNITY_BEGIN ();
|
||||||
|
RUN_TEST (test_send_after_unbind_fails);
|
||||||
|
RUN_TEST (test_send_after_disconnect_fails);
|
||||||
|
RUN_TEST (test_unbind_via_last_endpoint);
|
||||||
|
RUN_TEST (test_wildcard_unbind_fails);
|
||||||
|
return UNITY_END ();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user