0
0
mirror of https://github.com/zeromq/libzmq.git synced 2025-01-16 12:16:33 +08:00

Merge pull request #852 from hintjens/master

Fixes to test cases
This commit is contained in:
Martin Hurton 2014-01-23 08:23:23 -08:00
commit a7065519df
3 changed files with 8 additions and 25 deletions

2
.gitignore vendored
View File

@ -86,6 +86,8 @@ tests/test_sub_forward_tipc
tests/test_term_endpoint_tipc tests/test_term_endpoint_tipc
tests/test_many_sockets tests/test_many_sockets
tests/test_diffserv tests/test_diffserv
tests/test_srcfd
tests/test_stream_disconnect
tests/test*.log tests/test*.log
tests/test*.trs tests/test*.trs
src/platform.hpp* src/platform.hpp*

View File

@ -25,7 +25,7 @@ noinst_PROGRAMS = test_system \
test_probe_router \ test_probe_router \
test_stream \ test_stream \
test_stream_empty \ test_stream_empty \
test_stream_disconnect_notifications \ test_stream_disconnect \
test_disconnect_inproc \ test_disconnect_inproc \
test_ctx_options \ test_ctx_options \
test_ctx_destroy \ test_ctx_destroy \
@ -91,7 +91,7 @@ test_router_handover_SOURCES = test_router_handover.cpp
test_probe_router_SOURCES = test_probe_router.cpp test_probe_router_SOURCES = test_probe_router.cpp
test_stream_SOURCES = test_stream.cpp test_stream_SOURCES = test_stream.cpp
test_stream_empty_SOURCES = test_stream_empty.cpp test_stream_empty_SOURCES = test_stream_empty.cpp
test_stream_disconnect_notifications_SOURCES = test_stream_disconnect_notifications.cpp test_stream_disconnect_SOURCES = test_stream_disconnect.cpp
test_disconnect_inproc_SOURCES = test_disconnect_inproc.cpp test_disconnect_inproc_SOURCES = test_disconnect_inproc.cpp
test_ctx_options_SOURCES = test_ctx_options.cpp test_ctx_options_SOURCES = test_ctx_options.cpp
test_iov_SOURCES = test_iov.cpp test_iov_SOURCES = test_iov.cpp
@ -121,7 +121,6 @@ test_reqrep_ipc_SOURCES = test_reqrep_ipc.cpp testutil.hpp
test_timeo_SOURCES = test_timeo.cpp test_timeo_SOURCES = test_timeo.cpp
test_fork_SOURCES = test_fork.cpp test_fork_SOURCES = test_fork.cpp
test_filter_ipc_SOURCES = test_filter_ipc.cpp test_filter_ipc_SOURCES = test_filter_ipc.cpp
test_zap_ipc_creds_SOURCES = test_zap_ipc_creds.cpp
endif endif
if BUILD_TIPC if BUILD_TIPC
test_connect_delay_tipc_SOURCES = test_connect_delay_tipc.cpp test_connect_delay_tipc_SOURCES = test_connect_delay_tipc.cpp
@ -141,7 +140,3 @@ XFAIL_TESTS = test_resource
if !ON_LINUX if !ON_LINUX
XFAIL_TESTS += test_abstract_ipc XFAIL_TESTS += test_abstract_ipc
endif endif
if !HAVE_IPC_PEERCRED
XFAIL_TESTS += test_zap_ipc_creds
endif

View File

