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
ab22aeb8
Commit
ab22aeb8
authored
Aug 17, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: test_setsockopt not yet using unity
Solution: migrate to unity
parent
30b9e5a1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
64 deletions
+68
-64
Makefile.am
Makefile.am
+2
-1
test_setsockopt.cpp
tests/test_setsockopt.cpp
+66
-63
No files found.
Makefile.am
View file @
ab22aeb8
...
...
@@ -668,7 +668,8 @@ tests_test_sockopt_hwm_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_sockopt_hwm_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_setsockopt_SOURCES
=
tests/test_setsockopt.cpp
tests_test_setsockopt_LDADD
=
src/libzmq.la
tests_test_setsockopt_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_setsockopt_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_heartbeats_SOURCES
=
tests/test_heartbeats.cpp
tests_test_heartbeats_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
...
...
tests/test_setsockopt.cpp
View file @
ab22aeb8
...
...
@@ -28,126 +28,129 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
void
test_setsockopt_tcp_recv_buffer
(
void
)
void
setUp
(
)
{
int
rc
;
void
*
ctx
=
zmq_ctx_new
();
void
*
socket
=
zmq_socket
(
ctx
,
ZMQ_PUSH
);
setup_test_context
();
}
void
tearDown
()
{
teardown_test_context
();
}
void
test_setsockopt_tcp_recv_buffer
()
{
void
*
socket
=
test_context_socket
(
ZMQ_PUSH
);
int
val
=
0
;
size_t
placeholder
=
sizeof
(
val
);
rc
=
zmq_getsockopt
(
socket
,
ZMQ_RCVBUF
,
&
val
,
&
placeholder
);
assert
(
rc
==
0
);
assert
(
val
==
-
1
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
socket
,
ZMQ_RCVBUF
,
&
val
,
&
placeholder
)
);
TEST_ASSERT_EQUAL_INT
(
-
1
,
val
);
val
=
16384
;
rc
=
zmq_setsockopt
(
socket
,
ZMQ_RCVBUF
,
&
val
,
sizeof
(
val
));
assert
(
rc
==
0
);
assert
(
val
==
16384
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
socket
,
ZMQ_RCVBUF
,
&
val
,
sizeof
(
val
))
);
TEST_ASSERT_EQUAL_INT
(
16384
,
val
);
rc
=
zmq_getsockopt
(
socket
,
ZMQ_RCVBUF
,
&
val
,
&
placeholder
);
assert
(
rc
==
0
);
assert
(
val
==
16384
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
socket
,
ZMQ_RCVBUF
,
&
val
,
&
placeholder
)
);
TEST_ASSERT_EQUAL_INT
(
16384
,
val
);
zmq_close
(
socket
);
zmq_ctx_term
(
ctx
);
test_context_socket_close
(
socket
);
}
void
test_setsockopt_tcp_send_buffer
(
void
)
void
test_setsockopt_tcp_send_buffer
()
{
int
rc
;
void
*
ctx
=
zmq_ctx_new
();
void
*
socket
=
zmq_socket
(
ctx
,
ZMQ_PUSH
);
void
*
socket
=
test_context_socket
(
ZMQ_PUSH
);
int
val
=
0
;
size_t
placeholder
=
sizeof
(
val
);
rc
=
zmq_getsockopt
(
socket
,
ZMQ_SNDBUF
,
&
val
,
&
placeholder
);
assert
(
rc
==
0
);
assert
(
val
==
-
1
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
socket
,
ZMQ_SNDBUF
,
&
val
,
&
placeholder
)
);
TEST_ASSERT_EQUAL_INT
(
-
1
,
val
);
val
=
16384
;
rc
=
zmq_setsockopt
(
socket
,
ZMQ_SNDBUF
,
&
val
,
sizeof
(
val
));
assert
(
rc
==
0
);
assert
(
val
==
16384
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
socket
,
ZMQ_SNDBUF
,
&
val
,
sizeof
(
val
))
);
TEST_ASSERT_EQUAL_INT
(
16384
,
val
);
rc
=
zmq_getsockopt
(
socket
,
ZMQ_SNDBUF
,
&
val
,
&
placeholder
);
assert
(
rc
==
0
);
assert
(
val
==
16384
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
socket
,
ZMQ_SNDBUF
,
&
val
,
&
placeholder
)
);
TEST_ASSERT_EQUAL_INT
(
16384
,
val
);
zmq_close
(
socket
);
zmq_ctx_term
(
ctx
);
test_context_socket_close
(
socket
);
}
void
test_setsockopt_use_fd
()
{
int
rc
;
void
*
ctx
=
zmq_ctx_new
();
void
*
socket
=
zmq_socket
(
ctx
,
ZMQ_PUSH
);
void
*
socket
=
test_context_socket
(
ZMQ_PUSH
);
int
val
=
0
;
size_t
placeholder
=
sizeof
(
val
);
rc
=
zmq_getsockopt
(
socket
,
ZMQ_USE_FD
,
&
val
,
&
placeholder
);
assert
(
rc
==
0
);
assert
(
val
==
-
1
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
socket
,
ZMQ_USE_FD
,
&
val
,
&
placeholder
)
);
TEST_ASSERT_EQUAL_INT
(
-
1
,
val
);
val
=
3
;
rc
=
zmq_setsockopt
(
socket
,
ZMQ_USE_FD
,
&
val
,
sizeof
(
val
));
assert
(
rc
==
0
);
assert
(
val
==
3
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
socket
,
ZMQ_USE_FD
,
&
val
,
sizeof
(
val
))
);
TEST_ASSERT_EQUAL_INT
(
3
,
val
);
rc
=
zmq_getsockopt
(
socket
,
ZMQ_USE_FD
,
&
val
,
&
placeholder
);
assert
(
rc
==
0
);
assert
(
val
==
3
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
socket
,
ZMQ_USE_FD
,
&
val
,
&
placeholder
)
);
TEST_ASSERT_EQUAL_INT
(
3
,
val
);
zmq_close
(
socket
);
zmq_ctx_term
(
ctx
);
test_context_socket_close
(
socket
);
}
#define BOUNDDEVBUFSZ 16
void
test_setsockopt_bindtodevice
()
{
void
*
ctx
=
zmq_ctx_new
();
void
*
socket
=
zmq_socket
(
ctx
,
ZMQ_PUSH
);
void
*
socket
=
test_context_socket
(
ZMQ_PUSH
);
#ifdef ZMQ_BINDTODEVICE
int
rc
;
char
devname
[
BOUNDDEVBUFSZ
];
size_t
buflen
=
BOUNDDEVBUFSZ
;
rc
=
zmq_getsockopt
(
socket
,
ZMQ_BINDTODEVICE
,
devname
,
&
buflen
);
assert
(
rc
==
0
);
assert
(
devname
[
0
]
==
'\0'
);
assert
(
buflen
==
1
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
socket
,
ZMQ_BINDTODEVICE
,
devname
,
&
buflen
)
);
TEST_ASSERT_EQUAL_INT8
(
'\0'
,
devname
[
0
]
);
TEST_ASSERT_EQUAL_UINT
(
1
,
buflen
);
sprintf
(
devname
,
"testdev"
);
buflen
=
strlen
(
devname
);
rc
=
zmq_setsockopt
(
socket
,
ZMQ_BINDTODEVICE
,
devname
,
buflen
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
socket
,
ZMQ_BINDTODEVICE
,
devname
,
buflen
)
);
buflen
=
BOUNDDEVBUFSZ
;
memset
(
devname
,
0
,
buflen
);
rc
=
zmq_getsockopt
(
socket
,
ZMQ_BINDTODEVICE
,
devname
,
&
buflen
);
assert
(
rc
==
0
);
assert
(
!
strncmp
(
"testdev"
,
devname
,
buflen
)
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
socket
,
ZMQ_BINDTODEVICE
,
devname
,
&
buflen
)
);
TEST_ASSERT_EQUAL_STRING_LEN
(
"testdev"
,
devname
,
buflen
);
#endif
zmq_close
(
socket
);
zmq_ctx_term
(
ctx
);
test_context_socket_close
(
socket
);
}
int
main
(
void
)
int
main
()
{
test_setsockopt_tcp_recv_buffer
();
test_setsockopt_tcp_send_buffer
();
test_setsockopt_use_fd
();
test_setsockopt_bindtodevice
();
setup_test_environment
();
UNITY_BEGIN
();
RUN_TEST
(
test_setsockopt_tcp_recv_buffer
);
RUN_TEST
(
test_setsockopt_tcp_send_buffer
);
RUN_TEST
(
test_setsockopt_use_fd
);
RUN_TEST
(
test_setsockopt_bindtodevice
);
return
UNITY_END
();
}
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