mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-09 15:26:04 +00:00
Problem: test_udp not using unity
Solution: migrate to unity, merge into test_radio_dish, and split up test cases
This commit is contained in:
parent
dc2764f58c
commit
6d89635f9a
@ -855,7 +855,6 @@ test_apps += tests/test_poller \
|
||||
tests/test_thread_safe \
|
||||
tests/test_timers \
|
||||
tests/test_radio_dish \
|
||||
tests/test_udp \
|
||||
tests/test_scatter_gather \
|
||||
tests/test_dgram \
|
||||
tests/test_app_meta
|
||||
@ -879,9 +878,6 @@ tests_test_radio_dish_SOURCES = tests/test_radio_dish.cpp
|
||||
tests_test_radio_dish_LDADD = src/libzmq.la ${UNITY_LIBS}
|
||||
tests_test_radio_dish_CPPFLAGS = ${UNITY_CPPFLAGS}
|
||||
|
||||
tests_test_udp_SOURCES = tests/test_udp.cpp
|
||||
tests_test_udp_LDADD = src/libzmq.la
|
||||
|
||||
tests_test_scatter_gather_SOURCES = tests/test_scatter_gather.cpp
|
||||
tests_test_scatter_gather_LDADD = src/libzmq.la
|
||||
|
||||
|
@ -132,7 +132,6 @@ IF (ENABLE_DRAFTS)
|
||||
test_client_server
|
||||
test_timers
|
||||
test_radio_dish
|
||||
test_udp
|
||||
test_scatter_gather
|
||||
test_dgram
|
||||
test_app_meta
|
||||
|
@ -111,7 +111,7 @@ void test_join_twice_fails ()
|
||||
test_context_socket_close (dish);
|
||||
}
|
||||
|
||||
void test_radio_dish ()
|
||||
void test_radio_dish_tcp_poll ()
|
||||
{
|
||||
size_t len = MAX_SOCKET_STRING;
|
||||
char my_endpoint[MAX_SOCKET_STRING];
|
||||
@ -176,6 +176,48 @@ void test_radio_dish ()
|
||||
test_context_socket_close (radio);
|
||||
}
|
||||
|
||||
void test_dish_connect_fails ()
|
||||
{
|
||||
void *dish = test_context_socket (ZMQ_DISH);
|
||||
|
||||
// Connecting dish should fail
|
||||
TEST_ASSERT_FAILURE_ERRNO (ENOCOMPATPROTO,
|
||||
zmq_connect (dish, "udp://127.0.0.1:5556"));
|
||||
|
||||
test_context_socket_close (dish);
|
||||
}
|
||||
|
||||
void test_radio_bind_fails ()
|
||||
{
|
||||
void *radio = test_context_socket (ZMQ_RADIO);
|
||||
|
||||
// Connecting dish should fail
|
||||
// Bind radio should fail
|
||||
TEST_ASSERT_FAILURE_ERRNO (ENOCOMPATPROTO,
|
||||
zmq_bind (radio, "udp://*:5556"));
|
||||
|
||||
test_context_socket_close (radio);
|
||||
}
|
||||
|
||||
void test_radio_dish_udp ()
|
||||
{
|
||||
void *radio = test_context_socket (ZMQ_RADIO);
|
||||
void *dish = test_context_socket (ZMQ_DISH);
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (dish, "udp://*:5556"));
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (radio, "udp://127.0.0.1:5556"));
|
||||
|
||||
msleep (SETTLE_TIME);
|
||||
|
||||
TEST_ASSERT_SUCCESS_ERRNO (zmq_join (dish, "TV"));
|
||||
|
||||
msg_send_expect_success (radio, "TV", "Friends");
|
||||
msg_recv_cmp (dish, "TV", "Friends");
|
||||
|
||||
test_context_socket_close (dish);
|
||||
test_context_socket_close (radio);
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
setup_test_environment ();
|
||||
@ -184,6 +226,10 @@ int main (void)
|
||||
RUN_TEST (test_leave_unjoined_fails);
|
||||
RUN_TEST (test_join_too_long_fails);
|
||||
RUN_TEST (test_join_twice_fails);
|
||||
RUN_TEST (test_radio_dish);
|
||||
RUN_TEST (test_radio_bind_fails);
|
||||
RUN_TEST (test_dish_connect_fails);
|
||||
RUN_TEST (test_radio_dish_tcp_poll);
|
||||
RUN_TEST (test_radio_dish_udp);
|
||||
|
||||
return UNITY_END ();
|
||||
}
|
||||
|
@ -1,134 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
|
||||
|
||||
This file is part of libzmq, the ZeroMQ core engine in C++.
|
||||
|
||||
libzmq is free software; you can redistribute it and/or modify it under
|
||||
the terms of the GNU Lesser General Public License (LGPL) as published
|
||||
by the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
As a special exception, the Contributors give you permission to link
|
||||
this library with independent modules to produce an executable,
|
||||
regardless of the license terms of these independent modules, and to
|
||||
copy and distribute the resulting executable under terms of your choice,
|
||||
provided that you also meet, for each linked independent module, the
|
||||
terms and conditions of the license of that module. An independent
|
||||
module is a module which is not derived from or based on this library.
|
||||
If you modify this library, you must extend this exception to your
|
||||
version of the library.
|
||||
|
||||
libzmq is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||
License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "testutil.hpp"
|
||||
|
||||
int msg_send (zmq_msg_t *msg_, void *s_, const char *group_, const char *body_)
|
||||
{
|
||||
int rc = zmq_msg_init_size (msg_, strlen (body_));
|
||||
if (rc != 0)
|
||||
return rc;
|
||||
|
||||
memcpy (zmq_msg_data (msg_), body_, strlen (body_));
|
||||
|
||||
rc = zmq_msg_set_group (msg_, group_);
|
||||
if (rc != 0) {
|
||||
zmq_msg_close (msg_);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = zmq_msg_send (msg_, s_, 0);
|
||||
|
||||
zmq_msg_close (msg_);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int msg_recv_cmp (zmq_msg_t *msg_,
|
||||
void *s_,
|
||||
const char *group_,
|
||||
const char *body_)
|
||||
{
|
||||
int rc = zmq_msg_init (msg_);
|
||||
if (rc != 0)
|
||||
return -1;
|
||||
|
||||
int recv_rc = zmq_msg_recv (msg_, s_, 0);
|
||||
if (recv_rc == -1) {
|
||||
zmq_msg_close (msg_);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strcmp (zmq_msg_group (msg_), group_) != 0) {
|
||||
zmq_msg_close (msg_);
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *body = (char *) malloc (sizeof (char) * (zmq_msg_size (msg_) + 1));
|
||||
memcpy (body, zmq_msg_data (msg_), zmq_msg_size (msg_));
|
||||
body[zmq_msg_size (msg_)] = '\0';
|
||||
|
||||
if (strcmp (body, body_) != 0) {
|
||||
zmq_msg_close (msg_);
|
||||
free (body);
|
||||
return -1;
|
||||
}
|
||||
|
||||
zmq_msg_close (msg_);
|
||||
free (body);
|
||||
return recv_rc;
|
||||
}
|
||||
|
||||
int main (void)
|
||||
{
|
||||
setup_test_environment ();
|
||||
void *ctx = zmq_ctx_new ();
|
||||
assert (ctx);
|
||||
|
||||
zmq_msg_t msg;
|
||||
|
||||
void *radio = zmq_socket (ctx, ZMQ_RADIO);
|
||||
void *dish = zmq_socket (ctx, ZMQ_DISH);
|
||||
|
||||
// Connecting dish should fail
|
||||
int rc = zmq_connect (dish, "udp://127.0.0.1:5556");
|
||||
assert (rc == -1);
|
||||
|
||||
rc = zmq_bind (dish, "udp://*:5556");
|
||||
assert (rc == 0);
|
||||
|
||||
// Bind radio should fail
|
||||
rc = zmq_bind (radio, "udp://*:5556");
|
||||
assert (rc == -1);
|
||||
|
||||
rc = zmq_connect (radio, "udp://127.0.0.1:5556");
|
||||
assert (rc == 0);
|
||||
|
||||
msleep (SETTLE_TIME);
|
||||
|
||||
rc = zmq_join (dish, "TV");
|
||||
assert (rc == 0);
|
||||
|
||||
rc = msg_send (&msg, radio, "TV", "Friends");
|
||||
assert (rc != -1);
|
||||
|
||||
rc = msg_recv_cmp (&msg, dish, "TV", "Friends");
|
||||
assert (rc != -1);
|
||||
|
||||
rc = zmq_close (dish);
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_close (radio);
|
||||
assert (rc == 0);
|
||||
|
||||
rc = zmq_ctx_term (ctx);
|
||||
assert (rc == 0);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user