test_dgram.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: MPL-2.0 */
2 
3 #include "testutil.hpp"
4 #include "testutil_unity.hpp"
5 
6 #include <stdlib.h>
7 #include <string.h>
8 
10 
11 void str_send_to (void *s_, const char *content_, const char *address_)
12 {
14  send_string_expect_success (s_, content_, 0);
15 }
16 
17 void str_recv_from (void *s_, char **ptr_content_, char **ptr_address_)
18 {
19  *ptr_address_ = s_recv (s_);
20  TEST_ASSERT_NOT_NULL (ptr_address_);
21 
22  *ptr_content_ = s_recv (s_);
23  TEST_ASSERT_NOT_NULL (ptr_content_);
24 }
25 
26 static const char test_question[] = "Is someone there ?";
27 static const char test_answer[] = "Yes, there is !";
28 
30 {
31  void *socket = test_context_socket (ZMQ_DGRAM);
32 
33  // Connecting dgram should fail
35  zmq_connect (socket, ENDPOINT_4));
36 
38 }
39 
41 {
42  char *message_string;
43  char *address;
44 
45  void *sender = test_context_socket (ZMQ_DGRAM);
46  void *listener = test_context_socket (ZMQ_DGRAM);
47 
49 
51 
52  str_send_to (sender, test_question, strrchr (ENDPOINT_4, '/') + 1);
53 
54  str_recv_from (listener, &message_string, &address);
55  TEST_ASSERT_EQUAL_STRING (test_question, message_string);
56  TEST_ASSERT_EQUAL_STRING (strrchr (ENDPOINT_5, '/') + 1, address);
57  free (message_string);
58 
59  str_send_to (listener, test_answer, address);
60  free (address);
61 
62  str_recv_from (sender, &message_string, &address);
63  TEST_ASSERT_EQUAL_STRING (test_answer, message_string);
64  TEST_ASSERT_EQUAL_STRING (strrchr (ENDPOINT_4, '/') + 1, address);
65  free (message_string);
66  free (address);
67 
69  test_context_socket_close (listener);
70 }
71 
72 int main (void)
73 {
75 
76  UNITY_BEGIN ();
79  return UNITY_END ();
80 }
test_roundtrip
void test_roundtrip()
Definition: test_dgram.cpp:40
TEST_ASSERT_EQUAL_STRING
#define TEST_ASSERT_EQUAL_STRING(expected, actual)
Definition: unity.h:235
UNITY_END
return UNITY_END()
ENDPOINT_4
#define ENDPOINT_4
Definition: libzmq/tests/testutil.hpp:43
RUN_TEST
#define RUN_TEST(func)
Definition: unity_internals.h:615
SETUP_TEARDOWN_TESTCONTEXT
#define SETUP_TEARDOWN_TESTCONTEXT
Definition: testutil_unity.hpp:172
str_recv_from
void str_recv_from(void *s_, char **ptr_content_, char **ptr_address_)
Definition: test_dgram.cpp:17
str_send_to
SETUP_TEARDOWN_TESTCONTEXT void str_send_to(void *s_, const char *content_, const char *address_)
Definition: test_dgram.cpp:11
address
const char * address
Definition: builds/zos/test_fork.cpp:6
s_recv
char * s_recv(void *socket_)
Definition: testutil.cpp:123
zmq_connect
ZMQ_EXPORT int zmq_connect(void *s_, const char *addr_)
Definition: zmq.cpp:307
testutil_unity.hpp
ENDPOINT_5
#define ENDPOINT_5
Definition: libzmq/tests/testutil.hpp:44
testutil.hpp
s_
std::string s_
Definition: gmock-matchers_test.cc:4128
test_connect_fails
void test_connect_fails()
Definition: test_dgram.cpp:29
zmq_bind
ZMQ_EXPORT int zmq_bind(void *s_, const char *addr_)
Definition: zmq.cpp:299
test_context_socket
void * test_context_socket(int type_)
Definition: testutil_unity.cpp:200
test_answer
static const char test_answer[]
Definition: test_dgram.cpp:27
send_string_expect_success
void send_string_expect_success(void *socket_, const char *str_, int flags_)
Definition: testutil_unity.cpp:94
ZMQ_DGRAM
#define ZMQ_DGRAM
Definition: zmq_draft.h:20
setup_test_environment
void setup_test_environment(int timeout_seconds_)
Definition: testutil.cpp:201
UNITY_BEGIN
UNITY_BEGIN()
ZMQ_SNDMORE
#define ZMQ_SNDMORE
Definition: zmq.h:359
test_question
static const char test_question[]
Definition: test_dgram.cpp:26
TEST_ASSERT_FAILURE_ERRNO
#define TEST_ASSERT_FAILURE_ERRNO(error_code, expr)
Definition: testutil_unity.hpp:95
ENOCOMPATPROTO
#define ENOCOMPATPROTO
Definition: zmq.h:160
test_context_socket_close
void * test_context_socket_close(void *socket_)
Definition: testutil_unity.cpp:208
TEST_ASSERT_NOT_NULL
#define TEST_ASSERT_NOT_NULL(pointer)
Definition: unity.h:125
TEST_ASSERT_SUCCESS_ERRNO
#define TEST_ASSERT_SUCCESS_ERRNO(expr)
Definition: proxy_thr.cpp:47
main
int main(void)
Definition: test_dgram.cpp:72


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:59