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
8ae91fdf
Commit
8ae91fdf
authored
Aug 22, 2017
by
sigiesec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: no test cases for zmq_poller_add*, zmq_poller_modify*, zmq_poller_remove* corner cases
Solution: added test cases
parent
68f416c0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
5 deletions
+70
-5
test_poller.cpp
tests/test_poller.cpp
+61
-0
test_system.cpp
tests/test_system.cpp
+0
-5
testutil.hpp
tests/testutil.hpp
+9
-0
No files found.
tests/test_poller.cpp
View file @
8ae91fdf
...
...
@@ -165,6 +165,66 @@ void test_null_event_pointers (void *ctx)
assert
(
rc
==
0
);
}
void
test_add_modify_remove_corner_cases
(
void
*
ctx
)
{
void
*
poller
=
zmq_poller_new
();
assert
(
poller
!=
NULL
);
void
*
zeromq_socket
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
assert
(
zeromq_socket
!=
NULL
);
int
rc
=
zmq_poller_add
(
poller
,
zeromq_socket
,
NULL
,
ZMQ_POLLIN
);
assert
(
rc
==
0
);
// attempt to add the same socket twice
rc
=
zmq_poller_add
(
poller
,
zeromq_socket
,
NULL
,
ZMQ_POLLIN
);
assert
(
rc
==
-
1
&&
errno
==
EINVAL
);
rc
=
zmq_poller_remove
(
poller
,
zeromq_socket
);
assert
(
rc
==
0
);
// attempt to remove socket that is not present
rc
=
zmq_poller_remove
(
poller
,
zeromq_socket
);
assert
(
rc
==
-
1
&&
errno
==
EINVAL
);
// attempt to modify socket that is not present
rc
=
zmq_poller_modify
(
poller
,
zeromq_socket
,
ZMQ_POLLIN
);
assert
(
rc
==
-
1
&&
errno
==
EINVAL
);
// add a socket with no events
// TODO should this really be legal? it does not make any sense...
rc
=
zmq_poller_add
(
poller
,
zeromq_socket
,
NULL
,
0
);
assert
(
rc
==
0
);
fd_t
plain_socket
=
socket
(
AF_INET
,
SOCK_STREAM
,
IPPROTO_TCP
);
rc
=
zmq_poller_add_fd
(
poller
,
plain_socket
,
NULL
,
ZMQ_POLLIN
);
assert
(
rc
==
0
);
// attempt to add the same plain socket twice
rc
=
zmq_poller_add_fd
(
poller
,
plain_socket
,
NULL
,
ZMQ_POLLIN
);
assert
(
rc
==
-
1
&&
errno
==
EINVAL
);
rc
=
zmq_poller_remove_fd
(
poller
,
plain_socket
);
assert
(
rc
==
0
);
// attempt to remove plain socket that is not present
rc
=
zmq_poller_remove_fd
(
poller
,
plain_socket
);
assert
(
rc
==
-
1
&&
errno
==
EINVAL
);
// attempt to modify plain socket that is not present
rc
=
zmq_poller_modify_fd
(
poller
,
plain_socket
,
ZMQ_POLLIN
);
assert
(
rc
==
-
1
&&
errno
==
EINVAL
);
rc
=
zmq_poller_destroy
(
&
poller
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
zeromq_socket
);
assert
(
rc
==
0
);
rc
=
close
(
plain_socket
);
assert
(
rc
==
0
);
}
void
test_wait_corner_cases
(
void
*
ctx
)
{
void
*
poller
=
zmq_poller_new
();
...
...
@@ -332,6 +392,7 @@ int main (void)
test_null_socket_pointers
();
test_null_event_pointers
(
ctx
);
test_add_modify_remove_corner_cases
(
ctx
);
test_wait_corner_cases
(
ctx
);
rc
=
zmq_poller_destroy
(
&
poller
);
...
...
tests/test_system.cpp
View file @
8ae91fdf
...
...
@@ -47,11 +47,6 @@ void initialise_network (void)
throw
std
::
runtime_error
(
"Could not start WSA"
);
}
int
close
(
int
fd
)
{
return
closesocket
(
fd
);
}
#else
void
initialise_network
(
void
)
...
...
tests/testutil.hpp
View file @
8ae91fdf
...
...
@@ -396,4 +396,13 @@ is_ipv6_available(void)
#endif // _WIN32_WINNT < 0x0600
}
#if defined (ZMQ_HAVE_WINDOWS)
int
close
(
int
fd
)
{
return
closesocket
(
fd
);
}
#endif
#endif
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