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
fdfa9071
Commit
fdfa9071
authored
May 23, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: test_inproc_connect not using test framework
Solution: migrate to unity
parent
d02ba135
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
127 additions
and
295 deletions
+127
-295
Makefile.am
Makefile.am
+2
-1
test_inproc_connect.cpp
tests/test_inproc_connect.cpp
+125
-294
No files found.
Makefile.am
View file @
fdfa9071
...
@@ -593,7 +593,8 @@ tests_test_conflate_LDADD = src/libzmq.la ${UNITY_LIBS}
...
@@ -593,7 +593,8 @@ tests_test_conflate_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_conflate_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_conflate_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_inproc_connect_SOURCES
=
tests/test_inproc_connect.cpp
tests_test_inproc_connect_SOURCES
=
tests/test_inproc_connect.cpp
tests_test_inproc_connect_LDADD
=
src/libzmq.la
tests_test_inproc_connect_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_inproc_connect_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_issue_566_SOURCES
=
tests/test_issue_566.cpp
tests_test_issue_566_SOURCES
=
tests/test_issue_566.cpp
tests_test_issue_566_LDADD
=
src/libzmq.la
tests_test_issue_566_LDADD
=
src/libzmq.la
...
...
tests/test_inproc_connect.cpp
View file @
fdfa9071
...
@@ -28,294 +28,194 @@
...
@@ -28,294 +28,194 @@
*/
*/
#include "testutil.hpp"
#include "testutil.hpp"
#include "testutil_unity.hpp"
static
void
pusher
(
void
*
ctx
)
void
setUp
()
{
setup_test_context
();
}
void
tearDown
()
{
teardown_test_context
();
}
static
void
pusher
(
void
*
/*unused*/
)
{
{
// Connect first
// Connect first
void
*
connectSocket
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
void
*
connectSocket
=
test_context_socket
(
ZMQ_PAIR
);
assert
(
connectSocket
);
int
rc
=
zmq_connect
(
connectSocket
,
"inproc://sink"
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
connectSocket
,
"inproc://sink"
));
assert
(
rc
==
0
);
// Queue up some data
// Queue up some data
rc
=
zmq_send_const
(
connectSocket
,
"foobar"
,
6
,
0
);
send_string_expect_success
(
connectSocket
,
"foobar"
,
0
);
assert
(
rc
==
6
);
// Cleanup
// Cleanup
rc
=
zmq_close
(
connectSocket
);
test_context_socket_close
(
connectSocket
);
assert
(
rc
==
0
);
}
}
static
void
simult_conn
(
void
*
payload
)
static
void
simult_conn
(
void
*
endpt_
)
{
{
// Pull out arguments - context followed by endpoint string
// Pull out arguments - endpoint string
void
*
ctx
=
(
void
*
)
((
void
**
)
payload
)[
0
];
const
char
*
endpt
=
static_cast
<
const
char
*>
(
endpt_
);
char
*
endpt
=
(
char
*
)
((
void
**
)
payload
)[
1
];
// Connect
// Connect
void
*
connectSocket
=
zmq_socket
(
ctx
,
ZMQ_SUB
);
void
*
connectSocket
=
test_context_socket
(
ZMQ_SUB
);
assert
(
connectSocket
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
connectSocket
,
endpt
));
int
rc
=
zmq_connect
(
connectSocket
,
endpt
);
assert
(
rc
==
0
);
// Cleanup
// Cleanup
rc
=
zmq_close
(
connectSocket
);
test_context_socket_close
(
connectSocket
);
assert
(
rc
==
0
);
}
}
static
void
simult_bind
(
void
*
payload
)
static
void
simult_bind
(
void
*
endpt_
)
{
{
// Pull out arguments - context followed by endpoint string
// Pull out arguments - context followed by endpoint string
void
*
ctx
=
(
void
*
)
((
void
**
)
payload
)[
0
];
const
char
*
endpt
=
static_cast
<
const
char
*>
(
endpt_
);
char
*
endpt
=
(
char
*
)
((
void
**
)
payload
)[
1
];
// Bind
// Bind
void
*
bindSocket
=
zmq_socket
(
ctx
,
ZMQ_PUB
);
void
*
bindSocket
=
test_context_socket
(
ZMQ_PUB
);
assert
(
bindSocket
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
bindSocket
,
endpt
));
int
rc
=
zmq_bind
(
bindSocket
,
endpt
);
assert
(
rc
==
0
);
// Cleanup
// Cleanup
rc
=
zmq_close
(
bindSocket
);
test_context_socket_close
(
bindSocket
);
assert
(
rc
==
0
);
}
}
void
test_bind_before_connect
()
void
test_bind_before_connect
()
{
{
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
// Bind first
// Bind first
void
*
bindSocket
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
void
*
bindSocket
=
test_context_socket
(
ZMQ_PAIR
);
assert
(
bindSocket
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
bindSocket
,
"inproc://bbc"
));
int
rc
=
zmq_bind
(
bindSocket
,
"inproc://bbc"
);
assert
(
rc
==
0
);
// Now connect
// Now connect
void
*
connectSocket
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
void
*
connectSocket
=
test_context_socket
(
ZMQ_PAIR
);
assert
(
connectSocket
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
connectSocket
,
"inproc://bbc"
));
rc
=
zmq_connect
(
connectSocket
,
"inproc://bbc"
);
assert
(
rc
==
0
);
// Queue up some data
// Queue up some data
rc
=
zmq_send_const
(
connectSocket
,
"foobar"
,
6
,
0
);
send_string_expect_success
(
connectSocket
,
"foobar"
,
0
);
assert
(
rc
==
6
);
// Read pending message
// Read pending message
zmq_msg_t
msg
;
recv_string_expect_success
(
bindSocket
,
"foobar"
,
0
);
rc
=
zmq_msg_init
(
&
msg
);
assert
(
rc
==
0
);
rc
=
zmq_msg_recv
(
&
msg
,
bindSocket
,
0
);
assert
(
rc
==
6
);
void
*
data
=
zmq_msg_data
(
&
msg
);
assert
(
memcmp
(
"foobar"
,
data
,
6
)
==
0
);
// Cleanup
// Cleanup
rc
=
zmq_close
(
connectSocket
);
test_context_socket_close
(
connectSocket
);
assert
(
rc
==
0
);
test_context_socket_close
(
bindSocket
);
rc
=
zmq_close
(
bindSocket
);
assert
(
rc
==
0
);
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
}
}
void
test_connect_before_bind
()
void
test_connect_before_bind
()
{
{
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
// Connect first
// Connect first
void
*
connectSocket
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
void
*
connectSocket
=
test_context_socket
(
ZMQ_PAIR
);
assert
(
connectSocket
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
connectSocket
,
"inproc://cbb"
));
int
rc
=
zmq_connect
(
connectSocket
,
"inproc://cbb"
);
assert
(
rc
==
0
);
// Queue up some data
// Queue up some data
rc
=
zmq_send_const
(
connectSocket
,
"foobar"
,
6
,
0
);
send_string_expect_success
(
connectSocket
,
"foobar"
,
0
);
assert
(
rc
==
6
);
// Now bind
// Now bind
void
*
bindSocket
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
void
*
bindSocket
=
test_context_socket
(
ZMQ_PAIR
);
assert
(
bindSocket
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
bindSocket
,
"inproc://cbb"
));
rc
=
zmq_bind
(
bindSocket
,
"inproc://cbb"
);
assert
(
rc
==
0
);
// Read pending message
// Read pending message
zmq_msg_t
msg
;
recv_string_expect_success
(
bindSocket
,
"foobar"
,
0
);
rc
=
zmq_msg_init
(
&
msg
);
assert
(
rc
==
0
);
rc
=
zmq_msg_recv
(
&
msg
,
bindSocket
,
0
);
assert
(
rc
==
6
);
void
*
data
=
zmq_msg_data
(
&
msg
);
assert
(
memcmp
(
"foobar"
,
data
,
6
)
==
0
);
// Cleanup
// Cleanup
rc
=
zmq_close
(
connectSocket
);
test_context_socket_close
(
connectSocket
);
assert
(
rc
==
0
);
test_context_socket_close
(
bindSocket
);
rc
=
zmq_close
(
bindSocket
);
assert
(
rc
==
0
);
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
}
}
void
test_connect_before_bind_pub_sub
()
void
test_connect_before_bind_pub_sub
()
{
{
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
// Connect first
// Connect first
void
*
connectSocket
=
zmq_socket
(
ctx
,
ZMQ_PUB
);
void
*
connectSocket
=
test_context_socket
(
ZMQ_PUB
);
assert
(
connectSocket
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
connectSocket
,
"inproc://cbbps"
));
int
rc
=
zmq_connect
(
connectSocket
,
"inproc://cbbps"
);
assert
(
rc
==
0
);
// Queue up some data, this will be dropped
// Queue up some data, this will be dropped
rc
=
zmq_send_const
(
connectSocket
,
"before"
,
6
,
0
);
send_string_expect_success
(
connectSocket
,
"before"
,
0
);
assert
(
rc
==
6
);
// Now bind
// Now bind
void
*
bindSocket
=
zmq_socket
(
ctx
,
ZMQ_SUB
);
void
*
bindSocket
=
test_context_socket
(
ZMQ_SUB
);
assert
(
bindSocket
);
TEST_ASSERT_SUCCESS_ERRNO
(
rc
=
zmq_setsockopt
(
bindSocket
,
ZMQ_SUBSCRIBE
,
""
,
0
);
zmq_setsockopt
(
bindSocket
,
ZMQ_SUBSCRIBE
,
""
,
0
));
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
bindSocket
,
"inproc://cbbps"
));
rc
=
zmq_bind
(
bindSocket
,
"inproc://cbbps"
);
assert
(
rc
==
0
);
// Wait for pub-sub connection to happen
// Wait for pub-sub connection to happen
msleep
(
SETTLE_TIME
);
msleep
(
SETTLE_TIME
);
// Queue up some data, this not will be dropped
// Queue up some data, this not will be dropped
rc
=
zmq_send_const
(
connectSocket
,
"after"
,
6
,
0
);
send_string_expect_success
(
connectSocket
,
"after"
,
0
);
assert
(
rc
==
6
);
// Read pending message
// Read pending message
zmq_msg_t
msg
;
recv_string_expect_success
(
bindSocket
,
"after"
,
0
);
rc
=
zmq_msg_init
(
&
msg
);
assert
(
rc
==
0
);
rc
=
zmq_msg_recv
(
&
msg
,
bindSocket
,
0
);
assert
(
rc
==
6
);
void
*
data
=
zmq_msg_data
(
&
msg
);
assert
(
memcmp
(
"after"
,
data
,
5
)
==
0
);
// Cleanup
// Cleanup
rc
=
zmq_close
(
connectSocket
);
test_context_socket_close
(
connectSocket
);
assert
(
rc
==
0
);
test_context_socket_close
(
bindSocket
);
rc
=
zmq_close
(
bindSocket
);
assert
(
rc
==
0
);
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
}
}
void
test_connect_before_bind_ctx_term
()
void
test_connect_before_bind_ctx_term
()
{
{
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
for
(
int
i
=
0
;
i
<
20
;
++
i
)
{
for
(
int
i
=
0
;
i
<
20
;
++
i
)
{
// Connect first
// Connect first
void
*
connectSocket
=
zmq_socket
(
ctx
,
ZMQ_ROUTER
);
void
*
connectSocket
=
test_context_socket
(
ZMQ_ROUTER
);
assert
(
connectSocket
);
char
ep
[
20
];
char
ep
[
20
];
sprintf
(
ep
,
"inproc://cbbrr%d"
,
i
);
sprintf
(
ep
,
"inproc://cbbrr%d"
,
i
);
int
rc
=
zmq_connect
(
connectSocket
,
ep
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
connectSocket
,
ep
));
assert
(
rc
==
0
);
// Cleanup
// Cleanup
rc
=
zmq_close
(
connectSocket
);
test_context_socket_close
(
connectSocket
);
assert
(
rc
==
0
);
}
}
int
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
}
}
void
test_multiple_connects
()
void
test_multiple_connects
()
{
{
const
unsigned
int
no_of_connects
=
10
;
const
unsigned
int
no_of_connects
=
10
;
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
int
rc
;
void
*
connectSocket
[
no_of_connects
];
void
*
connectSocket
[
no_of_connects
];
// Connect first
// Connect first
for
(
unsigned
int
i
=
0
;
i
<
no_of_connects
;
++
i
)
{
for
(
unsigned
int
i
=
0
;
i
<
no_of_connects
;
++
i
)
{
connectSocket
[
i
]
=
zmq_socket
(
ctx
,
ZMQ_PUSH
);
connectSocket
[
i
]
=
test_context_socket
(
ZMQ_PUSH
);
assert
(
connectSocket
[
i
]);
TEST_ASSERT_SUCCESS_ERRNO
(
rc
=
zmq_connect
(
connectSocket
[
i
],
"inproc://multiple"
);
zmq_connect
(
connectSocket
[
i
],
"inproc://multiple"
));
assert
(
rc
==
0
);
// Queue up some data
// Queue up some data
rc
=
zmq_send_const
(
connectSocket
[
i
],
"foobar"
,
6
,
0
);
send_string_expect_success
(
connectSocket
[
i
],
"foobar"
,
0
);
assert
(
rc
==
6
);
}
}
// Now bind
// Now bind
void
*
bindSocket
=
zmq_socket
(
ctx
,
ZMQ_PULL
);
void
*
bindSocket
=
test_context_socket
(
ZMQ_PULL
);
assert
(
bindSocket
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
bindSocket
,
"inproc://multiple"
));
rc
=
zmq_bind
(
bindSocket
,
"inproc://multiple"
);
assert
(
rc
==
0
);
for
(
unsigned
int
i
=
0
;
i
<
no_of_connects
;
++
i
)
{
for
(
unsigned
int
i
=
0
;
i
<
no_of_connects
;
++
i
)
{
// Read pending message
recv_string_expect_success
(
bindSocket
,
"foobar"
,
0
);
zmq_msg_t
msg
;
rc
=
zmq_msg_init
(
&
msg
);
assert
(
rc
==
0
);
rc
=
zmq_msg_recv
(
&
msg
,
bindSocket
,
0
);
assert
(
rc
==
6
);
void
*
data
=
zmq_msg_data
(
&
msg
);
assert
(
memcmp
(
"foobar"
,
data
,
6
)
==
0
);
}
}
// Cleanup
// Cleanup
for
(
unsigned
int
i
=
0
;
i
<
no_of_connects
;
++
i
)
{
for
(
unsigned
int
i
=
0
;
i
<
no_of_connects
;
++
i
)
{
rc
=
zmq_close
(
connectSocket
[
i
]);
test_context_socket_close
(
connectSocket
[
i
]);
assert
(
rc
==
0
);
}
}
rc
=
zmq_close
(
bindSocket
);
test_context_socket_close
(
bindSocket
);
assert
(
rc
==
0
);
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
}
}
void
test_multiple_threads
()
void
test_multiple_threads
()
{
{
const
unsigned
int
no_of_threads
=
30
;
const
unsigned
int
no_of_threads
=
30
;
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
int
rc
;
void
*
threads
[
no_of_threads
];
void
*
threads
[
no_of_threads
];
// Connect first
// Connect first
for
(
unsigned
int
i
=
0
;
i
<
no_of_threads
;
++
i
)
{
for
(
unsigned
int
i
=
0
;
i
<
no_of_threads
;
++
i
)
{
threads
[
i
]
=
zmq_threadstart
(
&
pusher
,
ctx
);
threads
[
i
]
=
zmq_threadstart
(
&
pusher
,
NULL
);
}
}
// Now bind
// Now bind
void
*
bindSocket
=
zmq_socket
(
ctx
,
ZMQ_PULL
);
void
*
bindSocket
=
test_context_socket
(
ZMQ_PULL
);
assert
(
bindSocket
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
bindSocket
,
"inproc://sink"
));
rc
=
zmq_bind
(
bindSocket
,
"inproc://sink"
);
assert
(
rc
==
0
);
for
(
unsigned
int
i
=
0
;
i
<
no_of_threads
;
++
i
)
{
for
(
unsigned
int
i
=
0
;
i
<
no_of_threads
;
++
i
)
{
// Read pending message
// Read pending message
zmq_msg_t
msg
;
recv_string_expect_success
(
bindSocket
,
"foobar"
,
0
);
rc
=
zmq_msg_init
(
&
msg
);
assert
(
rc
==
0
);
rc
=
zmq_msg_recv
(
&
msg
,
bindSocket
,
0
);
assert
(
rc
==
6
);
void
*
data
=
zmq_msg_data
(
&
msg
);
assert
(
memcmp
(
"foobar"
,
data
,
6
)
==
0
);
}
}
// Cleanup
// Cleanup
...
@@ -323,27 +223,19 @@ void test_multiple_threads ()
...
@@ -323,27 +223,19 @@ void test_multiple_threads ()
zmq_threadclose
(
threads
[
i
]);
zmq_threadclose
(
threads
[
i
]);
}
}
rc
=
zmq_close
(
bindSocket
);
test_context_socket_close
(
bindSocket
);
assert
(
rc
==
0
);
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
}
}
void
test_simultaneous_connect_bind_threads
()
void
test_simultaneous_connect_bind_threads
()
{
{
const
unsigned
int
no_of_times
=
50
;
const
unsigned
int
no_of_times
=
50
;
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
void
*
threads
[
no_of_times
*
2
];
void
*
threads
[
no_of_times
*
2
];
void
*
thr_args
[
no_of_times
]
[
2
]
;
void
*
thr_args
[
no_of_times
];
char
endpts
[
no_of_times
][
20
];
char
endpts
[
no_of_times
][
20
];
// Set up thread arguments: context followed by endpoint string
// Set up thread arguments: context followed by endpoint string
for
(
unsigned
int
i
=
0
;
i
<
no_of_times
;
++
i
)
{
for
(
unsigned
int
i
=
0
;
i
<
no_of_times
;
++
i
)
{
thr_args
[
i
][
0
]
=
(
void
*
)
ctx
;
thr_args
[
i
]
=
(
void
*
)
endpts
[
i
];
thr_args
[
i
][
1
]
=
(
void
*
)
endpts
[
i
];
sprintf
(
endpts
[
i
],
"inproc://foo_%d"
,
i
);
sprintf
(
endpts
[
i
],
"inproc://foo_%d"
,
i
);
}
}
...
@@ -360,170 +252,109 @@ void test_simultaneous_connect_bind_threads ()
...
@@ -360,170 +252,109 @@ void test_simultaneous_connect_bind_threads ()
zmq_threadclose
(
threads
[
i
*
2
+
0
]);
zmq_threadclose
(
threads
[
i
*
2
+
0
]);
zmq_threadclose
(
threads
[
i
*
2
+
1
]);
zmq_threadclose
(
threads
[
i
*
2
+
1
]);
}
}
int
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
}
}
void
test_routing_id
()
void
test_routing_id
()
{
{
// Create the infrastructure
// Create the infrastructure
void
*
ctx
=
zmq_ctx_new
();
void
*
sc
=
test_context_socket
(
ZMQ_DEALER
);
assert
(
ctx
);
void
*
sc
=
zmq_socket
(
ctx
,
ZMQ_DEALER
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
sc
,
"inproc://routing_id"
));
assert
(
sc
);
int
rc
=
zmq_connect
(
sc
,
"inproc://routing_id"
);
void
*
sb
=
test_context_socket
(
ZMQ_ROUTER
);
assert
(
rc
==
0
);
void
*
sb
=
zmq_socket
(
ctx
,
ZMQ_ROUTER
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
sb
,
"inproc://routing_id"
));
assert
(
sb
);
rc
=
zmq_bind
(
sb
,
"inproc://routing_id"
);
assert
(
rc
==
0
);
// Send 2-part message.
// Send 2-part message.
rc
=
zmq_send
(
sc
,
"A"
,
1
,
ZMQ_SNDMORE
);
TEST_ASSERT_EQUAL_INT
(
assert
(
rc
==
1
);
1
,
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_send
(
sc
,
"A"
,
1
,
ZMQ_SNDMORE
))
);
rc
=
zmq_send
(
sc
,
"B"
,
1
,
0
);
TEST_ASSERT_EQUAL_INT
(
assert
(
rc
==
1
);
1
,
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_send
(
sc
,
"B"
,
1
,
0
))
);
// Routing id comes first.
// Routing id comes first.
zmq_msg_t
msg
;
zmq_msg_t
msg
;
rc
=
zmq_msg_init
(
&
msg
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_init
(
&
msg
));
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
msg
,
sb
,
0
));
rc
=
zmq_msg_recv
(
&
msg
,
sb
,
0
);
TEST_ASSERT_EQUAL_INT
(
1
,
zmq_msg_more
(
&
msg
));
assert
(
rc
>=
0
);
int
more
=
zmq_msg_more
(
&
msg
);
assert
(
more
==
1
);
// Then the first part of the message body.
// Then the first part of the message body.
rc
=
zmq_msg_recv
(
&
msg
,
sb
,
0
);
TEST_ASSERT_EQUAL_INT
(
assert
(
rc
==
1
);
1
,
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
msg
,
sb
,
0
)));
more
=
zmq_msg_more
(
&
msg
);
TEST_ASSERT_EQUAL_INT
(
1
,
zmq_msg_more
(
&
msg
));
assert
(
more
==
1
);
// And finally, the second part of the message body.
// And finally, the second part of the message body.
rc
=
zmq_msg_recv
(
&
msg
,
sb
,
0
);
TEST_ASSERT_EQUAL_INT
(
assert
(
rc
==
1
);
1
,
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_msg_recv
(
&
msg
,
sb
,
0
)));
more
=
zmq_msg_more
(
&
msg
);
TEST_ASSERT_EQUAL_INT
(
0
,
zmq_msg_more
(
&
msg
));
assert
(
more
==
0
);
// Deallocate the infrastructure.
// Deallocate the infrastructure.
rc
=
zmq_close
(
sc
);
test_context_socket_close
(
sc
);
assert
(
rc
==
0
);
test_context_socket_close
(
sb
);
rc
=
zmq_close
(
sb
);
assert
(
rc
==
0
);
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
}
}
void
test_connect_only
()
void
test_connect_only
()
{
{
void
*
ctx
=
zmq_ctx_new
();
void
*
connectSocket
=
test_context_socket
(
ZMQ_PUSH
);
assert
(
ctx
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
connectSocket
,
"inproc://a"
));
void
*
connectSocket
=
zmq_socket
(
ctx
,
ZMQ_PUSH
);
assert
(
connectSocket
);
int
rc
=
zmq_connect
(
connectSocket
,
"inproc://a"
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
connectSocket
);
assert
(
rc
==
0
);
rc
=
zmq_ctx_term
(
ctx
);
test_context_socket_close
(
connectSocket
);
assert
(
rc
==
0
);
}
}
void
test_unbind
()
void
test_unbind
()
{
{
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
// Bind and unbind socket 1
// Bind and unbind socket 1
void
*
bindSocket1
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
void
*
bindSocket1
=
test_context_socket
(
ZMQ_PAIR
);
assert
(
bindSocket1
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
bindSocket1
,
"inproc://unbind"
));
int
rc
=
zmq_bind
(
bindSocket1
,
"inproc://unbind"
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_unbind
(
bindSocket1
,
"inproc://unbind"
));
assert
(
rc
==
0
);
zmq_unbind
(
bindSocket1
,
"inproc://unbind"
);
assert
(
rc
==
0
);
// Bind socket 2
// Bind socket 2
void
*
bindSocket2
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
void
*
bindSocket2
=
test_context_socket
(
ZMQ_PAIR
);
assert
(
bindSocket2
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
bindSocket2
,
"inproc://unbind"
));
rc
=
zmq_bind
(
bindSocket2
,
"inproc://unbind"
);
assert
(
rc
==
0
);
// Now connect
// Now connect
void
*
connectSocket
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
void
*
connectSocket
=
test_context_socket
(
ZMQ_PAIR
);
assert
(
connectSocket
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
connectSocket
,
"inproc://unbind"
));
rc
=
zmq_connect
(
connectSocket
,
"inproc://unbind"
);
assert
(
rc
==
0
);
// Queue up some data
// Queue up some data
rc
=
zmq_send_const
(
connectSocket
,
"foobar"
,
6
,
0
);
send_string_expect_success
(
connectSocket
,
"foobar"
,
0
);
assert
(
rc
==
6
);
// Read pending message
// Read pending message
zmq_msg_t
msg
;
recv_string_expect_success
(
bindSocket2
,
"foobar"
,
0
);
rc
=
zmq_msg_init
(
&
msg
);
assert
(
rc
==
0
);
rc
=
zmq_msg_recv
(
&
msg
,
bindSocket2
,
0
);
assert
(
rc
==
6
);
void
*
data
=
zmq_msg_data
(
&
msg
);
assert
(
memcmp
(
"foobar"
,
data
,
6
)
==
0
);
// Cleanup
// Cleanup
rc
=
zmq_close
(
connectSocket
);
test_context_socket_close
(
connectSocket
);
assert
(
rc
==
0
);
test_context_socket_close
(
bindSocket1
);
rc
=
zmq_close
(
bindSocket1
);
test_context_socket_close
(
bindSocket2
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
bindSocket2
);
assert
(
rc
==
0
);
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
}
}
void
test_shutdown_during_pend
()
void
test_shutdown_during_pend
()
{
{
void
*
ctx
=
zmq_ctx_new
();
assert
(
ctx
);
// Connect first
// Connect first
void
*
connectSocket
=
zmq_socket
(
ctx
,
ZMQ_PAIR
);
void
*
connectSocket
=
test_context_socket
(
ZMQ_PAIR
);
assert
(
connectSocket
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
connectSocket
,
"inproc://cbb"
));
int
rc
=
zmq_connect
(
connectSocket
,
"inproc://cbb"
);
assert
(
rc
==
0
);
zmq_ctx_shutdown
(
ctx
);
zmq_ctx_shutdown
(
get_test_context
()
);
// Cleanup
// Cleanup
rc
=
zmq_close
(
connectSocket
);
test_context_socket_close
(
connectSocket
);
assert
(
rc
==
0
);
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
}
}
int
main
(
void
)
int
main
(
void
)
{
{
setup_test_environment
();
setup_test_environment
();
test_bind_before_connect
();
UNITY_BEGIN
();
test_connect_before_bind
(
);
RUN_TEST
(
test_bind_before_connect
);
test_connect_before_bind_pub_sub
(
);
RUN_TEST
(
test_connect_before_bind
);
test_connect_before_bind_ctx_term
(
);
RUN_TEST
(
test_connect_before_bind_pub_sub
);
test_multiple_connects
(
);
RUN_TEST
(
test_connect_before_bind_ctx_term
);
test_multiple_threads
(
);
RUN_TEST
(
test_multiple_connects
);
test_simultaneous_connect_bind_threads
(
);
RUN_TEST
(
test_multiple_threads
);
test_routing_id
(
);
RUN_TEST
(
test_simultaneous_connect_bind_threads
);
test_connect_only
(
);
RUN_TEST
(
test_routing_id
);
test_unbind
(
);
RUN_TEST
(
test_connect_only
);
test_shutdown_during_pend
(
);
RUN_TEST
(
test_unbind
);
RUN_TEST
(
test_shutdown_during_pend
);
return
0
;
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