2023-06-05 00:16:05 +01:00
|
|
|
/* SPDX-License-Identifier: MPL-2.0 */
|
2011-11-06 14:03:51 +01:00
|
|
|
|
2013-08-17 13:43:45 +01:00
|
|
|
#include "testutil.hpp"
|
2019-03-22 06:48:49 -04:00
|
|
|
#include "testutil_unity.hpp"
|
2011-11-06 14:03:51 +01:00
|
|
|
|
2019-03-24 12:51:28 -04:00
|
|
|
SETUP_TEARDOWN_TESTCONTEXT
|
2014-07-29 13:43:38 -05:00
|
|
|
|
2019-03-22 06:48:49 -04: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 13:43:38 -05:00
|
|
|
|
2019-03-22 06:48:49 -04:00
|
|
|
void *sc = test_context_socket (ZMQ_DEALER);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, "inproc://a"));
|
2014-07-29 13:43:38 -05:00
|
|
|
|
2011-11-06 14:03:51 +01:00
|
|
|
// Send 2-part message.
|
2019-03-22 06:48:49 -04: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 06:48:49 -04: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 06:48:49 -04: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 06:48:49 -04: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 06:48:49 -04:00
|
|
|
void test_shared_refcounted ()
|
|
|
|
{
|
2014-07-29 13:43:38 -05:00
|
|
|
// Test ZMQ_SHARED property (case 1, refcounted messages)
|
2014-07-12 18:05:49 -05:00
|
|
|
zmq_msg_t msg_a;
|
2019-03-22 06:48:49 -04:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (
|
|
|
|
zmq_msg_init_size (&msg_a, 1024)); // large enough to be a type_lmsg
|
2014-07-12 18:05:49 -05:00
|
|
|
|
|
|
|
// Message is not shared
|
2019-03-22 06:48:49 -04:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_get (&msg_a, ZMQ_SHARED));
|
2014-07-12 18:05:49 -05:00
|
|
|
|
|
|
|
zmq_msg_t msg_b;
|
2019-03-22 06:48:49 -04:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg_b));
|
2014-07-12 18:05:49 -05:00
|
|
|
|
2019-03-22 06:48:49 -04:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_copy (&msg_b, &msg_a));
|
2014-07-12 18:05:49 -05:00
|
|
|
|
|
|
|
// Message is now shared
|
2019-03-22 06:48:49 -04:00
|
|
|
TEST_ASSERT_EQUAL_INT (
|
|
|
|
1, TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_get (&msg_b, ZMQ_SHARED)));
|
2014-07-12 18:05:49 -05:00
|
|
|
|
2014-07-29 13:43:38 -05:00
|
|
|
// cleanup
|
2019-03-22 06:48:49 -04:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg_a));
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg_b));
|
|
|
|
}
|
2014-07-29 13:43:38 -05:00
|
|
|
|
2019-03-22 06:48:49 -04:00
|
|
|
void test_shared_const ()
|
|
|
|
{
|
|
|
|
zmq_msg_t msg_a;
|
2014-07-29 13:43:38 -05:00
|
|
|
// Test ZMQ_SHARED property (case 2, constant data messages)
|
2019-03-22 06:48:49 -04:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (
|
|
|
|
zmq_msg_init_data (&msg_a, (void *) "TEST", 5, 0, 0));
|
2014-07-29 13:43:38 -05:00
|
|
|
|
|
|
|
// Message reports as shared
|
2019-03-22 06:48:49 -04:00
|
|
|
TEST_ASSERT_EQUAL_INT (
|
|
|
|
1, TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_get (&msg_a, ZMQ_SHARED)));
|
2014-07-29 13:43:38 -05:00
|
|
|
|
|
|
|
// cleanup
|
2019-03-22 06:48:49 -04:00
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg_a));
|
|
|
|
}
|
2014-07-29 13:43:38 -05:00
|
|
|
|
2019-03-22 06:48:49 -04:00
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
setup_test_environment ();
|
2014-07-29 13:43:38 -05:00
|
|
|
|
2019-03-22 06:48:49 -04: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
|
|
|
}
|