@ -40,9 +40,8 @@ bool has_more (void* socket)
int more = 0; int more = 0;
size_t more_size = sizeof(more); size_t more_size = sizeof(more);
int rc = zmq_getsockopt (socket, ZMQ_RCVMORE, &more, &more_size); int rc = zmq_getsockopt (socket, ZMQ_RCVMORE, &more, &more_size);
if (rc != 0) { if (rc != 0)
return false; return false;
}
return more != 0; return more != 0;
} }
@ -136,8 +135,6 @@ int main(int, char**)
int rc = zmq_poll (items, 2, 100); int rc = zmq_poll (items, 2, 100);
assert (rc >= 0); assert (rc >= 0);
printf ("Event received for step %d.\n", step);
// Check for data received by the server. // Check for data received by the server.
if (items [SERVER].revents & ZMQ_POLLIN) { if (items [SERVER].revents & ZMQ_POLLIN) {
assert (dialog [step].turn == CLIENT); assert (dialog [step].turn == CLIENT);
@ -164,15 +161,12 @@ int main(int, char**)
// 0-length frame is a disconnection notification. The server // 0-length frame is a disconnection notification. The server
// should receive it as the last step in the dialogue. // should receive it as the last step in the dialogue.
if (size == 0) { if (size == 0) {
printf ("server received disconnection notification!\n");
++step; ++step;
assert (step == steps); assert (step == steps);
} }
else { else {
printf ("server received %d bytes.\n", size); assert ((size_t) size == strlen (dialog [step].text));
fprintf(stderr, "size = %d, len = %ld\n", size, strlen(dialog [step].text)); int cmp = memcmp (dialog [step].text, data, size);
assert((size_t)size == strlen(dialog [step].text));
int cmp = memcmp(dialog [step].text, data, size);
assert (cmp == 0); assert (cmp == 0);
++step; ++step;
@ -189,8 +183,6 @@ int main(int, char**)
zmq_msg_size (&data_frame)); zmq_msg_size (&data_frame));
// Send the response. // Send the response.
printf ("server sending %d bytes.\n",
(int)zmq_msg_size (&data_frame));
rc = zmq_msg_send (&peer_frame, sockets [SERVER], ZMQ_SNDMORE); rc = zmq_msg_send (&peer_frame, sockets [SERVER], ZMQ_SNDMORE);
assert (rc != -1); assert (rc != -1);
rc = zmq_msg_send (&data_frame, sockets [SERVER], ZMQ_SNDMORE); rc = zmq_msg_send (&data_frame, sockets [SERVER], ZMQ_SNDMORE);
@ -228,13 +220,10 @@ int main(int, char**)
// Make sure payload matches what we expect. // Make sure payload matches what we expect.
const char * const data = (const char*)zmq_msg_data (&data_frame); const char * const data = (const char*)zmq_msg_data (&data_frame);
const int size = zmq_msg_size (&data_frame); const int size = zmq_msg_size (&data_frame);
fprintf(stderr, "size = %d, len = %ld\n", size, strlen(dialog [step].text)); assert ((size_t)size == strlen(dialog [step].text));
assert((size_t)size == strlen(dialog [step].text));
int cmp = memcmp(dialog [step].text, data, size); int cmp = memcmp(dialog [step].text, data, size);
assert (cmp == 0); assert (cmp == 0);
printf ("client received %d bytes.\n", size);
++step; ++step;
// Prepare the response (next line in the dialog). // Prepare the response (next line in the dialog).
@ -246,7 +235,6 @@ int main(int, char**)
memcpy (zmq_msg_data (&data_frame), dialog [step].text, zmq_msg_size (&data_frame)); memcpy (zmq_msg_data (&data_frame), dialog [step].text, zmq_msg_size (&data_frame));
// Send the response. // Send the response.
printf ("client sending %d bytes.\n", (int)zmq_msg_size (&data_frame));
rc = zmq_msg_send (&peer_frame, sockets [CLIENT], ZMQ_SNDMORE); rc = zmq_msg_send (&peer_frame, sockets [CLIENT], ZMQ_SNDMORE);
assert (rc != -1); assert (rc != -1);
rc = zmq_msg_send (&data_frame, sockets [CLIENT], ZMQ_SNDMORE); rc = zmq_msg_send (&data_frame, sockets [CLIENT], ZMQ_SNDMORE);
@ -260,8 +248,6 @@ int main(int, char**)
} }
} }
assert (step == steps); assert (step == steps);
printf ("Done, exiting now.\n");
rc = zmq_close (sockets [CLIENT]); rc = zmq_close (sockets [CLIENT]);
assert (rc == 0); assert (rc == 0);
rc = zmq_close (sockets [SERVER]); rc = zmq_close (sockets [SERVER]);