Commit f92cdf94 authored by Simon Giesecke's avatar Simon Giesecke

Problem: test_ctx_destroy not using unity, and mixing test cases

Solution: migrate to unit and split up test cases
parent b2e50d9d
...@@ -545,7 +545,8 @@ tests_test_iov_SOURCES = tests/test_iov.cpp ...@@ -545,7 +545,8 @@ tests_test_iov_SOURCES = tests/test_iov.cpp
tests_test_iov_LDADD = src/libzmq.la tests_test_iov_LDADD = src/libzmq.la
tests_test_ctx_destroy_SOURCES = tests/test_ctx_destroy.cpp tests_test_ctx_destroy_SOURCES = tests/test_ctx_destroy.cpp
tests_test_ctx_destroy_LDADD = src/libzmq.la tests_test_ctx_destroy_LDADD = src/libzmq.la ${UNITY_LIBS}
tests_test_ctx_destroy_CPPFLAGS = ${UNITY_CPPFLAGS}
tests_test_security_null_SOURCES = tests/test_security_null.cpp tests_test_security_null_SOURCES = tests/test_security_null.cpp
tests_test_security_null_LDADD = src/libzmq.la tests_test_security_null_LDADD = src/libzmq.la
......
...@@ -28,6 +28,17 @@ ...@@ -28,6 +28,17 @@
*/ */
#include "testutil.hpp" #include "testutil.hpp"
#include "testutil_unity.hpp"
#include <unity.h>
void setUp ()
{
}
void tearDown ()
{
}
static void receiver (void *socket) static void receiver (void *socket)
{ {
...@@ -38,40 +49,28 @@ static void receiver (void *socket) ...@@ -38,40 +49,28 @@ static void receiver (void *socket)
void test_ctx_destroy () void test_ctx_destroy ()
{ {
int rc;
// Set up our context and sockets // Set up our context and sockets
void *ctx = zmq_ctx_new (); void *ctx = zmq_ctx_new ();
assert (ctx); TEST_ASSERT_NOT_NULL (ctx);
void *socket = zmq_socket (ctx, ZMQ_PULL); void *socket = zmq_socket (ctx, ZMQ_PULL);
assert (socket); TEST_ASSERT_NOT_NULL (socket);
// Close the socket // Close the socket
rc = zmq_close (socket); TEST_ASSERT_SUCCESS_ERRNO (zmq_close (socket));
assert (rc == 0);
// Test error - API has multiple ways to kill Contexts
rc = zmq_ctx_term (NULL);
assert (rc == -1 && errno == EFAULT);
rc = zmq_term (NULL);
assert (rc == -1 && errno == EFAULT);
// Destroy the context // Destroy the context
rc = zmq_ctx_destroy (ctx); TEST_ASSERT_SUCCESS_ERRNO (zmq_ctx_destroy (ctx));
assert (rc == 0);
} }
void test_ctx_shutdown () void test_ctx_shutdown ()
{ {
int rc;
// Set up our context and sockets // Set up our context and sockets
void *ctx = zmq_ctx_new (); void *ctx = zmq_ctx_new ();
assert (ctx); TEST_ASSERT_NOT_NULL (ctx);
void *socket = zmq_socket (ctx, ZMQ_PULL); void *socket = zmq_socket (ctx, ZMQ_PULL);
assert (socket); TEST_ASSERT_NOT_NULL (socket);
// Spawn a thread to receive on socket // Spawn a thread to receive on socket
void *receiver_thread = zmq_threadstart (&receiver, socket); void *receiver_thread = zmq_threadstart (&receiver, socket);
...@@ -79,32 +78,49 @@ void test_ctx_shutdown () ...@@ -79,32 +78,49 @@ void test_ctx_shutdown ()
// Wait for thread to start up and block // Wait for thread to start up and block
msleep (SETTLE_TIME); msleep (SETTLE_TIME);
// Test error - Shutdown context
rc = zmq_ctx_shutdown (NULL);
assert (rc == -1 && errno == EFAULT);
// Shutdown context, if we used destroy here we would deadlock. // Shutdown context, if we used destroy here we would deadlock.
rc = zmq_ctx_shutdown (ctx); TEST_ASSERT_SUCCESS_ERRNO (zmq_ctx_shutdown (ctx));
assert (rc == 0);
// Wait for thread to finish // Wait for thread to finish
zmq_threadclose (receiver_thread); zmq_threadclose (receiver_thread);
// Close the socket. // Close the socket.
rc = zmq_close (socket); TEST_ASSERT_SUCCESS_ERRNO (zmq_close (socket));
assert (rc == 0);
// Destory the context, will now not hang as we have closed the socket. // Destory the context, will now not hang as we have closed the socket.
rc = zmq_ctx_destroy (ctx); TEST_ASSERT_SUCCESS_ERRNO (zmq_ctx_destroy (ctx));
assert (rc == 0); }
void test_zmq_ctx_term_null_fails ()
{
int rc = zmq_ctx_term (NULL);
TEST_ASSERT_EQUAL_INT (-1, rc);
TEST_ASSERT_EQUAL_INT (EFAULT, errno);
}
void test_zmq_term_null_fails ()
{
int rc = zmq_term (NULL);
TEST_ASSERT_EQUAL_INT (-1, rc);
TEST_ASSERT_EQUAL_INT (EFAULT, errno);
}
void test_zmq_ctx_shutdown_null_fails ()
{
int rc = zmq_ctx_shutdown (NULL);
TEST_ASSERT_EQUAL_INT (-1, rc);
TEST_ASSERT_EQUAL_INT (EFAULT, errno);
} }
int main (void) int main (void)
{ {
setup_test_environment (); setup_test_environment ();
test_ctx_destroy (); UNITY_BEGIN ();
test_ctx_shutdown (); RUN_TEST (test_ctx_destroy);
RUN_TEST (test_ctx_shutdown);
return 0; RUN_TEST (test_zmq_ctx_term_null_fails);
RUN_TEST (test_zmq_term_null_fails);
RUN_TEST (test_zmq_ctx_shutdown_null_fails);
return UNITY_END ();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment