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
8b030a92
Commit
8b030a92
authored
May 25, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: no tests for corner cases of setsockopt ZMQ_HEARTBEAT_TTL
Solution: added tests
parent
d90e70c1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
test_heartbeats.cpp
tests/test_heartbeats.cpp
+54
-0
No files found.
tests/test_heartbeats.cpp
View file @
8b030a92
...
...
@@ -29,6 +29,14 @@ typedef SOCKET raw_socket;
typedef
int
raw_socket
;
#endif
#include <limits.h>
// TODO remove this here, either ensure that UINT16_MAX is always properly
// defined or handle this at a more central location
#ifndef UINT16_MAX
#define UINT16_MAX 65535
#endif
#include "testutil_unity.hpp"
void
setUp
()
...
...
@@ -366,6 +374,48 @@ DEFINE_TESTS (pull, push, ZMQ_PULL, ZMQ_PUSH)
DEFINE_TESTS
(
sub
,
pub
,
ZMQ_SUB
,
ZMQ_PUB
)
DEFINE_TESTS
(
pair
,
pair
,
ZMQ_PAIR
,
ZMQ_PAIR
)
const
int
deciseconds_per_millisecond
=
100
;
const
int
heartbeat_ttl_max
=
(
UINT16_MAX
+
1
)
*
deciseconds_per_millisecond
-
1
;
void
test_setsockopt_heartbeat_success
(
const
int
value
)
{
void
*
const
socket
=
test_context_socket
(
ZMQ_PAIR
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
socket
,
ZMQ_HEARTBEAT_TTL
,
&
value
,
sizeof
(
value
)));
int
value_read
;
size_t
value_read_size
=
sizeof
(
value_read
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_getsockopt
(
socket
,
ZMQ_HEARTBEAT_TTL
,
&
value_read
,
&
value_read_size
));
TEST_ASSERT_EQUAL_INT
(
value
-
value
%
deciseconds_per_millisecond
,
value_read
);
test_context_socket_close
(
socket
);
}
void
test_setsockopt_heartbeat_ttl_max
()
{
test_setsockopt_heartbeat_success
(
heartbeat_ttl_max
);
}
void
test_setsockopt_heartbeat_ttl_more_than_max_fails
()
{
void
*
const
socket
=
test_context_socket
(
ZMQ_PAIR
);
const
int
value
=
heartbeat_ttl_max
+
1
;
TEST_ASSERT_FAILURE_ERRNO
(
EINVAL
,
zmq_setsockopt
(
socket
,
ZMQ_HEARTBEAT_TTL
,
&
value
,
sizeof
(
value
)));
test_context_socket_close
(
socket
);
}
void
test_setsockopt_heartbeat_ttl_near_zero
()
{
test_setsockopt_heartbeat_success
(
deciseconds_per_millisecond
-
1
);
}
int
main
(
void
)
{
setup_test_environment
();
...
...
@@ -381,6 +431,10 @@ int main (void)
RUN_TEST
(
test_heartbeat_ttl_sub_pub
);
RUN_TEST
(
test_heartbeat_ttl_pair_pair
);
RUN_TEST
(
test_setsockopt_heartbeat_ttl_max
);
RUN_TEST
(
test_setsockopt_heartbeat_ttl_more_than_max_fails
);
RUN_TEST
(
test_setsockopt_heartbeat_ttl_near_zero
);
RUN_TEST
(
test_heartbeat_notimeout_dealer_router
);
RUN_TEST
(
test_heartbeat_notimeout_req_rep
);
RUN_TEST
(
test_heartbeat_notimeout_pull_push
);
...
...
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