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
c66288a8
Commit
c66288a8
authored
Aug 20, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: duplicate code
Solution: extracted into common method
parent
713f075f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
55 deletions
+39
-55
test_xpub_verbose.cpp
tests/test_xpub_verbose.cpp
+39
-55
No files found.
tests/test_xpub_verbose.cpp
View file @
c66288a8
...
...
@@ -122,46 +122,60 @@ void test_xpub_verbose_one_sub ()
TEST_ASSERT_EQUAL_INT
(
0
,
rc
);
}
void
test_xpub_verbose_two_subs
()
void
create_xpub_with_2_subs
(
void
*
ctx_
,
void
**
pub_
,
void
**
sub0_
,
void
**
sub1_
)
{
int
rc
;
char
buffer
[
2
];
void
*
ctx
=
zmq_ctx_new
();
TEST_ASSERT_NOT_NULL
(
ctx
);
void
*
pub
=
zmq_socket
(
ctx
,
ZMQ_XPUB
);
TEST_ASSERT_NOT_NULL
(
pub
);
rc
=
zmq_bind
(
pub
,
"inproc://soname"
);
*
pub_
=
zmq_socket
(
ctx_
,
ZMQ_XPUB
);
TEST_ASSERT_NOT_NULL
(
*
pub_
);
int
rc
=
zmq_bind
(
*
pub_
,
"inproc://soname"
);
TEST_ASSERT_EQUAL_INT
(
0
,
rc
);
void
*
sub0
=
zmq_socket
(
ctx
,
ZMQ_SUB
);
TEST_ASSERT_NOT_NULL
(
sub0
);
rc
=
zmq_connect
(
sub0
,
"inproc://soname"
);
*
sub0_
=
zmq_socket
(
ctx_
,
ZMQ_SUB
);
TEST_ASSERT_NOT_NULL
(
*
sub0_
);
rc
=
zmq_connect
(
*
sub0_
,
"inproc://soname"
);
TEST_ASSERT_EQUAL_INT
(
0
,
rc
);
void
*
sub1
=
zmq_socket
(
ctx
,
ZMQ_SUB
);
TEST_ASSERT_NOT_NULL
(
sub1
);
rc
=
zmq_connect
(
sub1
,
"inproc://soname"
);
*
sub1_
=
zmq_socket
(
ctx_
,
ZMQ_SUB
);
TEST_ASSERT_NOT_NULL
(
*
sub1_
);
rc
=
zmq_connect
(
*
sub1_
,
"inproc://soname"
);
TEST_ASSERT_EQUAL_INT
(
0
,
rc
);
}
// Subscribe for A on the first socket
rc
=
zmq_setsockopt
(
sub0
,
ZMQ_SUBSCRIBE
,
"A"
,
1
);
void
create_duplicate_subscription
(
void
*
pub_
,
void
*
sub0_
,
void
*
sub1_
)
{
// Subscribe for A
int
rc
=
zmq_setsockopt
(
sub0_
,
ZMQ_SUBSCRIBE
,
"A"
,
1
);
TEST_ASSERT_EQUAL_INT
(
0
,
rc
);
// Receive subscriptions from subscriber
rc
=
zmq_recv
(
pub
,
buffer
,
2
,
0
);
char
buffer
[
2
];
rc
=
zmq_recv
(
pub_
,
buffer
,
2
,
0
);
TEST_ASSERT_EQUAL_INT
(
2
,
rc
);
assert
(
buffer
[
0
]
==
1
);
assert
(
buffer
[
1
]
==
'A'
);
// Subscribe
for A on the second
socket
rc
=
zmq_setsockopt
(
sub1
,
ZMQ_SUBSCRIBE
,
"A"
,
1
);
// Subscribe
again for A on the other
socket
rc
=
zmq_setsockopt
(
sub1
_
,
ZMQ_SUBSCRIBE
,
"A"
,
1
);
TEST_ASSERT_EQUAL_INT
(
0
,
rc
);
// This time it is duplicated, so it will be filtered out
rc
=
zmq_recv
(
pub
,
buffer
,
1
,
ZMQ_DONTWAIT
);
// This time it is duplicated, so it will be filtered out
by XPUB
rc
=
zmq_recv
(
pub
_
,
buffer
,
1
,
ZMQ_DONTWAIT
);
TEST_ASSERT_EQUAL_INT
(
-
1
,
rc
);
TEST_ASSERT_EQUAL_INT
(
EAGAIN
,
errno
);
}
void
test_xpub_verbose_two_subs
()
{
int
rc
;
char
buffer
[
2
];
void
*
ctx
=
zmq_ctx_new
();
TEST_ASSERT_NOT_NULL
(
ctx
);
void
*
pub
,
*
sub0
,
*
sub1
;
create_xpub_with_2_subs
(
ctx
,
&
pub
,
&
sub0
,
&
sub1
);
create_duplicate_subscription
(
pub
,
sub0
,
sub1
);
// Subscribe socket for B instead
rc
=
zmq_setsockopt
(
sub0
,
ZMQ_SUBSCRIBE
,
"B"
,
1
);
...
...
@@ -351,39 +365,9 @@ void test_xpub_verboser_two_subs ()
void
*
ctx
=
zmq_ctx_new
();
TEST_ASSERT_NOT_NULL
(
ctx
);
void
*
pub
=
zmq_socket
(
ctx
,
ZMQ_XPUB
);
TEST_ASSERT_NOT_NULL
(
pub
);
rc
=
zmq_bind
(
pub
,
"inproc://soname"
);
TEST_ASSERT_EQUAL_INT
(
0
,
rc
);
void
*
sub0
=
zmq_socket
(
ctx
,
ZMQ_SUB
);
TEST_ASSERT_NOT_NULL
(
sub0
);
rc
=
zmq_connect
(
sub0
,
"inproc://soname"
);
TEST_ASSERT_EQUAL_INT
(
0
,
rc
);
void
*
sub1
=
zmq_socket
(
ctx
,
ZMQ_SUB
);
TEST_ASSERT_NOT_NULL
(
sub1
);
rc
=
zmq_connect
(
sub1
,
"inproc://soname"
);
TEST_ASSERT_EQUAL_INT
(
0
,
rc
);
// Subscribe for A
rc
=
zmq_setsockopt
(
sub0
,
ZMQ_SUBSCRIBE
,
"A"
,
1
);
TEST_ASSERT_EQUAL_INT
(
0
,
rc
);
// Receive subscriptions from subscriber
rc
=
zmq_recv
(
pub
,
buffer
,
2
,
0
);
TEST_ASSERT_EQUAL_INT
(
2
,
rc
);
assert
(
buffer
[
0
]
==
1
);
assert
(
buffer
[
1
]
==
'A'
);
// Subscribe again for A on the other socket
rc
=
zmq_setsockopt
(
sub1
,
ZMQ_SUBSCRIBE
,
"A"
,
1
);
TEST_ASSERT_EQUAL_INT
(
0
,
rc
);
// This time it is duplicated, so it will be filtered out by XPUB
rc
=
zmq_recv
(
pub
,
buffer
,
1
,
ZMQ_DONTWAIT
);
TEST_ASSERT_EQUAL_INT
(
-
1
,
rc
);
TEST_ASSERT_EQUAL_INT
(
EAGAIN
,
errno
);
void
*
pub
,
*
sub0
,
*
sub1
;
create_xpub_with_2_subs
(
ctx
,
&
pub
,
&
sub0
,
&
sub1
);
create_duplicate_subscription
(
pub
,
sub0
,
sub1
);
// Unsubscribe for A, this time it exists in XPUB
rc
=
zmq_setsockopt
(
sub0
,
ZMQ_UNSUBSCRIBE
,
"A"
,
1
);
...
...
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