Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
8372797c
Commit
8372797c
authored
Mar 21, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: code duplication in test_reqrep_tcp
Solution: extracted bind_loopback
parent
c84c3a52
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
53 deletions
+23
-53
test_reqrep_tcp.cpp
tests/test_reqrep_tcp.cpp
+9
-51
testutil_unity.hpp
tests/testutil_unity.hpp
+14
-2
No files found.
tests/test_reqrep_tcp.cpp
View file @
8372797c
...
...
@@ -40,31 +40,13 @@ void tearDown ()
teardown_test_context
();
}
const
char
*
bind_address_loopback_ipv4
=
"tcp://127.0.0.1:*"
;
const
char
*
bind_address_loopback_ipv6
=
"tcp://[::1]:*"
;
const
char
*
get_loopback_bin_address
(
bool
ipv6
)
{
if
(
ipv6
&&
!
is_ipv6_available
())
{
TEST_IGNORE_MESSAGE
(
"ipv6 is not available"
);
}
return
ipv6
?
bind_address_loopback_ipv6
:
bind_address_loopback_ipv4
;
}
void
test_single_connect
(
int
ipv6
)
{
size_t
len
=
MAX_SOCKET_STRING
;
char
my_endpoint
[
MAX_SOCKET_STRING
];
const
char
*
address
=
get_loopback_bin_address
(
ipv6
);
void
*
sb
=
test_context_socket
(
ZMQ_REP
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sb
,
ZMQ_IPV6
,
&
ipv6
,
sizeof
(
int
)));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
sb
,
address
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
sb
,
ZMQ_LAST_ENDPOINT
,
my_endpoint
,
&
len
));
bind_loopback
(
sb
,
ipv6
,
my_endpoint
,
len
);
void
*
sc
=
test_context_socket
(
ZMQ_REQ
);
TEST_ASSERT_SUCCESS_ERRNO
(
...
...
@@ -73,6 +55,9 @@ void test_single_connect (int ipv6)
bounce
(
sb
,
sc
);
// TODO is explicit disconnect/unbind essential for the test? if not,
// these calls should probably be left out, for clarity/readability
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_disconnect
(
sc
,
my_endpoint
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_unbind
(
sb
,
my_endpoint
));
...
...
@@ -89,30 +74,14 @@ void test_multi_connect (int ipv6)
char
my_endpoint_2
[
MAX_SOCKET_STRING
];
char
my_endpoint_3
[
MAX_SOCKET_STRING
*
2
];
const
char
*
address
=
get_loopback_bin_address
(
ipv6
);
void
*
sb0
=
test_context_socket
(
ZMQ_REP
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sb0
,
ZMQ_IPV6
,
&
ipv6
,
sizeof
(
int
)));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
sb0
,
address
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
sb0
,
ZMQ_LAST_ENDPOINT
,
my_endpoint_0
,
&
len
));
bind_loopback
(
sb0
,
ipv6
,
my_endpoint_0
,
len
);
void
*
sb1
=
test_context_socket
(
ZMQ_REP
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sb1
,
ZMQ_IPV6
,
&
ipv6
,
sizeof
(
int
)));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
sb1
,
address
));
len
=
MAX_SOCKET_STRING
;
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
sb1
,
ZMQ_LAST_ENDPOINT
,
my_endpoint_1
,
&
len
));
bind_loopback
(
sb1
,
ipv6
,
my_endpoint_1
,
len
);
void
*
sb2
=
test_context_socket
(
ZMQ_REP
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sb2
,
ZMQ_IPV6
,
&
ipv6
,
sizeof
(
int
)));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
sb2
,
address
));
len
=
MAX_SOCKET_STRING
;
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
sb2
,
ZMQ_LAST_ENDPOINT
,
my_endpoint_2
,
&
len
));
bind_loopback
(
sb2
,
ipv6
,
my_endpoint_2
,
len
);
void
*
sc
=
test_context_socket
(
ZMQ_REQ
);
TEST_ASSERT_SUCCESS_ERRNO
(
...
...
@@ -159,22 +128,11 @@ void test_multi_connect_same_port (int ipv6)
char
my_endpoint_4
[
MAX_SOCKET_STRING
*
2
];
char
my_endpoint_5
[
MAX_SOCKET_STRING
*
2
];
const
char
*
address
=
get_loopback_bin_address
(
ipv6
);
void
*
sb0
=
test_context_socket
(
ZMQ_REP
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sb0
,
ZMQ_IPV6
,
&
ipv6
,
sizeof
(
int
)));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
sb0
,
address
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
sb0
,
ZMQ_LAST_ENDPOINT
,
my_endpoint_0
,
&
len
));
bind_loopback
(
sb0
,
ipv6
,
my_endpoint_0
,
len
);
void
*
sb1
=
test_context_socket
(
ZMQ_REP
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sb1
,
ZMQ_IPV6
,
&
ipv6
,
sizeof
(
int
)));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
sb1
,
address
));
len
=
MAX_SOCKET_STRING
;
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
sb1
,
ZMQ_LAST_ENDPOINT
,
my_endpoint_1
,
&
len
));
bind_loopback
(
sb1
,
ipv6
,
my_endpoint_1
,
len
);
void
*
sc0
=
test_context_socket
(
ZMQ_REQ
);
TEST_ASSERT_SUCCESS_ERRNO
(
...
...
tests/testutil_unity.hpp
View file @
8372797c
...
...
@@ -192,9 +192,21 @@ void *test_context_socket_close (void *socket)
return
socket
;
}
void
bind_loopback
_ipv4
(
void
*
socket
,
char
*
my_endpoint
,
size_t
len
)
void
bind_loopback
(
void
*
socket
,
int
ipv6
,
char
*
my_endpoint
,
size_t
len
)
{
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
socket
,
"tcp://127.0.0.1:*"
));
if
(
ipv6
&&
!
is_ipv6_available
())
{
TEST_IGNORE_MESSAGE
(
"ipv6 is not available"
);
}
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
socket
,
ZMQ_IPV6
,
&
ipv6
,
sizeof
(
int
)));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
socket
,
ipv6
?
"tcp://[::1]:*"
:
"tcp://127.0.0.1:*"
));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
socket
,
ZMQ_LAST_ENDPOINT
,
my_endpoint
,
&
len
));
}
void
bind_loopback_ipv4
(
void
*
socket
,
char
*
my_endpoint
,
size_t
len
)
{
bind_loopback
(
socket
,
false
,
my_endpoint
,
len
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment