2023-06-05 01:16:05 +02:00
|
|
|
/* SPDX-License-Identifier: MPL-2.0 */
|
2011-11-06 14:03:51 +01:00
|
|
|
|
2013-08-17 14:43:45 +02:00
|
|
|
#include "testutil.hpp"
|
2019-03-22 11:48:49 +01:00
|
|
|
#include "testutil_unity.hpp"
|
2011-11-06 14:03:51 +01:00
|
|
|
|
2019-03-24 17:51:28 +01:00
|
|
|
SETUP_TEARDOWN_TESTCONTEXT
|
2014-07-29 20:43:38 +02:00
|
|
|
|
2019-03-22 11:48:49 +01:00
|
|
|
void test_more ()
|
|
|
|
{
|
|
|
|
// Create the infrastructure
|
|
|
|
void *sb = test_context_socket (ZMQ_ROUTER);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "inproc://a"));
|
2014-07-29 20:43:38 +02:00
|
|
|
|
2019-03-22 11:48:49 +01:00
|
|
|
void *sc = test_context_socket (ZMQ_DEALER);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, "inproc://a"));
|
2014-07-29 20:43:38 +02:00
|
|
|
|
2011-11-06 14:03:51 +01:00
|
|
|
// Send 2-part message.
|
2019-03-22 11:48:49 +01:00
|
|
|
send_string_expect_success (sc, "A", ZMQ_SNDMORE);
|
|
|
|
send_string_expect_success (sc, "B", 0);
|
2011-11-06 14:03:51 +01:00
|
|
|
|
2017-09-07 11:21:13 +02:00
|
|
|
// Routing id comes first.
|
2011-11-06 14:03:51 +01:00
|
|
|
zmq_msg_t msg;
|
2019-03-22 11:48:49 +01:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg));
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, sb, 0));
|
|
|
|
TEST_ASSERT_EQUAL_INT (1, TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_more (&msg)));
|
2011-11-06 14:03:51 +01:00
|
|
|
|
|
|
|
// Then the first part of the message body.
|
2019-03-22 11:48:49 +01:00
|
|
|
TEST_ASSERT_EQUAL_INT (
|
|
|
|
1, TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, sb, 0)));
|
|
|
|
TEST_ASSERT_EQUAL_INT (1, TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_more (&msg)));
|
2011-11-06 14:03:51 +01:00
|
|
|
|
|
|
|
// And finally, the second part of the message body.
|
2019-03-22 11:48:49 +01:00
|
|
|
TEST_ASSERT_EQUAL_INT (
|
|
|
|
1, TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, sb, 0)));
|
|
|
|
TEST_ASSERT_EQUAL_INT (0, TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_more (&msg)));
|
|
|
|
|
|
|
|
// Deallocate the infrastructure.
|
|
|
|
test_context_socket_close (sc);
|
|
|
|
test_context_socket_close (sb);
|
|
|
|
}
|
2011-11-06 14:03:51 +01:00
|
|
|
|
2019-03-22 11:48:49 +01:00
|
|
|
void test_shared_refcounted ()
|
|
|
|
{
|
2014-07-29 20:43:38 +02:00
|
|
|
// Test ZMQ_SHARED property (case 1, refcounted messages)
|
2014-07-13 01:05:49 +02:00
|
|
|
zmq_msg_t msg_a;
|
2019-03-22 11:48:49 +01:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (
|
|
|
|
zmq_msg_init_size (&msg_a, 1024)); // large enough to be a type_lmsg
|
2014-07-13 01:05:49 +02:00
|
|
|
|
|
|
|
// Message is not shared
|
2019-03-22 11:48:49 +01:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_get (&msg_a, ZMQ_SHARED));
|
2014-07-13 01:05:49 +02:00
|
|
|
|
|
|
|
zmq_msg_t msg_b;
|
2019-03-22 11:48:49 +01:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg_b));
|
2014-07-13 01:05:49 +02:00
|
|
|
|
2019-03-22 11:48:49 +01:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_copy (&msg_b, &msg_a));
|
2014-07-13 01:05:49 +02:00
|
|
|
|
|
|
|
// Message is now shared
|
2019-03-22 11:48:49 +01:00
|
|
|
TEST_ASSERT_EQUAL_INT (
|
|
|
|
1, TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_get (&msg_b, ZMQ_SHARED)));
|
2014-07-13 01:05:49 +02:00
|
|
|
|
2014-07-29 20:43:38 +02:00
|
|
|
// cleanup
|
2019-03-22 11:48:49 +01:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg_a));
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg_b));
|
|
|
|
}
|
2014-07-29 20:43:38 +02:00
|
|
|
|
2019-03-22 11:48:49 +01:00
|
|
|
void test_shared_const ()
|
|
|
|
{
|
|
|
|
zmq_msg_t msg_a;
|
2014-07-29 20:43:38 +02:00
|
|
|
// Test ZMQ_SHARED property (case 2, constant data messages)
|
2019-03-22 11:48:49 +01:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (
|
|
|
|
zmq_msg_init_data (&msg_a, (void *) "TEST", 5, 0, 0));
|
2014-07-29 20:43:38 +02:00
|
|
|
|
|
|
|
// Message reports as shared
|
2019-03-22 11:48:49 +01:00
|
|
|
TEST_ASSERT_EQUAL_INT (
|
|
|
|
1, TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_get (&msg_a, ZMQ_SHARED)));
|
2014-07-29 20:43:38 +02:00
|
|
|
|
|
|
|
// cleanup
|
2019-03-22 11:48:49 +01:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg_a));
|
|
|
|
}
|
2014-07-29 20:43:38 +02:00
|
|
|
|
2019-03-22 11:48:49 +01:00
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
setup_test_environment ();
|
2014-07-29 20:43:38 +02:00
|
|
|
|
2019-03-22 11:48:49 +01:00
|
|
|
UNITY_BEGIN ();
|
|
|
|
RUN_TEST (test_more);
|
|
|
|
RUN_TEST (test_shared_refcounted);
|
|
|
|
RUN_TEST (test_shared_const);
|
|
|
|
return UNITY_END ();
|
2011-11-06 14:03:51 +01:00
|
|
|
}
|