1 | /* |
2 | Copyright (c) 2007-2017 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 | |
32 | #include <unity.h> |
33 | |
34 | void setUp () |
35 | { |
36 | } |
37 | |
38 | void tearDown () |
39 | { |
40 | } |
41 | |
42 | // tests all socket-related functions with a NULL socket argument |
43 | void test_zmq_socket_null_context () |
44 | { |
45 | void *s = zmq_socket (NULL, ZMQ_PAIR); |
46 | TEST_ASSERT_NULL (s); |
47 | TEST_ASSERT_EQUAL_INT (EFAULT, errno); // TODO use EINVAL instead? |
48 | } |
49 | |
50 | void test_zmq_close_null_socket () |
51 | { |
52 | int rc = zmq_close (NULL); |
53 | TEST_ASSERT_EQUAL_INT (-1, rc); |
54 | TEST_ASSERT_EQUAL_INT (ENOTSOCK, errno); // TODO use EINVAL instead? |
55 | } |
56 | |
57 | void test_zmq_setsockopt_null_socket () |
58 | { |
59 | int hwm = 100; |
60 | size_t hwm_size = sizeof hwm; |
61 | int rc = zmq_setsockopt (NULL, ZMQ_SNDHWM, &hwm, hwm_size); |
62 | TEST_ASSERT_EQUAL_INT (-1, rc); |
63 | TEST_ASSERT_EQUAL_INT (ENOTSOCK, errno); // TODO use EINVAL instead? |
64 | } |
65 | |
66 | void test_zmq_getsockopt_null_socket () |
67 | { |
68 | int hwm; |
69 | size_t hwm_size = sizeof hwm; |
70 | int rc = zmq_getsockopt (NULL, ZMQ_SNDHWM, &hwm, &hwm_size); |
71 | TEST_ASSERT_EQUAL_INT (-1, rc); |
72 | TEST_ASSERT_EQUAL_INT (ENOTSOCK, errno); // TODO use EINVAL instead? |
73 | } |
74 | |
75 | void test_zmq_socket_monitor_null_socket () |
76 | { |
77 | int rc = zmq_socket_monitor (NULL, "inproc://monitor" , ZMQ_EVENT_ALL); |
78 | TEST_ASSERT_EQUAL_INT (-1, rc); |
79 | TEST_ASSERT_EQUAL_INT (ENOTSOCK, errno); // TODO use EINVAL instead? |
80 | } |
81 | |
82 | #ifdef ZMQ_BUILD_DRAFT_API |
83 | void test_zmq_join_null_socket () |
84 | { |
85 | int rc = zmq_join (NULL, "group" ); |
86 | TEST_ASSERT_EQUAL_INT (-1, rc); |
87 | TEST_ASSERT_EQUAL_INT (ENOTSOCK, errno); // TODO use EINVAL instead? |
88 | } |
89 | |
90 | void test_zmq_leave_null_socket () |
91 | { |
92 | int rc = zmq_leave (NULL, "group" ); |
93 | TEST_ASSERT_EQUAL_INT (-1, rc); |
94 | TEST_ASSERT_EQUAL_INT (ENOTSOCK, errno); // TODO use EINVAL instead? |
95 | } |
96 | #endif |
97 | |
98 | |
99 | void test_zmq_bind_null_socket () |
100 | { |
101 | int rc = zmq_bind (NULL, "inproc://socket" ); |
102 | TEST_ASSERT_EQUAL_INT (-1, rc); |
103 | TEST_ASSERT_EQUAL_INT (ENOTSOCK, errno); // TODO use EINVAL instead? |
104 | } |
105 | |
106 | void test_zmq_connect_null_socket () |
107 | { |
108 | int rc = zmq_connect (NULL, "inproc://socket" ); |
109 | TEST_ASSERT_EQUAL_INT (-1, rc); |
110 | TEST_ASSERT_EQUAL_INT (ENOTSOCK, errno); // TODO use EINVAL instead? |
111 | } |
112 | |
113 | void test_zmq_unbind_null_socket () |
114 | { |
115 | int rc = zmq_unbind (NULL, "inproc://socket" ); |
116 | TEST_ASSERT_EQUAL_INT (-1, rc); |
117 | TEST_ASSERT_EQUAL_INT (ENOTSOCK, errno); // TODO use EINVAL instead? |
118 | } |
119 | |
120 | void test_zmq_disconnect_null_socket () |
121 | { |
122 | int rc = zmq_disconnect (NULL, "inproc://socket" ); |
123 | TEST_ASSERT_EQUAL_INT (-1, rc); |
124 | TEST_ASSERT_EQUAL_INT (ENOTSOCK, errno); // TODO use EINVAL instead? |
125 | } |
126 | |
127 | int main (void) |
128 | { |
129 | UNITY_BEGIN (); |
130 | RUN_TEST (test_zmq_socket_null_context); |
131 | RUN_TEST (test_zmq_close_null_socket); |
132 | RUN_TEST (test_zmq_setsockopt_null_socket); |
133 | RUN_TEST (test_zmq_getsockopt_null_socket); |
134 | RUN_TEST (test_zmq_socket_monitor_null_socket); |
135 | RUN_TEST (test_zmq_bind_null_socket); |
136 | RUN_TEST (test_zmq_connect_null_socket); |
137 | RUN_TEST (test_zmq_unbind_null_socket); |
138 | RUN_TEST (test_zmq_disconnect_null_socket); |
139 | |
140 | #ifdef ZMQ_BUILD_DRAFT_API |
141 | RUN_TEST (test_zmq_join_null_socket); |
142 | RUN_TEST (test_zmq_leave_null_socket); |
143 | #endif |
144 | |
145 | return UNITY_END (); |
146 | } |
147 | |