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
12c6ae22
Commit
12c6ae22
authored
May 22, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: test_pub_invert_matching not using test framework
Solution: migrate to unity
parent
fa467d34
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
66 deletions
+53
-66
Makefile.am
Makefile.am
+2
-1
test_pub_invert_matching.cpp
tests/test_pub_invert_matching.cpp
+51
-65
No files found.
Makefile.am
View file @
12c6ae22
...
...
@@ -660,7 +660,8 @@ tests_test_stream_exceeds_buffer_SOURCES = tests/test_stream_exceeds_buffer.cpp
tests_test_stream_exceeds_buffer_LDADD
=
src/libzmq.la
tests_test_pub_invert_matching_SOURCES
=
tests/test_pub_invert_matching.cpp
tests_test_pub_invert_matching_LDADD
=
src/libzmq.la
tests_test_pub_invert_matching_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_pub_invert_matching_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_bind_after_connect_tcp_SOURCES
=
tests/test_bind_after_connect_tcp.cpp
tests_test_bind_after_connect_tcp_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
...
...
tests/test_pub_invert_matching.cpp
View file @
12c6ae22
...
...
@@ -28,109 +28,95 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
int
main
(
void
)
void
setUp
(
)
{
setup_test_environment
();
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
setup_test_context
();
}
void
tearDown
()
{
teardown_test_context
();
}
void
test
()
{
// Create a publisher
void
*
pub
=
zmq_socket
(
ctx
,
ZMQ_PUB
);
assert
(
pub
);
int
rc
=
zmq_bind
(
pub
,
"inproc://soname"
);
assert
(
rc
==
0
);
void
*
pub
=
test_context_socket
(
ZMQ_PUB
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
pub
,
"inproc://soname"
));
// Create two subscribers
void
*
sub1
=
zmq_socket
(
ctx
,
ZMQ_SUB
);
assert
(
sub1
);
rc
=
zmq_connect
(
sub1
,
"inproc://soname"
);
assert
(
rc
==
0
);
void
*
sub1
=
test_context_socket
(
ZMQ_SUB
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
sub1
,
"inproc://soname"
));
void
*
sub2
=
zmq_socket
(
ctx
,
ZMQ_SUB
);
assert
(
sub2
);
rc
=
zmq_connect
(
sub2
,
"inproc://soname"
);
assert
(
rc
==
0
);
void
*
sub2
=
test_context_socket
(
ZMQ_SUB
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
sub2
,
"inproc://soname"
));
// Subscribe pub1 to one prefix
// and pub2 to another prefix.
const
char
PREFIX1
[]
=
"prefix1"
;
const
char
PREFIX2
[]
=
"p2"
;
rc
=
zmq_setsockopt
(
sub1
,
ZMQ_SUBSCRIBE
,
PREFIX1
,
sizeof
(
PREFIX1
));
assert
(
rc
==
0
);
rc
=
zmq_setsockopt
(
sub2
,
ZMQ_SUBSCRIBE
,
PREFIX2
,
sizeof
(
PREFIX2
));
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sub1
,
ZMQ_SUBSCRIBE
,
PREFIX1
,
strlen
(
PREFIX1
)));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sub2
,
ZMQ_SUBSCRIBE
,
PREFIX2
,
strlen
(
PREFIX2
)));
// Send a message with the first prefix
rc
=
zmq_send_const
(
pub
,
PREFIX1
,
sizeof
(
PREFIX1
),
0
);
assert
(
rc
==
sizeof
(
PREFIX1
));
send_string_expect_success
(
pub
,
PREFIX1
,
0
);
// sub1 should receive it, but not sub2
rc
=
zmq_recv
(
sub1
,
NULL
,
0
,
ZMQ_DONTWAIT
);
assert
(
rc
==
sizeof
(
PREFIX1
));
recv_string_expect_success
(
sub1
,
PREFIX1
,
ZMQ_DONTWAIT
);
rc
=
zmq_recv
(
sub2
,
NULL
,
0
,
ZMQ_DONTWAIT
);
assert
(
rc
==
-
1
);
assert
(
errno
==
EAGAIN
);
TEST_ASSERT_FAILURE_ERRNO
(
EAGAIN
,
zmq_recv
(
sub2
,
NULL
,
0
,
ZMQ_DONTWAIT
));
// Send a message with the second prefix
rc
=
zmq_send_const
(
pub
,
PREFIX2
,
sizeof
(
PREFIX2
),
0
);
assert
(
rc
==
sizeof
(
PREFIX2
));
send_string_expect_success
(
pub
,
PREFIX2
,
0
);
// sub2 should receive it, but not sub1
rc
=
zmq_recv
(
sub2
,
NULL
,
0
,
ZMQ_DONTWAIT
);
assert
(
rc
==
sizeof
(
PREFIX2
));
recv_string_expect_success
(
sub2
,
PREFIX2
,
ZMQ_DONTWAIT
);
rc
=
zmq_recv
(
sub1
,
NULL
,
0
,
ZMQ_DONTWAIT
);
assert
(
rc
==
-
1
);
assert
(
errno
==
EAGAIN
);
TEST_ASSERT_FAILURE_ERRNO
(
EAGAIN
,
zmq_recv
(
sub1
,
NULL
,
0
,
ZMQ_DONTWAIT
));
// Now invert the matching
int
invert
=
1
;
rc
=
zmq_setsockopt
(
pub
,
ZMQ_INVERT_MATCHING
,
&
invert
,
sizeof
(
invert
));
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
pub
,
ZMQ_INVERT_MATCHING
,
&
invert
,
sizeof
(
invert
))
);
// ... on both sides, otherwise the SUB socket will filter the messages out
rc
=
zmq_setsockopt
(
sub1
,
ZMQ_INVERT_MATCHING
,
&
invert
,
sizeof
(
invert
));
rc
=
zmq_setsockopt
(
sub2
,
ZMQ_INVERT_MATCHING
,
&
invert
,
sizeof
(
invert
));
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sub1
,
ZMQ_INVERT_MATCHING
,
&
invert
,
sizeof
(
invert
)));
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_setsockopt
(
sub2
,
ZMQ_INVERT_MATCHING
,
&
invert
,
sizeof
(
invert
)));
// Send a message with the first prefix
rc
=
zmq_send_const
(
pub
,
PREFIX1
,
sizeof
(
PREFIX1
),
0
);
assert
(
rc
==
sizeof
(
PREFIX1
));
send_string_expect_success
(
pub
,
PREFIX1
,
0
);
// sub2 should receive it, but not sub1
rc
=
zmq_recv
(
sub2
,
NULL
,
0
,
ZMQ_DONTWAIT
);
assert
(
rc
==
sizeof
(
PREFIX1
));
recv_string_expect_success
(
sub2
,
PREFIX1
,
ZMQ_DONTWAIT
);
rc
=
zmq_recv
(
sub1
,
NULL
,
0
,
ZMQ_DONTWAIT
);
assert
(
rc
==
-
1
);
assert
(
errno
==
EAGAIN
);
TEST_ASSERT_FAILURE_ERRNO
(
EAGAIN
,
zmq_recv
(
sub1
,
NULL
,
0
,
ZMQ_DONTWAIT
));
// Send a message with the second prefix
rc
=
zmq_send_const
(
pub
,
PREFIX2
,
sizeof
(
PREFIX2
),
0
);
assert
(
rc
==
sizeof
(
PREFIX2
));
send_string_expect_success
(
pub
,
PREFIX2
,
0
);
// sub1 should receive it, but not sub2
rc
=
zmq_recv
(
sub1
,
NULL
,
0
,
ZMQ_DONTWAIT
);
assert
(
rc
==
sizeof
(
PREFIX2
));
rc
=
zmq_recv
(
sub2
,
NULL
,
0
,
ZMQ_DONTWAIT
);
assert
(
rc
==
-
1
);
assert
(
errno
==
EAGAIN
);
recv_string_expect_success
(
sub1
,
PREFIX2
,
ZMQ_DONTWAIT
);
TEST_ASSERT_FAILURE_ERRNO
(
EAGAIN
,
zmq_recv
(
sub2
,
NULL
,
0
,
ZMQ_DONTWAIT
));
// Clean up.
rc
=
zmq_close
(
pub
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
sub1
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
sub2
);
assert
(
rc
==
0
);
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
return
0
;
test_context_socket_close
(
pub
);
test_context_socket_close
(
sub1
);
test_context_socket_close
(
sub2
);
}
int
main
()
{
setup_test_environment
();
UNITY_BEGIN
();
RUN_TEST
(
test
);
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