2023-06-05 00:16:05 +01:00
|
|
|
/* SPDX-License-Identifier: MPL-2.0 */
|
2015-02-02 01:17:37 +02:00
|
|
|
|
|
|
|
#include "testutil.hpp"
|
2018-03-14 18:45:26 +01:00
|
|
|
#include "testutil_unity.hpp"
|
2015-02-02 01:17:37 +02:00
|
|
|
|
2019-03-24 12:51:28 -04:00
|
|
|
SETUP_TEARDOWN_TESTCONTEXT
|
2015-02-02 01:17:37 +02:00
|
|
|
|
2018-05-27 07:01:36 -04:00
|
|
|
void create_inproc_client_server_pair (void **server_, void **client_)
|
2018-03-14 18:45:26 +01:00
|
|
|
{
|
2018-05-27 07:01:36 -04:00
|
|
|
*server_ = test_context_socket (ZMQ_SERVER);
|
|
|
|
*client_ = test_context_socket (ZMQ_CLIENT);
|
2015-02-02 01:17:37 +02:00
|
|
|
|
2018-03-14 18:45:26 +01:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (
|
2018-05-27 07:01:36 -04:00
|
|
|
zmq_bind (*server_, "inproc://test-client-server"));
|
2018-03-14 18:45:26 +01:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (
|
2018-05-27 07:01:36 -04:00
|
|
|
zmq_connect (*client_, "inproc://test-client-server"));
|
2018-03-14 18:56:50 +01:00
|
|
|
}
|
2015-02-02 01:17:37 +02:00
|
|
|
|
2018-05-27 07:01:36 -04:00
|
|
|
void send_sndmore_expect_failure (void *socket_)
|
2018-03-14 18:56:50 +01:00
|
|
|
{
|
2018-05-27 07:01:36 -04:00
|
|
|
int rc = zmq_send (socket_, "X", 1, ZMQ_SNDMORE);
|
2018-03-14 18:56:50 +01:00
|
|
|
TEST_ASSERT_EQUAL_INT (-1, rc);
|
|
|
|
TEST_ASSERT_EQUAL_INT (EINVAL, errno);
|
|
|
|
}
|
2015-02-02 01:17:37 +02:00
|
|
|
|
2018-03-14 18:56:50 +01:00
|
|
|
void test_client_sndmore_fails ()
|
|
|
|
{
|
|
|
|
void *server, *client;
|
|
|
|
create_inproc_client_server_pair (&server, &client);
|
2015-02-02 01:17:37 +02:00
|
|
|
|
2018-03-14 18:56:50 +01:00
|
|
|
send_sndmore_expect_failure (client);
|
2015-12-29 17:00:06 +01:00
|
|
|
|
2018-03-14 18:56:50 +01:00
|
|
|
test_context_socket_close (server);
|
|
|
|
test_context_socket_close (client);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_server_sndmore_fails ()
|
|
|
|
{
|
|
|
|
void *server, *client;
|
|
|
|
create_inproc_client_server_pair (&server, &client);
|
|
|
|
|
|
|
|
send_sndmore_expect_failure (server);
|
|
|
|
|
|
|
|
test_context_socket_close (server);
|
|
|
|
test_context_socket_close (client);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_routing_id ()
|
|
|
|
{
|
|
|
|
void *server, *client;
|
|
|
|
create_inproc_client_server_pair (&server, &client);
|
|
|
|
|
|
|
|
send_string_expect_success (client, "X", 0);
|
2015-02-02 01:17:37 +02:00
|
|
|
|
2018-03-14 18:45:26 +01:00
|
|
|
uint32_t routing_id;
|
|
|
|
{
|
|
|
|
zmq_msg_t msg;
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg));
|
2015-12-29 17:00:06 +01:00
|
|
|
|
2018-03-14 18:45:26 +01:00
|
|
|
int rc = TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, server, 0));
|
|
|
|
TEST_ASSERT_EQUAL_INT (1, rc);
|
2015-02-02 01:17:37 +02:00
|
|
|
|
2018-03-14 18:45:26 +01:00
|
|
|
routing_id = zmq_msg_routing_id (&msg);
|
|
|
|
TEST_ASSERT_NOT_EQUAL (0, routing_id);
|
2015-02-02 01:17:37 +02:00
|
|
|
|
2018-03-14 18:45:26 +01:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg));
|
|
|
|
}
|
2015-02-02 01:17:37 +02:00
|
|
|
|
2018-03-14 18:45:26 +01:00
|
|
|
{
|
|
|
|
zmq_msg_t msg;
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_size (&msg, 1));
|
2015-02-02 01:17:37 +02:00
|
|
|
|
2019-12-08 14:26:57 +01:00
|
|
|
char *data = static_cast<char *> (zmq_msg_data (&msg));
|
2018-03-14 18:45:26 +01:00
|
|
|
data[0] = 2;
|
2015-02-02 01:17:37 +02:00
|
|
|
|
2018-03-14 18:45:26 +01:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_set_routing_id (&msg, routing_id));
|
2015-12-29 17:00:06 +01:00
|
|
|
|
2018-03-14 18:56:50 +01:00
|
|
|
int rc = zmq_msg_send (&msg, server, 0);
|
2018-03-14 18:45:26 +01:00
|
|
|
TEST_ASSERT_EQUAL_INT (1, rc);
|
|
|
|
}
|
2015-02-02 01:17:37 +02:00
|
|
|
|
2018-03-14 18:45:26 +01:00
|
|
|
{
|
|
|
|
zmq_msg_t msg;
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg));
|
2015-02-02 01:17:37 +02:00
|
|
|
|
2018-03-14 18:45:26 +01:00
|
|
|
int rc = zmq_msg_recv (&msg, client, 0);
|
|
|
|
TEST_ASSERT_EQUAL_INT (1, rc);
|
2016-01-19 20:05:22 +02:00
|
|
|
|
2018-03-14 18:45:26 +01:00
|
|
|
routing_id = zmq_msg_routing_id (&msg);
|
|
|
|
TEST_ASSERT_EQUAL_UINT32 (0, routing_id);
|
2015-07-21 19:42:20 -07:00
|
|
|
|
2018-03-14 18:45:26 +01:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg));
|
|
|
|
}
|
2015-02-02 01:17:37 +02:00
|
|
|
|
2018-03-14 18:45:26 +01:00
|
|
|
test_context_socket_close (server);
|
|
|
|
test_context_socket_close (client);
|
|
|
|
}
|
2015-02-02 01:17:37 +02:00
|
|
|
|
2018-03-14 18:45:26 +01:00
|
|
|
int main (void)
|
|
|
|
{
|
|
|
|
setup_test_environment ();
|
2015-02-02 01:17:37 +02:00
|
|
|
|
2018-03-14 18:45:26 +01:00
|
|
|
UNITY_BEGIN ();
|
2018-03-14 18:56:50 +01:00
|
|
|
RUN_TEST (test_client_sndmore_fails);
|
|
|
|
RUN_TEST (test_server_sndmore_fails);
|
|
|
|
RUN_TEST (test_routing_id);
|
2018-03-14 18:45:26 +01:00
|
|
|
return UNITY_END ();
|
2015-02-02 01:17:37 +02:00
|
|
|
}
|