2023-06-05 01:16:05 +02:00
|
|
|
/* SPDX-License-Identifier: MPL-2.0 */
|
2010-08-27 18:35:59 +02:00
|
|
|
|
2010-08-28 13:58:23 +02:00
|
|
|
#include "testutil.hpp"
|
2018-12-07 13:51:30 +01:00
|
|
|
#include "testutil_unity.hpp"
|
2010-08-28 13:58:23 +02:00
|
|
|
|
2019-03-23 13:04:57 +01:00
|
|
|
#include <stdlib.h>
|
2018-12-07 13:51:30 +01:00
|
|
|
|
2019-03-24 17:51:28 +01:00
|
|
|
SETUP_TEARDOWN_TESTCONTEXT
|
2018-12-07 13:51:30 +01:00
|
|
|
|
|
|
|
void test_leak ()
|
2017-05-11 00:31:17 +02:00
|
|
|
{
|
|
|
|
char my_endpoint[256];
|
|
|
|
|
2018-12-07 13:51:30 +01:00
|
|
|
void *sb = test_context_socket (ZMQ_REP);
|
2019-03-24 18:19:36 +01:00
|
|
|
bind_loopback_ipc (sb, my_endpoint, sizeof my_endpoint);
|
2017-05-11 00:31:17 +02:00
|
|
|
|
2018-12-07 13:51:30 +01:00
|
|
|
void *sc = test_context_socket (ZMQ_REQ);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint));
|
2017-05-11 00:31:17 +02:00
|
|
|
|
2018-12-07 13:51:30 +01:00
|
|
|
static const char leakymsg[] = "leakymsg";
|
|
|
|
send_string_expect_success (sc, leakymsg, 0);
|
2017-05-11 00:31:17 +02:00
|
|
|
|
|
|
|
char *buf = s_recv (sb);
|
|
|
|
free (buf);
|
|
|
|
|
2018-12-07 13:51:30 +01:00
|
|
|
test_context_socket_close (sc);
|
2017-05-11 00:31:17 +02:00
|
|
|
|
|
|
|
msleep (SETTLE_TIME);
|
|
|
|
|
2018-12-07 13:51:30 +01:00
|
|
|
send_string_expect_success (sb, leakymsg, 0);
|
2017-05-11 00:31:17 +02:00
|
|
|
|
2018-12-07 13:51:30 +01:00
|
|
|
test_context_socket_close (sb);
|
2017-05-11 00:31:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_simple (void)
|
2010-08-27 18:35:59 +02:00
|
|
|
{
|
2017-05-01 13:23:19 +02:00
|
|
|
char my_endpoint[256];
|
2011-03-24 10:03:49 +01:00
|
|
|
|
2018-12-07 13:51:30 +01:00
|
|
|
void *sb = test_context_socket (ZMQ_REP);
|
2019-03-24 18:19:36 +01:00
|
|
|
bind_loopback_ipc (sb, my_endpoint, sizeof my_endpoint);
|
2011-03-24 10:03:49 +01:00
|
|
|
|
2018-12-07 13:51:30 +01:00
|
|
|
void *sc = test_context_socket (ZMQ_REQ);
|
|
|
|
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint));
|
2018-02-01 11:46:09 +01:00
|
|
|
|
2011-03-24 10:03:49 +01:00
|
|
|
bounce (sb, sc);
|
|
|
|
|
2018-12-07 13:51:30 +01:00
|
|
|
test_context_socket_close (sc);
|
|
|
|
test_context_socket_close (sb);
|
2017-05-11 00:31:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main (void)
|
|
|
|
{
|
|
|
|
setup_test_environment ();
|
|
|
|
|
2018-12-07 13:51:30 +01:00
|
|
|
UNITY_BEGIN ();
|
|
|
|
RUN_TEST (test_simple);
|
|
|
|
RUN_TEST (test_leak);
|
|
|
|
return UNITY_END ();
|
2010-08-27 18:35:59 +02:00
|
|
|
}
|