2023-06-05 00:16:05 +01:00
|
|
|
/* SPDX-License-Identifier: MPL-2.0 */
|
2013-10-30 16:03:27 +01:00
|
|
|
|
2016-02-12 15:46:55 +01:00
|
|
|
#include "testutil.hpp"
|
2018-12-07 07:51:30 -05:00
|
|
|
#include "testutil_unity.hpp"
|
2013-10-30 16:03:27 +01:00
|
|
|
|
2019-03-24 12:51:28 -04:00
|
|
|
SETUP_TEARDOWN_TESTCONTEXT
|
2013-10-30 16:03:27 +01:00
|
|
|
|
2018-12-07 07:51:30 -05:00
|
|
|
// TODO this is heavily duplicated with test_reqrep_device.cpp
|
|
|
|
void test_roundtrip ()
|
|
|
|
{
|
2013-10-30 16:03:27 +01:00
|
|
|
// Create a req/rep device.
|
2018-12-07 07:51:30 -05:00
|
|
|
void *dealer = test_context_socket (ZMQ_DEALER);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (dealer, "tipc://{5560,0,0}"));
|
|
|
|
void *router = test_context_socket (ZMQ_ROUTER);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (router, "tipc://{5561,0,0}"));
|
2013-10-30 16:03:27 +01:00
|
|
|
|
|
|
|
// Create a worker.
|
2018-12-07 07:51:30 -05:00
|
|
|
void *rep = test_context_socket (ZMQ_REP);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (rep, "tipc://{5560,0}@0.0.0"));
|
2013-10-30 16:03:27 +01:00
|
|
|
|
|
|
|
// Create a client.
|
2018-12-07 07:51:30 -05:00
|
|
|
void *req = test_context_socket (ZMQ_REQ);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (req, "tipc://{5561,0}@0.0.0"));
|
2013-10-30 16:03:27 +01:00
|
|
|
|
|
|
|
// Send a request.
|
2018-12-07 07:51:30 -05:00
|
|
|
send_string_expect_success (req, "ABC", ZMQ_SNDMORE);
|
|
|
|
send_string_expect_success (req, "DEF", 0);
|
2013-10-30 16:03:27 +01:00
|
|
|
|
|
|
|
// Pass the request through the device.
|
|
|
|
for (int i = 0; i != 4; i++) {
|
|
|
|
zmq_msg_t msg;
|
2018-12-07 07:51:30 -05:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg));
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, router, 0));
|
2013-10-30 16:03:27 +01:00
|
|
|
int rcvmore;
|
|
|
|
size_t sz = sizeof (rcvmore);
|
2018-12-07 07:51:30 -05:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (
|
|
|
|
zmq_getsockopt (router, ZMQ_RCVMORE, &rcvmore, &sz));
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (
|
|
|
|
zmq_msg_send (&msg, dealer, rcvmore ? ZMQ_SNDMORE : 0));
|
2013-10-30 16:03:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Receive the request.
|
2018-12-07 07:51:30 -05:00
|
|
|
recv_string_expect_success (rep, "ABC", 0);
|
2013-10-30 16:03:27 +01:00
|
|
|
int rcvmore;
|
|
|
|
size_t sz = sizeof (rcvmore);
|
2018-12-07 07:51:30 -05:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (
|
|
|
|
zmq_getsockopt (rep, ZMQ_RCVMORE, &rcvmore, &sz));
|
|
|
|
TEST_ASSERT_TRUE (rcvmore);
|
|
|
|
recv_string_expect_success (rep, "DEF", 0);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (
|
|
|
|
zmq_getsockopt (rep, ZMQ_RCVMORE, &rcvmore, &sz));
|
|
|
|
TEST_ASSERT_FALSE (rcvmore);
|
2013-10-30 16:03:27 +01:00
|
|
|
|
|
|
|
// Send the reply.
|
2018-12-07 07:51:30 -05:00
|
|
|
send_string_expect_success (rep, "GHI", ZMQ_SNDMORE);
|
|
|
|
send_string_expect_success (rep, "JKL", 0);
|
2013-10-30 16:03:27 +01:00
|
|
|
|
|
|
|
// Pass the reply through the device.
|
|
|
|
for (int i = 0; i != 4; i++) {
|
|
|
|
zmq_msg_t msg;
|
2018-12-07 07:51:30 -05:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg));
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, dealer, 0));
|
2013-10-30 16:03:27 +01:00
|
|
|
int rcvmore;
|
2018-12-07 07:51:30 -05:00
|
|
|
size_t sz = sizeof (rcvmore);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (
|
|
|
|
zmq_getsockopt (dealer, ZMQ_RCVMORE, &rcvmore, &sz));
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (
|
|
|
|
zmq_msg_send (&msg, router, rcvmore ? ZMQ_SNDMORE : 0));
|
2013-10-30 16:03:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Receive the reply.
|
2018-12-07 07:51:30 -05:00
|
|
|
recv_string_expect_success (req, "GHI", 0);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (
|
|
|
|
zmq_getsockopt (req, ZMQ_RCVMORE, &rcvmore, &sz));
|
|
|
|
TEST_ASSERT_TRUE (rcvmore);
|
|
|
|
recv_string_expect_success (req, "JKL", 0);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (
|
|
|
|
zmq_getsockopt (req, ZMQ_RCVMORE, &rcvmore, &sz));
|
|
|
|
TEST_ASSERT_FALSE (rcvmore);
|
2013-10-30 16:03:27 +01:00
|
|
|
|
|
|
|
// Clean up.
|
2018-12-07 07:51:30 -05:00
|
|
|
test_context_socket_close (req);
|
|
|
|
test_context_socket_close (rep);
|
|
|
|
test_context_socket_close (router);
|
|
|
|
test_context_socket_close (dealer);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
if (!is_tipc_available ()) {
|
|
|
|
printf ("TIPC environment unavailable, skipping test\n");
|
|
|
|
return 77;
|
|
|
|
}
|
|
|
|
|
|
|
|
UNITY_BEGIN ();
|
|
|
|
RUN_TEST (test_roundtrip);
|
|
|
|
return UNITY_END ();
|
2013-10-30 16:03:27 +01:00
|
|
|
}
|