From 740780293a4532bf6c36468204f40d3d4efdef46 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Fri, 22 Mar 2019 09:30:09 -0400 Subject: [PATCH] Problem: tests without test framework Solution: migrate to Unity --- Makefile.am | 6 +++-- tests/test_pair_vmci.cpp | 48 +++++++++++++++++++++----------------- tests/test_reqrep_vmci.cpp | 48 +++++++++++++++++++++----------------- 3 files changed, 56 insertions(+), 46 deletions(-) diff --git a/Makefile.am b/Makefile.am index 524ff350..87fe18b8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -941,12 +941,14 @@ if HAVE_VMCI test_apps += test_pair_vmci test_reqrep_vmci test_pair_vmci_SOURCES = tests/test_pair_vmci.cpp -test_pair_vmci_LDADD = src/libzmq.la +test_pair_vmci_LDADD = src/libzmq.la ${UNITY_LIBS} +test_pair_vmci_CPPFLAGS = ${UNITY_CPPFLAGS} test_pair_vmci_LDFLAGS = @LIBZMQ_VMCI_LDFLAGS@ test_pair_vmci_CXXFLAGS = @LIBZMQ_VMCI_CXXFLAGS@ test_reqrep_vmci_SOURCES = tests/test_reqrep_vmci.cpp -test_reqrep_vmci_LDADD = src/libzmq.la +test_reqrep_vmci_LDADD = src/libzmq.la ${UNITY_LIBS} +test_reqrep_vmci_CPPFLAGS = ${UNITY_CPPFLAGS} test_reqrep_vmci_LDFLAGS = @LIBZMQ_VMCI_LDFLAGS@ test_reqrep_vmci_CXXFLAGS = @LIBZMQ_VMCI_CXXFLAGS@ diff --git a/tests/test_pair_vmci.cpp b/tests/test_pair_vmci.cpp index c190deae..850e794f 100644 --- a/tests/test_pair_vmci.cpp +++ b/tests/test_pair_vmci.cpp @@ -32,37 +32,41 @@ #include #include "testutil.hpp" +#include "testutil_unity.hpp" -int main (void) +void setUp () { - setup_test_environment (); - void *ctx = zmq_ctx_new (); - assert (ctx); + setup_test_context (); +} +void tearDown () +{ + teardown_test_context (); +} + +void test_pair_vmci () +{ std::stringstream s; s << "vmci://" << VMCISock_GetLocalCID () << ":" << 5560; std::string endpoint = s.str (); - void *sb = zmq_socket (ctx, ZMQ_PAIR); - assert (sb); - int rc = zmq_bind (sb, endpoint.c_str ()); - assert (rc == 0); + void *sb = test_context_socket (ZMQ_PAIR); + TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, endpoint.c_str ())); - void *sc = zmq_socket (ctx, ZMQ_PAIR); - assert (sc); - rc = zmq_connect (sc, endpoint.c_str ()); - assert (rc == 0); + void *sc = test_context_socket (ZMQ_PAIR); + TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, endpoint.c_str ())); bounce (sb, sc); - rc = zmq_close (sc); - assert (rc == 0); - - rc = zmq_close (sb); - assert (rc == 0); - - rc = zmq_ctx_term (ctx); - assert (rc == 0); - - return 0; + test_context_socket_close (sc); + test_context_socket_close (sb); +} + +int main (void) +{ + setup_test_environment (); + + UNITY_BEGIN (); + RUN_TEST (test_pair_vmci); + return UNITY_END (); } diff --git a/tests/test_reqrep_vmci.cpp b/tests/test_reqrep_vmci.cpp index 6cae22b1..09970eae 100644 --- a/tests/test_reqrep_vmci.cpp +++ b/tests/test_reqrep_vmci.cpp @@ -32,37 +32,41 @@ #include #include "testutil.hpp" +#include "testutil_unity.hpp" -int main (void) +void setUp () { - setup_test_environment (); - void *ctx = zmq_ctx_new (); - assert (ctx); + setup_test_context (); +} +void tearDown () +{ + teardown_test_context (); +} + +void test_reqrep_vmci () +{ std::stringstream s; s << "vmci://" << VMCISock_GetLocalCID () << ":" << 5560; std::string endpoint = s.str (); - void *sb = zmq_socket (ctx, ZMQ_REP); - assert (sb); - int rc = zmq_bind (sb, endpoint.c_str ()); - assert (rc == 0); + void *sb = test_context_socket (ZMQ_REP); + TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, endpoint.c_str ())); - void *sc = zmq_socket (ctx, ZMQ_REQ); - assert (sc); - rc = zmq_connect (sc, endpoint.c_str ()); - assert (rc == 0); + void *sc = test_context_socket (ZMQ_REQ); + TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, endpoint.c_str ())); bounce (sb, sc); - rc = zmq_close (sc); - assert (rc == 0); - - rc = zmq_close (sb); - assert (rc == 0); - - rc = zmq_ctx_term (ctx); - assert (rc == 0); - - return 0; + test_context_socket_close (sc); + test_context_socket_close (sb); +} + +int main (void) +{ + setup_test_environment (); + + UNITY_BEGIN (); + RUN_TEST (test_reqrep_vmci); + return UNITY_END (); }