1 | /* |
2 | Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file |
3 | |
4 | This file is part of libzmq, the ZeroMQ core engine in C++. |
5 | |
6 | libzmq is free software; you can redistribute it and/or modify it under |
7 | the terms of the GNU Lesser General Public License (LGPL) as published |
8 | by the Free Software Foundation; either version 3 of the License, or |
9 | (at your option) any later version. |
10 | |
11 | As a special exception, the Contributors give you permission to link |
12 | this library with independent modules to produce an executable, |
13 | regardless of the license terms of these independent modules, and to |
14 | copy and distribute the resulting executable under terms of your choice, |
15 | provided that you also meet, for each linked independent module, the |
16 | terms and conditions of the license of that module. An independent |
17 | module is a module which is not derived from or based on this library. |
18 | If you modify this library, you must extend this exception to your |
19 | version of the library. |
20 | |
21 | libzmq is distributed in the hope that it will be useful, but WITHOUT |
22 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
23 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
24 | License for more details. |
25 | |
26 | You should have received a copy of the GNU Lesser General Public License |
27 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
28 | */ |
29 | |
30 | #include "testutil.hpp" |
31 | #include "testutil_unity.hpp" |
32 | |
33 | SETUP_TEARDOWN_TESTCONTEXT |
34 | |
35 | void create_inproc_client_server_pair (void **server_, void **client_) |
36 | { |
37 | *server_ = test_context_socket (ZMQ_SERVER); |
38 | *client_ = test_context_socket (ZMQ_CLIENT); |
39 | |
40 | TEST_ASSERT_SUCCESS_ERRNO ( |
41 | zmq_bind (*server_, "inproc://test-client-server" )); |
42 | TEST_ASSERT_SUCCESS_ERRNO ( |
43 | zmq_connect (*client_, "inproc://test-client-server" )); |
44 | } |
45 | |
46 | void send_sndmore_expect_failure (void *socket_) |
47 | { |
48 | int rc = zmq_send (socket_, "X" , 1, ZMQ_SNDMORE); |
49 | TEST_ASSERT_EQUAL_INT (-1, rc); |
50 | TEST_ASSERT_EQUAL_INT (EINVAL, errno); |
51 | } |
52 | |
53 | void test_client_sndmore_fails () |
54 | { |
55 | void *server, *client; |
56 | create_inproc_client_server_pair (&server, &client); |
57 | |
58 | send_sndmore_expect_failure (client); |
59 | |
60 | test_context_socket_close (server); |
61 | test_context_socket_close (client); |
62 | } |
63 | |
64 | void test_server_sndmore_fails () |
65 | { |
66 | void *server, *client; |
67 | create_inproc_client_server_pair (&server, &client); |
68 | |
69 | send_sndmore_expect_failure (server); |
70 | |
71 | test_context_socket_close (server); |
72 | test_context_socket_close (client); |
73 | } |
74 | |
75 | void test_routing_id () |
76 | { |
77 | void *server, *client; |
78 | create_inproc_client_server_pair (&server, &client); |
79 | |
80 | send_string_expect_success (client, "X" , 0); |
81 | |
82 | uint32_t routing_id; |
83 | { |
84 | zmq_msg_t msg; |
85 | TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg)); |
86 | |
87 | int rc = TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_recv (&msg, server, 0)); |
88 | TEST_ASSERT_EQUAL_INT (1, rc); |
89 | |
90 | routing_id = zmq_msg_routing_id (&msg); |
91 | TEST_ASSERT_NOT_EQUAL (0, routing_id); |
92 | |
93 | TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg)); |
94 | } |
95 | |
96 | { |
97 | zmq_msg_t msg; |
98 | TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init_size (&msg, 1)); |
99 | |
100 | char *data = static_cast<char *> (zmq_msg_data (&msg)); |
101 | data[0] = 2; |
102 | |
103 | TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_set_routing_id (&msg, routing_id)); |
104 | |
105 | int rc = zmq_msg_send (&msg, server, 0); |
106 | TEST_ASSERT_EQUAL_INT (1, rc); |
107 | } |
108 | |
109 | { |
110 | zmq_msg_t msg; |
111 | TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_init (&msg)); |
112 | |
113 | int rc = zmq_msg_recv (&msg, client, 0); |
114 | TEST_ASSERT_EQUAL_INT (1, rc); |
115 | |
116 | routing_id = zmq_msg_routing_id (&msg); |
117 | TEST_ASSERT_EQUAL_UINT32 (0, routing_id); |
118 | |
119 | TEST_ASSERT_SUCCESS_ERRNO (zmq_msg_close (&msg)); |
120 | } |
121 | |
122 | test_context_socket_close (server); |
123 | test_context_socket_close (client); |
124 | } |
125 | |
126 | int main (void) |
127 | { |
128 | setup_test_environment (); |
129 | |
130 | UNITY_BEGIN (); |
131 | RUN_TEST (test_client_sndmore_fails); |
132 | RUN_TEST (test_server_sndmore_fails); |
133 | RUN_TEST (test_routing_id); |
134 | return UNITY_END (); |
135 | } |
136 | |