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
4ab38143
Commit
4ab38143
authored
Mar 22, 2019
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Problem: tests without test framework
Solution: migrate to Unity
parent
6f083df5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
65 deletions
+52
-65
Makefile.am
Makefile.am
+2
-1
test_term_endpoint_tipc.cpp
tests/test_term_endpoint_tipc.cpp
+50
-64
No files found.
Makefile.am
View file @
4ab38143
...
...
@@ -912,7 +912,8 @@ tests_test_sub_forward_tipc_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_sub_forward_tipc_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_term_endpoint_tipc_SOURCES
=
tests/test_term_endpoint_tipc.cpp
tests_test_term_endpoint_tipc_LDADD
=
src/libzmq.la
tests_test_term_endpoint_tipc_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
tests_test_term_endpoint_tipc_CPPFLAGS
=
${
UNITY_CPPFLAGS
}
tests_test_address_tipc_SOURCES
=
tests/test_address_tipc.cpp
tests_test_address_tipc_LDADD
=
src/libzmq.la
${
UNITY_LIBS
}
...
...
tests/test_term_endpoint_tipc.cpp
View file @
4ab38143
...
...
@@ -28,98 +28,84 @@
*/
#include "testutil.hpp"
#include "testutil_unity.hpp"
int
main
(
void
)
void
setUp
(
)
{
if
(
!
is_tipc_available
())
{
printf
(
"TIPC environment unavailable, skipping test
\n
"
);
return
77
;
}
setup_test_context
();
}
void
tearDown
()
{
teardown_test_context
();
}
int
rc
;
char
buf
[
32
];
const
char
*
ep
=
"tipc://{5560,0,0}"
;
const
char
*
name
=
"tipc://{5560,0}@0.0.0"
;
const
char
ep
[]
=
"tipc://{5560,0,0}"
;
const
char
name
[]
=
"tipc://{5560,0}@0.0.0"
;
fprintf
(
stderr
,
"unbind endpoint test running...
\n
"
);
void
test_term_endpoint_unbind_tipc
()
{
if
(
!
is_tipc_available
())
{
TEST_IGNORE_MESSAGE
(
"TIPC environment unavailable, skipping test
\n
"
);
}
// Create infrastructure.
void
*
ctx
=
zmq_init
(
1
);
assert
(
ctx
);
void
*
push
=
zmq_socket
(
ctx
,
ZMQ_PUSH
);
assert
(
push
);
rc
=
zmq_bind
(
push
,
ep
);
assert
(
rc
==
0
);
void
*
pull
=
zmq_socket
(
ctx
,
ZMQ_PULL
);
assert
(
pull
);
rc
=
zmq_connect
(
pull
,
name
);
assert
(
rc
==
0
);
void
*
push
=
test_context_socket
(
ZMQ_PUSH
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
push
,
ep
));
void
*
pull
=
test_context_socket
(
ZMQ_PULL
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
pull
,
name
));
// Pass one message through to ensure the connection is established.
rc
=
zmq_send
(
push
,
"ABC"
,
3
,
0
);
assert
(
rc
==
3
);
rc
=
zmq_recv
(
pull
,
buf
,
sizeof
(
buf
),
0
);
assert
(
rc
==
3
);
send_string_expect_success
(
push
,
"ABC"
,
0
);
recv_string_expect_success
(
pull
,
"ABC"
,
0
);
// Unbind the lisnening endpoint
rc
=
zmq_unbind
(
push
,
ep
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_unbind
(
push
,
ep
));
// Let events some time
msleep
(
SETTLE_TIME
);
// Check that sending would block (there's no outbound connection).
rc
=
zmq_send
(
push
,
"ABC"
,
3
,
ZMQ_DONTWAIT
);
assert
(
rc
==
-
1
&&
zmq_errno
()
==
EAGAIN
);
TEST_ASSERT_FAILURE_ERRNO
(
EAGAIN
,
zmq_send
(
push
,
"ABC"
,
3
,
ZMQ_DONTWAIT
));
// Clean up.
rc
=
zmq_close
(
pull
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
push
);
assert
(
rc
==
0
);
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
// Now the other way round.
fprintf
(
stderr
,
"disconnect endpoint test running...
\n
"
);
test_context_socket_close
(
pull
);
test_context_socket_close
(
push
);
}
void
test_term_endpoint_disconnect_tipc
()
{
if
(
!
is_tipc_available
())
{
TEST_IGNORE_MESSAGE
(
"TIPC environment unavailable, skipping test
\n
"
);
}
// Create infrastructure.
ctx
=
zmq_init
(
1
);
assert
(
ctx
);
push
=
zmq_socket
(
ctx
,
ZMQ_PUSH
);
assert
(
push
);
rc
=
zmq_connect
(
push
,
name
);
assert
(
rc
==
0
);
pull
=
zmq_socket
(
ctx
,
ZMQ_PULL
);
assert
(
pull
);
rc
=
zmq_bind
(
pull
,
ep
);
assert
(
rc
==
0
);
void
*
push
=
test_context_socket
(
ZMQ_PUSH
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_connect
(
push
,
name
));
void
*
pull
=
test_context_socket
(
ZMQ_PULL
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_bind
(
pull
,
ep
));
// Pass one message through to ensure the connection is established.
rc
=
zmq_send
(
push
,
"ABC"
,
3
,
0
);
assert
(
rc
==
3
);
rc
=
zmq_recv
(
pull
,
buf
,
sizeof
(
buf
),
0
);
assert
(
rc
==
3
);
send_string_expect_success
(
push
,
"ABC"
,
0
);
recv_string_expect_success
(
pull
,
"ABC"
,
0
);
// Disconnect the bound endpoint
rc
=
zmq_disconnect
(
push
,
name
);
assert
(
rc
==
0
);
TEST_ASSERT_SUCCESS_ERRNO
(
zmq_disconnect
(
push
,
name
));
msleep
(
SETTLE_TIME
);
// Check that sending would block (there's no inbound connections).
rc
=
zmq_send
(
push
,
"ABC"
,
3
,
ZMQ_DONTWAIT
);
assert
(
rc
==
-
1
&&
zmq_errno
()
==
EAGAIN
);
TEST_ASSERT_FAILURE_ERRNO
(
EAGAIN
,
zmq_send
(
push
,
"ABC"
,
3
,
ZMQ_DONTWAIT
));
// Clean up.
rc
=
zmq_close
(
pull
);
assert
(
rc
==
0
);
rc
=
zmq_close
(
push
);
assert
(
rc
==
0
);
rc
=
zmq_ctx_term
(
ctx
);
assert
(
rc
==
0
);
return
0
;
test_context_socket_close
(
pull
);
test_context_socket_close
(
push
);
}
int
main
(
void
)
{
UNITY_BEGIN
();
RUN_TEST
(
test_term_endpoint_unbind_tipc
);
RUN_TEST
(
test_term_endpoint_disconnect_tipc
);
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