The branch, master has been updated
via 307b5e74c506b609d5c407be0943f45255ab5122 (commit)
from 3d9c0861e86edcbfad10b84da332093fd6438f32 (commit)
- Log -----------------------------------------------------------------
commit 307b5e74c506b609d5c407be0943f45255ab5122
Author: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
Date: Thu Feb 4 16:22:04 2010 +0100
Migrate from cppunit to Boost.test
-----------------------------------------------------------------------
Summary of changes:
configure.in | 7 +-
examples/Makefile.am | 2 +-
libt2n.spec.in | 3 +-
test/Makefile.am | 6 +-
test/callback.cpp | 641 ++++++++++++++++-----------------
test/cmdgroup.cpp | 192 +++++------
test/comm.cpp | 577 ++++++++++++++---------------
test/hello.cpp | 664 ++++++++++++++++-----------------
test/newserver.cpp | 175 ++++-----
test/reconnect.cpp | 728 ++++++++++++++++++-------------------
test/reentrant.cpp | 161 ++++-----
test/serialize.cpp | 130 +++----
test/simplecmd.cpp | 339 ++++++++---------
test/test.cpp | 99 -----
test/test_fixtures.hxx | 57 +++
test/timeout.cpp | 959 ++++++++++++++++++++++++------------------------
test/wrapper.cpp | 462 +++++++++++-------------
17 files changed, 2470 insertions(+), 2732 deletions(-)
delete mode 100644 test/test.cpp
create mode 100644 test/test_fixtures.hxx
diff --git a/configure.in b/configure.in
index 4a06a93..faf76e4 100644
--- a/configure.in
+++ b/configure.in
@@ -15,21 +15,24 @@ AC_PATH_PROG(DOXYGEN, doxygen)
AM_CONDITIONAL(HAVE_DOXYGEN, test -n $DOXYGEN)
AM_CONDITIONAL(AUTOCHECK, test "$enable_autocheck" = yes)
-AM_PATH_CPPUNIT(1.8.0)
AX_BOOST_BASE([1.33])
AX_BOOST_SERIALIZATION
+AX_BOOST_UNIT_TEST_FRAMEWORK
if test "x$BOOST_SERIALIZATION_LIB" = "x"; then
echo "Sorry, we need the Serialization-Lib from Boost."
exit 1
fi
+if test "x$BOOST_UNIT_TEST_FRAMEWORK_LIB" = "x"; then
+ AC_MSG_ERROR([Sorry, we need the unit test framework from Boost.])
+fi
PKG_CHECK_MODULES(XMLPP, libxml++-2.6 >= 2.8.1)
AC_SUBST(XMLPP_CFLAGS)
AC_SUBST(XMLPP_LIBS)
dnl fake installed libt2n (codegen) for example-codegen
-dnl LIBT2N_CFLAGS="-I\$(top_srcdir)/src @BOOST_CPPFLAGS@ @CPPUNIT_CFLAGS@
-I\$(top_srcdir)/codegen"
+dnl LIBT2N_CFLAGS="-I\$(top_srcdir)/src @BOOST_CPPFLAGS@
-I\$(top_srcdir)/codegen"
dnl LIBT2N_LIBS="\$(top_builddir)/src/libt2n.la @BOOST_SERIALIZATION_LIB@
@BOOST_LDFLAGS@"
dnl LIBT2N_CODEGEN="\$(top_builddir)/codegen/libt2n-codegen"
dnl LIBT2N_CLIENT_PCTEMPLATE="\$(top_srcdir)/codegen/clientlib.pc.in"
diff --git a/examples/Makefile.am b/examples/Makefile.am
index c45351b..90c5ddf 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,4 +1,4 @@
-INCLUDES = -I$(top_srcdir)/src @BOOST_CPPFLAGS@ @CPPUNIT_CFLAGS@
+INCLUDES = -I$(top_srcdir)/src @BOOST_CPPFLAGS@
LDADD = $(top_builddir)/src/libt2n.la @BOOST_SERIALIZATION_LIB@ @BOOST_LDFLAGS@
diff --git a/libt2n.spec.in b/libt2n.spec.in
index 52fd1ab..f8333a9 100644
--- a/libt2n.spec.in
+++ b/libt2n.spec.in
@@ -8,7 +8,7 @@ Vendor: Intra2net AG
Source:
http://www.intra2net.com/en/developer/libt2n/download/%{name}-%{version}.tar.gz
Buildroot: /tmp/%{name}-%{version}-root
Prefix: /usr
-BuildPrereq: libtool cppunit-devel
+BuildPrereq: libtool
URL: http://www.intra2net.com/en/developer/libt2n
%description
@@ -31,6 +31,7 @@ autoreconf --force --install
./configure $RPM_BUILD_WITH_OPTIMIZE --prefix=%{prefix}
%__make %{?_smp_mflags}
+export BOOST_TEST_LOG_LEVEL=test_suite
make check
%install
diff --git a/test/Makefile.am b/test/Makefile.am
index 5aad119..0f6be49 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,10 +1,10 @@
-INCLUDES = -I$(top_srcdir)/src @BOOST_CPPFLAGS@ @CPPUNIT_CFLAGS@
+INCLUDES = -I$(top_srcdir)/src @BOOST_CPPFLAGS@
METASOURCES = AUTO
check_PROGRAMS = test
test_LDADD = $(top_builddir)/src/libt2n.la @BOOST_SERIALIZATION_LIB@ \
- @BOOST_LDFLAGS@ @CPPUNIT_LIBS@
+ @BOOST_LDFLAGS@ @BOOST_UNIT_TEST_FRAMEWORK_LIB@
test_SOURCES = newserver.cpp callback.cpp cmdgroup.cpp comm.cpp hello.cpp
reconnect.cpp \
- reentrant.cpp serialize.cpp simplecmd.cpp test.cpp timeout.cpp
wrapper.cpp
+ reentrant.cpp serialize.cpp simplecmd.cpp timeout.cpp wrapper.cpp
test_fixtures.hxx
TESTS = test
diff --git a/test/callback.cpp b/test/callback.cpp
index d3bdfa8..eb600cb 100644
--- a/test/callback.cpp
+++ b/test/callback.cpp
@@ -33,463 +33,448 @@ on this file might be covered by the GNU General Public
License.
#include <boost/bind.hpp>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <cppunit/ui/text/TestRunner.h>
-#include <cppunit/extensions/HelperMacros.h>
+#define BOOST_TEST_DYN_LINK
+#include <boost/test/unit_test.hpp>
#include <socket_client.hxx>
#include <socket_server.hxx>
+#include "test_fixtures.hxx"
+
using namespace std;
using namespace libt2n;
-using namespace CppUnit;
-class test_callback : public TestFixture
+class test_callbackFixture : public KillChildOnShutdownFixture
{
- CPPUNIT_TEST_SUITE(test_callback);
-
- CPPUNIT_TEST(ServerNewConnCallback);
- CPPUNIT_TEST(ServerConnClosedCallback);
- CPPUNIT_TEST(ServerConnDeletedCallback);
- CPPUNIT_TEST(ServerCallbackOrder);
- CPPUNIT_TEST(ClientConnClosedCallback);
- CPPUNIT_TEST(ClientConnDeletedCallback);
-
- CPPUNIT_TEST_SUITE_END();
-
+protected:
std::vector<bool> callback_done;
- pid_t child_pid;
+ void callback_func(callback_event_type ev, int conn_id)
+ {
+ // we don't care for the conn_id, we just mark the callback as done
+ if (callback_done[ev])
+ throw runtime_error("callback already done for this event");
- public:
+ callback_done[ev]=true;
+ }
- void setUp()
+public:
+ test_callbackFixture()
{
callback_done.resize(__events_end);
}
- void tearDown()
+ ~test_callbackFixture()
{
callback_done.clear();
-
- // make sure the server-child is dead before the next test runs
- kill(child_pid,SIGKILL);
- sleep(1);
}
+};
- void callback_func(callback_event_type ev, int conn_id)
- {
- // we don't care for the conn_id, we just mark the callback as done
- if (callback_done[ev])
- throw runtime_error("callback already done for this event");
-
- callback_done[ev]=true;
- }
+BOOST_FIXTURE_TEST_SUITE(test_callback, test_callbackFixture)
- void ServerNewConnCallback()
+BOOST_AUTO_TEST_CASE(ServerNewConnCallback)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- string data;
- // wait till server is up
- sleep(1);
+ string data;
+ // wait till server is up
+ sleep(1);
- {
- socket_client_connection sc("./socket");
+ {
+ socket_client_connection sc("./socket");
- sc.write("ABC");
+ sc.write("ABC");
- // wait half a sec
- sc.fill_buffer(500000);
- sc.get_packet(data);
+ // wait half a sec
+ sc.fill_buffer(500000);
+ sc.get_packet(data);
- // close the connection
- }
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
+ // close the connection
}
-
- // don't call atexit and stuff
- _exit(0);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- socket_server ss("./socket");
+ // don't call atexit and stuff
+ _exit(0);
+ }
-
ss.add_callback(new_connection,bind(&test_callback::callback_func,
boost::ref(*this), new_connection, _1));
+ default:
+ // parent
+ {
+ socket_server ss("./socket");
- // max 3 sec
- for (int i=0; i < 3; i++)
- {
- ss.fill_buffer(1000000);
+
ss.add_callback(new_connection,bind(&test_callback::ServerNewConnCallback::callback_func,
boost::ref(*this), new_connection, _1));
- string data;
- unsigned int cid;
- if(ss.get_packet(data,cid))
- {
- server_connection* con=ss.get_connection(cid);
- con->write("XYZ");
- }
+ // max 3 sec
+ for (int i=0; i < 3; i++)
+ {
+ ss.fill_buffer(1000000);
+
+ string data;
+ unsigned int cid;
+ if(ss.get_packet(data,cid))
+ {
+ server_connection* con=ss.get_connection(cid);
+ con->write("XYZ");
}
-
CPPUNIT_ASSERT_EQUAL(true,static_cast<bool>(callback_done[new_connection]));
-
CPPUNIT_ASSERT_EQUAL(false,static_cast<bool>(callback_done[connection_closed]));
-
CPPUNIT_ASSERT_EQUAL(false,static_cast<bool>(callback_done[connection_deleted]));
}
+
BOOST_CHECK_EQUAL(true,static_cast<bool>(callback_done[new_connection]));
+
BOOST_CHECK_EQUAL(false,static_cast<bool>(callback_done[connection_closed]));
+
BOOST_CHECK_EQUAL(false,static_cast<bool>(callback_done[connection_deleted]));
}
}
+}
- void ServerConnClosedCallback()
+BOOST_AUTO_TEST_CASE(ServerConnClosedCallback)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- string data;
- // wait till server is up
- sleep(1);
+ string data;
+ // wait till server is up
+ sleep(1);
- {
- socket_client_connection sc("./socket");
+ {
+ socket_client_connection sc("./socket");
- sc.write("ABC");
+ sc.write("ABC");
- // wait half a sec
- sc.fill_buffer(500000);
- sc.get_packet(data);
+ // wait half a sec
+ sc.fill_buffer(500000);
+ sc.get_packet(data);
- // close the connection
- }
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
+ // close the connection
}
-
- // don't call atexit and stuff
- _exit(0);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- socket_server ss("./socket");
+ // don't call atexit and stuff
+ _exit(0);
+ }
-
ss.add_callback(connection_closed,bind(&test_callback::callback_func,
boost::ref(*this), connection_closed, _1));
+ default:
+ // parent
+ {
+ socket_server ss("./socket");
- // max 3 sec
- for (int i=0; i < 3; i++)
- {
- ss.fill_buffer(1000000);
+
ss.add_callback(connection_closed,bind(&test_callback::ServerConnClosedCallback::callback_func,
boost::ref(*this), connection_closed, _1));
- string data;
- unsigned int cid;
- if(ss.get_packet(data,cid))
- {
- server_connection* con=ss.get_connection(cid);
- con->write("XYZ");
- }
+ // max 3 sec
+ for (int i=0; i < 3; i++)
+ {
+ ss.fill_buffer(1000000);
+
+ string data;
+ unsigned int cid;
+ if(ss.get_packet(data,cid))
+ {
+ server_connection* con=ss.get_connection(cid);
+ con->write("XYZ");
}
-
CPPUNIT_ASSERT_EQUAL(false,static_cast<bool>(callback_done[new_connection]));
-
CPPUNIT_ASSERT_EQUAL(true,static_cast<bool>(callback_done[connection_closed]));
-
CPPUNIT_ASSERT_EQUAL(false,static_cast<bool>(callback_done[connection_deleted]));
}
+
BOOST_CHECK_EQUAL(false,static_cast<bool>(callback_done[new_connection]));
+
BOOST_CHECK_EQUAL(true,static_cast<bool>(callback_done[connection_closed]));
+
BOOST_CHECK_EQUAL(false,static_cast<bool>(callback_done[connection_deleted]));
}
}
+}
- void ServerConnDeletedCallback()
+BOOST_AUTO_TEST_CASE(ServerConnDeletedCallback)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- string data;
- // wait till server is up
- sleep(1);
+ string data;
+ // wait till server is up
+ sleep(1);
- {
- socket_client_connection sc("./socket");
+ {
+ socket_client_connection sc("./socket");
- sc.write("ABC");
+ sc.write("ABC");
- // wait half a sec
- sc.fill_buffer(500000);
- sc.get_packet(data);
+ // wait half a sec
+ sc.fill_buffer(500000);
+ sc.get_packet(data);
- // close the connection
- }
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
+ // close the connection
}
-
- // don't call atexit and stuff
- _exit(0);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- socket_server ss("./socket");
+ // don't call atexit and stuff
+ _exit(0);
+ }
-
ss.add_callback(connection_deleted,bind(&test_callback::callback_func,
boost::ref(*this), connection_deleted, _1));
+ default:
+ // parent
+ {
+ socket_server ss("./socket");
- // max 3 sec
- for (int i=0; i < 3; i++)
- {
- ss.fill_buffer(1000000);
+
ss.add_callback(connection_deleted,bind(&test_callback::ServerConnDeletedCallback::callback_func,
boost::ref(*this), connection_deleted, _1));
- string data;
- unsigned int cid;
- if(ss.get_packet(data,cid))
- {
- server_connection* con=ss.get_connection(cid);
- con->write("XYZ");
- }
- ss.cleanup();
+ // max 3 sec
+ for (int i=0; i < 3; i++)
+ {
+ ss.fill_buffer(1000000);
+
+ string data;
+ unsigned int cid;
+ if(ss.get_packet(data,cid))
+ {
+ server_connection* con=ss.get_connection(cid);
+ con->write("XYZ");
}
ss.cleanup();
-
-
CPPUNIT_ASSERT_EQUAL(false,static_cast<bool>(callback_done[new_connection]));
-
CPPUNIT_ASSERT_EQUAL(false,static_cast<bool>(callback_done[connection_closed]));
-
CPPUNIT_ASSERT_EQUAL(true,static_cast<bool>(callback_done[connection_deleted]));
}
+ ss.cleanup();
+
+
BOOST_CHECK_EQUAL(false,static_cast<bool>(callback_done[new_connection]));
+
BOOST_CHECK_EQUAL(false,static_cast<bool>(callback_done[connection_closed]));
+
BOOST_CHECK_EQUAL(true,static_cast<bool>(callback_done[connection_deleted]));
}
}
+}
- void ServerCallbackOrder()
+BOOST_AUTO_TEST_CASE(ServerCallbackOrder)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- string data;
- // wait till server is up
- sleep(1);
+ string data;
+ // wait till server is up
+ sleep(1);
- {
- socket_client_connection sc("./socket");
+ {
+ socket_client_connection sc("./socket");
- sc.write("1");
+ sc.write("1");
- // wait half a sec
- sc.fill_buffer(500000);
- sc.get_packet(data);
+ // wait half a sec
+ sc.fill_buffer(500000);
+ sc.get_packet(data);
- sc.write("2");
+ sc.write("2");
- // close the connection
- }
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
+ // close the connection
}
-
- // don't call atexit and stuff
- _exit(0);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- socket_server ss("./socket");
+ // don't call atexit and stuff
+ _exit(0);
+ }
-
ss.add_callback(connection_closed,bind(&test_callback::callback_func,
boost::ref(*this), connection_closed, _1));
-
ss.add_callback(connection_deleted,bind(&test_callback::callback_func,
boost::ref(*this), connection_deleted, _1));
+ default:
+ // parent
+ {
+ socket_server ss("./socket");
- bool got_1=false;
+
ss.add_callback(connection_closed,bind(&test_callback::ServerCallbackOrder::callback_func,
boost::ref(*this), connection_closed, _1));
+
ss.add_callback(connection_deleted,bind(&test_callback::ServerCallbackOrder::callback_func,
boost::ref(*this), connection_deleted, _1));
- for (int i=0; i < 5; i++)
- {
- ss.fill_buffer(500000);
+ bool got_1=false;
- string data;
- unsigned int cid;
- if(!got_1 && ss.get_packet(data,cid))
- {
- server_connection* con=ss.get_connection(cid);
- con->write("XYZ");
- got_1=true;
- // don't call get_packet anymore
- }
- ss.cleanup();
+ for (int i=0; i < 5; i++)
+ {
+ ss.fill_buffer(500000);
+
+ string data;
+ unsigned int cid;
+ if(!got_1 && ss.get_packet(data,cid))
+ {
+ server_connection* con=ss.get_connection(cid);
+ con->write("XYZ");
+ got_1=true;
+ // don't call get_packet anymore
}
ss.cleanup();
+ }
+ ss.cleanup();
- CPPUNIT_ASSERT_EQUAL_MESSAGE("closed
done",true,static_cast<bool>(callback_done[connection_closed]));
- CPPUNIT_ASSERT_EQUAL_MESSAGE("not deleted
yet",false,static_cast<bool>(callback_done[connection_deleted]));
+
BOOST_CHECK_MESSAGE(static_cast<bool>(callback_done[connection_closed]) ==
true, "closed done");
+
BOOST_CHECK_MESSAGE(static_cast<bool>(callback_done[connection_deleted]) ==
false, "not deleted yet");
- for (int i=0; i < 4; i++)
- {
- ss.fill_buffer(500000);
+ for (int i=0; i < 4; i++)
+ {
+ ss.fill_buffer(500000);
- string data;
- unsigned int cid;
- ss.get_packet(data,cid);
- ss.cleanup();
- }
+ string data;
+ unsigned int cid;
+ ss.get_packet(data,cid);
ss.cleanup();
-
- CPPUNIT_ASSERT_EQUAL_MESSAGE("closed done
(2)",true,static_cast<bool>(callback_done[connection_closed]));
- CPPUNIT_ASSERT_EQUAL_MESSAGE("deleted
done",true,static_cast<bool>(callback_done[connection_deleted]));
}
+ ss.cleanup();
+
+
BOOST_CHECK_MESSAGE(static_cast<bool>(callback_done[connection_closed]) ==
true, "closed done (2)");
+
BOOST_CHECK_MESSAGE(static_cast<bool>(callback_done[connection_deleted]) ==
true, "not deleted yet(2)");
}
}
+}
- void ClientConnClosedCallback()
+BOOST_AUTO_TEST_CASE(ClientConnClosedCallback)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- socket_server ss("./socket");
-
- // max 3 sec
- for (int i=0; i < 3; i++)
- {
- ss.fill_buffer(1000000);
-
- string data;
- unsigned int cid;
- if(ss.get_packet(data,cid))
- break;
- }
- } catch(...)
+ socket_server ss("./socket");
+
+ // max 3 sec
+ for (int i=0; i < 3; i++)
{
- std::cerr << "exception in child. ignoring\n";
- }
+ ss.fill_buffer(1000000);
- // don't call atexit and stuff
- _exit(0);
+ string data;
+ unsigned int cid;
+ if(ss.get_packet(data,cid))
+ break;
+ }
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
- // wait till server is up
- sleep(1);
+ // don't call atexit and stuff
+ _exit(0);
+ }
- socket_client_connection sc("./socket");
+ default:
+ // parent
+ {
+ string data;
+ // wait till server is up
+ sleep(1);
-
sc.add_callback(connection_closed,bind(&test_callback::callback_func,
boost::ref(*this), connection_closed, 0));
+ socket_client_connection sc("./socket");
- sc.write("ABC");
+
sc.add_callback(connection_closed,bind(&test_callback::ClientConnClosedCallback::callback_func,
boost::ref(*this), connection_closed, 0));
- // wait half a sec
- sc.fill_buffer(500000);
- sc.get_packet(data);
+ sc.write("ABC");
-
CPPUNIT_ASSERT_EQUAL(false,static_cast<bool>(callback_done[new_connection]));
-
CPPUNIT_ASSERT_EQUAL(true,static_cast<bool>(callback_done[connection_closed]));
-
CPPUNIT_ASSERT_EQUAL(false,static_cast<bool>(callback_done[connection_deleted]));
- }
+ // wait half a sec
+ sc.fill_buffer(500000);
+ sc.get_packet(data);
+
+
BOOST_CHECK_EQUAL(false,static_cast<bool>(callback_done[new_connection]));
+
BOOST_CHECK_EQUAL(true,static_cast<bool>(callback_done[connection_closed]));
+
BOOST_CHECK_EQUAL(false,static_cast<bool>(callback_done[connection_deleted]));
}
}
+}
- void ClientConnDeletedCallback()
+BOOST_AUTO_TEST_CASE(ClientConnDeletedCallback)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- socket_server ss("./socket");
-
- // max 3 sec
- for (int i=0; i < 3; i++)
- {
- ss.fill_buffer(1000000);
-
- string data;
- unsigned int cid;
- if(ss.get_packet(data,cid))
- break;
- }
- } catch(...)
+ socket_server ss("./socket");
+
+ // max 3 sec
+ for (int i=0; i < 3; i++)
{
- std::cerr << "exception in child. ignoring\n";
- }
+ ss.fill_buffer(1000000);
- // don't call atexit and stuff
- _exit(0);
+ string data;
+ unsigned int cid;
+ if(ss.get_packet(data,cid))
+ break;
+ }
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
- // wait till server is up
- sleep(1);
+ // don't call atexit and stuff
+ _exit(0);
+ }
- {
- socket_client_connection sc("./socket");
+ default:
+ // parent
+ {
+ string data;
+ // wait till server is up
+ sleep(1);
-
sc.add_callback(connection_deleted,bind(&test_callback::callback_func,
boost::ref(*this), connection_deleted, 0));
+ {
+ socket_client_connection sc("./socket");
- sc.write("ABC");
+
sc.add_callback(connection_deleted,bind(&test_callback::ClientConnDeletedCallback::callback_func,
boost::ref(*this), connection_deleted, 0));
- // wait half a sec
- sc.fill_buffer(500000);
- sc.get_packet(data);
- }
+ sc.write("ABC");
-
CPPUNIT_ASSERT_EQUAL(false,static_cast<bool>(callback_done[new_connection]));
-
CPPUNIT_ASSERT_EQUAL(false,static_cast<bool>(callback_done[connection_closed]));
-
CPPUNIT_ASSERT_EQUAL(true,static_cast<bool>(callback_done[connection_deleted]));
+ // wait half a sec
+ sc.fill_buffer(500000);
+ sc.get_packet(data);
}
+
+
BOOST_CHECK_EQUAL(false,static_cast<bool>(callback_done[new_connection]));
+
BOOST_CHECK_EQUAL(false,static_cast<bool>(callback_done[connection_closed]));
+
BOOST_CHECK_EQUAL(true,static_cast<bool>(callback_done[connection_deleted]));
}
}
-};
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_callback);
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/cmdgroup.cpp b/test/cmdgroup.cpp
index 6b092ec..1c30cc3 100644
--- a/test/cmdgroup.cpp
+++ b/test/cmdgroup.cpp
@@ -30,9 +30,8 @@ on this file might be covered by the GNU General Public
License.
#include <sstream>
#include <stdexcept>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <cppunit/ui/text/TestRunner.h>
-#include <cppunit/extensions/HelperMacros.h>
+#define BOOST_TEST_DYN_LINK
+#include <boost/test/unit_test.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
@@ -47,8 +46,9 @@ on this file might be covered by the GNU General Public
License.
#include <command_client.hxx>
#include <command_server.hxx>
+#include "test_fixtures.hxx"
+
using namespace std;
-using namespace CppUnit;
using namespace libt2n;
string testfunc4(const string& str)
@@ -173,134 +173,112 @@ BOOST_CLASS_EXPORT(cmd_group_b)
BOOST_CLASS_EXPORT(testfunc4a_cmd)
BOOST_CLASS_EXPORT(testfunc4b_cmd)
-class test_cmdgroup : public TestFixture
-{
- CPPUNIT_TEST_SUITE(test_cmdgroup);
-
- CPPUNIT_TEST(GroupOk);
- CPPUNIT_TEST(WrongGroup);
-
- CPPUNIT_TEST_SUITE_END();
-
- pid_t child_pid;
- public:
-
- void setUp()
- { }
-
- void tearDown()
- {
- // make sure the server-child is dead before the next test runs
- kill(child_pid,SIGKILL);
- sleep(1);
- }
+BOOST_FIXTURE_TEST_SUITE(test_cmdgroup, KillChildOnShutdownFixture)
- void GroupOk()
+BOOST_AUTO_TEST_CASE(GroupOk)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ socket_server ss("./socket");
+ group_command_server<cmd_group_a> cs(ss);
+
+ // max 10 sec
+ for (int i=0; i < 10; i++)
+ cs.handle(1000000);
+ } catch(...)
{
- try
- {
- socket_server ss("./socket");
- group_command_server<cmd_group_a> cs(ss);
-
- // max 10 sec
- for (int i=0; i < 10; i++)
- cs.handle(1000000);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
- command_client cc(&sc);
+ // don't call atexit and stuff
+ _exit(0);
+ }
+
+ default:
+ // parent
+ {
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
+ command_client cc(&sc);
- result_container rc;
- cc.send_command(new testfunc4a_cmd("hello"),rc);
+ result_container rc;
+ cc.send_command(new testfunc4a_cmd("hello"),rc);
- string
ret=dynamic_cast<testfunc4_res*>(rc.get_result())->get_data();
+ string
ret=dynamic_cast<testfunc4_res*>(rc.get_result())->get_data();
- CPPUNIT_ASSERT_EQUAL(string("hello, testfunc() was here"),ret);
- }
+ BOOST_CHECK_EQUAL(string("hello, testfunc() was here"),ret);
}
}
+}
- void WrongGroup()
+BOOST_AUTO_TEST_CASE(WrongGroup)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- socket_server ss("./socket");
- group_command_server<cmd_group_b> cs(ss);
-
- // max 10 sec
- for (int i=0; i < 10; i++)
- cs.handle(1000000);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
- }
+ socket_server ss("./socket");
+ group_command_server<cmd_group_b> cs(ss);
- default:
- // parent
+ // max 10 sec
+ for (int i=0; i < 10; i++)
+ cs.handle(1000000);
+ } catch(...)
{
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
- command_client cc(&sc);
+ std::cerr << "exception in child. ignoring\n";
+ }
- result_container rc;
- cc.send_command(new testfunc4a_cmd("hello"),rc);
+ // don't call atexit and stuff
+ _exit(0);
+ }
- string ret;
+ default:
+ // parent
+ {
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
+ command_client cc(&sc);
- try
- {
-
ret=dynamic_cast<testfunc4_res*>(rc.get_result())->get_data();
- }
- catch(t2n_command_error &e)
- { ret=e.what(); }
- catch(...)
- { throw; }
+ result_container rc;
+ cc.send_command(new testfunc4a_cmd("hello"),rc);
- string expected_what="illegal command of type ";
+ string ret;
-
CPPUNIT_ASSERT_EQUAL(expected_what,ret.substr(0,expected_what.size()));
+ try
+ {
+ ret=dynamic_cast<testfunc4_res*>(rc.get_result())->get_data();
}
+ catch(t2n_command_error &e)
+ { ret=e.what(); }
+ catch(...)
+ { throw; }
+
+ string expected_what="illegal command of type ";
+
+
BOOST_CHECK_EQUAL(expected_what,ret.substr(0,expected_what.size()));
}
}
+}
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(test_cmdgroup);
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/comm.cpp b/test/comm.cpp
index f9c58e3..7b301a6 100644
--- a/test/comm.cpp
+++ b/test/comm.cpp
@@ -31,78 +31,84 @@ on this file might be covered by the GNU General Public
License.
#include <sstream>
#include <stdexcept>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <cppunit/ui/text/TestRunner.h>
-#include <cppunit/extensions/HelperMacros.h>
+#define BOOST_TEST_DYN_LINK
+#include <boost/test/unit_test.hpp>
#include <socket_client.hxx>
#include <socket_server.hxx>
+#include "test_fixtures.hxx"
+
using namespace std;
using namespace libt2n;
-using namespace CppUnit;
+BOOST_FIXTURE_TEST_SUITE(test_comm, KillChildOnShutdownFixture)
-class test_comm : public TestFixture
+BOOST_AUTO_TEST_CASE(UnixCommToServer)
{
- CPPUNIT_TEST_SUITE(test_comm);
+ string data;
- CPPUNIT_TEST(UnixCommToServer);
- CPPUNIT_TEST(UnixCommToServerAndBack);
- CPPUNIT_TEST(UnixCommToServerAndBackBig);
- CPPUNIT_TEST(IPCommToServer);
- CPPUNIT_TEST(IPCommToServerAndBack);
- CPPUNIT_TEST(IPCommToServerAndBackBig);
+ switch(child_pid=fork())
+ {
+ case -1:
+ {
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
+ {
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
+ sc.write("hello");
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
+ }
- CPPUNIT_TEST_SUITE_END();
+ // don't call atexit and stuff
+ _exit(0);
+ }
- pid_t child_pid;
+ default:
+ // parent
+ {
+ socket_server ss("./socket");
- public:
+ time_t t0 = time(NULL);
- void setUp()
- { }
+ // max 10 sec
+ while (time(NULL) < t0 + 10 )
+ {
+ ss.fill_buffer(1000000);
- void tearDown()
- {
- // make sure the server-child is dead before the next test runs
- kill(child_pid,SIGKILL);
- sleep(1);
+ if(ss.get_packet(data))
+ break;
+ }
+ }
}
+ BOOST_CHECK_EQUAL(string("hello"),data);
+}
- void UnixCommToServer()
+BOOST_AUTO_TEST_CASE(UnixCommToServerAndBack)
+{
+ switch(child_pid=fork())
{
- string data;
-
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
- {
- try
- {
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
- sc.write("hello");
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
- }
-
- default:
- // parent
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
socket_server ss("./socket");
+ ss.set_logging(&cerr,debug);
time_t t0 = time(NULL);
@@ -111,352 +117,319 @@ class test_comm : public TestFixture
{
ss.fill_buffer(1000000);
- if(ss.get_packet(data))
- break;
- }
- }
- }
- CPPUNIT_ASSERT_EQUAL(string("hello"),data);
- }
+ string data;
+ unsigned int cid;
- void UnixCommToServerAndBack()
- {
- switch(child_pid=fork())
- {
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
- {
- try
- {
- socket_server ss("./socket");
- ss.set_logging(&cerr,debug);
-
- time_t t0 = time(NULL);
-
- // max 10 sec
- while (time(NULL) < t0 + 10 )
+ if(ss.get_packet(data,cid))
{
- ss.fill_buffer(1000000);
-
- string data;
- unsigned int cid;
+ server_connection* con=ss.get_connection(cid);
- if(ss.get_packet(data,cid))
- {
- server_connection* con=ss.get_connection(cid);
+ if (data=="QUIT")
+ break;
- if (data=="QUIT")
- break;
-
- if (data=="ABC")
- con->write("DEF");
- else
- con->write("xyz");
- }
+ if (data=="ABC")
+ con->write("DEF");
+ else
+ con->write("xyz");
}
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
}
-
- // don't call atexit and stuff
- _exit(0);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ default:
+ // parent
+ {
+ string data;
- sc.write("ABC");
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- sc.fill_buffer(1000000);
- sc.get_packet(data);
+ sc.write("ABC");
- CPPUNIT_ASSERT_EQUAL(string("DEF"),data);
+ sc.fill_buffer(1000000);
+ sc.get_packet(data);
- sc.write("HAHA");
+ BOOST_CHECK_EQUAL(string("DEF"),data);
- sc.fill_buffer(1000000);
- sc.get_packet(data);
+ sc.write("HAHA");
- CPPUNIT_ASSERT_EQUAL(string("xyz"),data);
+ sc.fill_buffer(1000000);
+ sc.get_packet(data);
- sc.write("QUIT");
- }
+ BOOST_CHECK_EQUAL(string("xyz"),data);
+
+ sc.write("QUIT");
}
}
+}
- void UnixCommToServerAndBackBig()
+BOOST_AUTO_TEST_CASE(UnixCommToServerAndBackBig)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- socket_server ss("./socket");
- ss.set_logging(&cerr,debug);
+ socket_server ss("./socket");
+ ss.set_logging(&cerr,debug);
- time_t t0 = time(NULL);
+ time_t t0 = time(NULL);
- // max 10 sec
- while (time(NULL) < t0 + 10 )
- {
- ss.fill_buffer(1000000);
+ // max 10 sec
+ while (time(NULL) < t0 + 10 )
+ {
+ ss.fill_buffer(1000000);
- string data;
- unsigned int cid;
+ string data;
+ unsigned int cid;
- if(ss.get_packet(data,cid))
- {
- server_connection* con=ss.get_connection(cid);
+ if(ss.get_packet(data,cid))
+ {
+ server_connection* con=ss.get_connection(cid);
- if (data=="QUIT")
- break;
+ if (data=="QUIT")
+ break;
- con->write(string().insert(0,100*1024,'y'));
- }
+ con->write(string().insert(0,100*1024,'y'));
}
- std::cerr << "child: OVER" << std::endl;
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
}
-
- // don't call atexit and stuff
- _exit(0);
+ std::cerr << "child: OVER" << std::endl;
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ default:
+ // parent
+ {
+ string data;
- sc.write(string().insert(0,100*1024,'x'));
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- while (!sc.get_packet(data))
- sc.fill_buffer(1000000);
+ sc.write(string().insert(0,100*1024,'x'));
- CPPUNIT_ASSERT_EQUAL(string().insert(0,100*1024,'y'),data);
+ while (!sc.get_packet(data))
+ sc.fill_buffer(1000000);
- sc.write("QUIT");
- }
+ BOOST_CHECK_EQUAL(string().insert(0,100*1024,'y'),data);
+
+ sc.write("QUIT");
}
}
+}
- void IPCommToServer()
- {
- string data;
+BOOST_AUTO_TEST_CASE(IPCommToServer)
+{
+ string data;
- switch(child_pid=fork())
+ switch(child_pid=fork())
+ {
+ case -1:
{
- case -1:
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc(6666);
+ sc.write("hello");
+ } catch(...)
{
- try
- {
- // wait till server is up
- sleep(1);
- socket_client_connection sc(6666);
- sc.write("hello");
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- socket_server ss(6666);
+ // don't call atexit and stuff
+ _exit(0);
+ }
- time_t t0 = time(NULL);
+ default:
+ // parent
+ {
+ socket_server ss(6666);
- // max 10 sec
- while (time(NULL) < t0 + 10 )
- {
- ss.fill_buffer(1000000);
+ time_t t0 = time(NULL);
- if(ss.get_packet(data))
- break;
- }
+ // max 10 sec
+ while (time(NULL) < t0 + 10 )
+ {
+ ss.fill_buffer(1000000);
+
+ if(ss.get_packet(data))
+ break;
}
}
- CPPUNIT_ASSERT_EQUAL(string("hello"),data);
}
+ BOOST_CHECK_EQUAL(string("hello"),data);
+}
- void IPCommToServerAndBack()
+BOOST_AUTO_TEST_CASE(IPCommToServerAndBack)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- socket_server ss(6666);
- ss.set_logging(&cerr,debug);
+ socket_server ss(6666);
+ ss.set_logging(&cerr,debug);
- time_t t0 = time(NULL);
+ time_t t0 = time(NULL);
- // max 10 sec
- while (time(NULL) < t0 + 10 )
- {
- ss.fill_buffer(1000000);
+ // max 10 sec
+ while (time(NULL) < t0 + 10 )
+ {
+ ss.fill_buffer(1000000);
- string data;
- unsigned int cid;
+ string data;
+ unsigned int cid;
- if(ss.get_packet(data,cid))
- {
- server_connection* con=ss.get_connection(cid);
+ if(ss.get_packet(data,cid))
+ {
+ server_connection* con=ss.get_connection(cid);
- if (data=="QUIT")
- break;
+ if (data=="QUIT")
+ break;
- if (data=="ABC")
- con->write("DEF");
- else
- con->write("xyz");
- }
+ if (data=="ABC")
+ con->write("DEF");
+ else
+ con->write("xyz");
}
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
}
- // don't call atexit and stuff
- _exit(0);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
+ // don't call atexit and stuff
+ _exit(0);
+ }
- default:
- // parent
- {
- string data;
+ default:
+ // parent
+ {
+ string data;
- // wait till server is up
- sleep(1);
- socket_client_connection sc(6666);
- sc.write("ABC");
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc(6666);
+ sc.write("ABC");
- sc.fill_buffer(1000000);
- sc.get_packet(data);
+ sc.fill_buffer(1000000);
+ sc.get_packet(data);
- CPPUNIT_ASSERT_EQUAL(string("DEF"),data);
+ BOOST_CHECK_EQUAL(string("DEF"),data);
- sc.write("HAHA");
+ sc.write("HAHA");
- sc.fill_buffer(1000000);
- sc.get_packet(data);
+ sc.fill_buffer(1000000);
+ sc.get_packet(data);
- CPPUNIT_ASSERT_EQUAL(string("xyz"),data);
+ BOOST_CHECK_EQUAL(string("xyz"),data);
- sc.write("QUIT");
- }
+ sc.write("QUIT");
}
}
+}
- void IPCommToServerAndBackBig()
+BOOST_AUTO_TEST_CASE(IPCommToServerAndBackBig)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- socket_server ss(6666);
- ss.set_logging(&cerr,debug);
+ socket_server ss(6666);
+ ss.set_logging(&cerr,debug);
- time_t t0 = time(NULL);
+ time_t t0 = time(NULL);
- // max 10 sec
- while (time(NULL) < t0 + 10 )
- {
- ss.fill_buffer(1000000);
+ // max 10 sec
+ while (time(NULL) < t0 + 10 )
+ {
+ ss.fill_buffer(1000000);
- string data;
- unsigned int cid;
+ string data;
+ unsigned int cid;
- if(ss.get_packet(data,cid))
- {
- server_connection* con=ss.get_connection(cid);
+ if(ss.get_packet(data,cid))
+ {
+ server_connection* con=ss.get_connection(cid);
- socket_handler* alias= dynamic_cast<
socket_handler* >(con);
+ socket_handler* alias= dynamic_cast< socket_handler*
>(con);
- if (data=="QUIT")
- break;
+ if (data=="QUIT")
+ break;
- alias->set_write_block_size( 4093 );
- con->write(string().insert(0,2048*1024,'y'));
- }
+ alias->set_write_block_size( 4093 );
+ con->write(string().insert(0,2048*1024,'y'));
}
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
}
- // don't call atexit and stuff
- _exit(0);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
+ // don't call atexit and stuff
+ _exit(0);
+ }
- default:
- // parent
- {
- string data;
+ default:
+ // parent
+ {
+ string data;
- // wait till server is up
- sleep(1);
- socket_client_connection sc(6666);
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc(6666);
- sc.write(string().insert(0,100*1024,'x'));
+ sc.write(string().insert(0,100*1024,'x'));
- while (!sc.get_packet(data))
- sc.fill_buffer(1000000);
+ while (!sc.get_packet(data))
+ sc.fill_buffer(1000000);
- CPPUNIT_ASSERT_EQUAL(string().insert(0,2048*1024,'y'),data);
+ BOOST_CHECK_EQUAL(string().insert(0,2048*1024,'y'),data);
- sc.write("QUIT");
- }
+ sc.write("QUIT");
}
- } // eo IPCommToServerAndBackBig()
-};
+ }
+} // eo IPCommToServerAndBackBig()
-CPPUNIT_TEST_SUITE_REGISTRATION(test_comm);
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/hello.cpp b/test/hello.cpp
index 2f804fd..d53a312 100644
--- a/test/hello.cpp
+++ b/test/hello.cpp
@@ -32,22 +32,22 @@ on this file might be covered by the GNU General Public
License.
#include <boost/bind.hpp>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <cppunit/ui/text/TestRunner.h>
-#include <cppunit/extensions/HelperMacros.h>
+#define BOOST_TEST_DYN_LINK
+#include <boost/test/unit_test.hpp>
#include <t2n_exception.hxx>
#include <socket_client.hxx>
#include <socket_server.hxx>
#include <command_client.hxx>
+#include "test_fixtures.hxx"
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
using namespace std;
using namespace libt2n;
-using namespace CppUnit;
// this is an evil hack to get access to real_write, don't ever do this in an
app!!!
class real_write_connection: public socket_server_connection
@@ -57,34 +57,9 @@ class real_write_connection: public socket_server_connection
{ socket_write(data); }
};
-class test_hello : public TestFixture
+class test_helloFixture : public KillChildOnShutdownFixture
{
- CPPUNIT_TEST_SUITE(test_hello);
-
- CPPUNIT_TEST(HelloOk);
- CPPUNIT_TEST(BadTag);
- CPPUNIT_TEST(BadVersion);
- CPPUNIT_TEST(SeparatorMissing);
- CPPUNIT_TEST(WrongByteOrder);
- CPPUNIT_TEST(OtherServerBig);
- CPPUNIT_TEST(OtherServerSmall);
-
- CPPUNIT_TEST_SUITE_END();
-
- pid_t child_pid;
-
- public:
-
- void setUp()
- { }
-
- void tearDown()
- {
- // make sure the server-child is dead before the next test runs
- kill(child_pid,SIGKILL);
- sleep(1);
- }
-
+protected:
void send_hello(string hello_string, socket_server* ss, int conn_id)
{
server_connection *sc=ss->get_connection(conn_id);
@@ -100,406 +75,419 @@ class test_hello : public TestFixture
rwc->real_write(hello_string);
}
- void HelloOk()
+public:
+ test_helloFixture()
+ {
+ }
+
+ ~test_helloFixture()
{
- switch(child_pid=fork())
+ }
+};
+
+BOOST_FIXTURE_TEST_SUITE(test_hello, test_helloFixture)
+
+BOOST_AUTO_TEST_CASE(HelloOk)
+{
+ switch(child_pid=fork())
+ {
+ case -1:
{
- case -1:
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ socket_server ss("./socket");
+
+ ostringstream hello;
+ hello << "T2Nv" << PROTOCOL_VERSION << ';';
+ int byteordercheck=1;
+ hello.write((char*)&byteordercheck,sizeof(byteordercheck));
+ hello << ';';
+
+
ss.add_callback(new_connection,bind(&test_hello::HelloOk::send_hello,
boost::ref(*this), hello.str(),&ss, _1));
+
+ // max 10 sec
+ for (int i=0; i < 10; i++)
+ ss.fill_buffer(1000000);
+ } catch(...)
{
- try
- {
- socket_server ss("./socket");
-
- ostringstream hello;
- hello << "T2Nv" << PROTOCOL_VERSION << ';';
- int byteordercheck=1;
- hello.write((char*)&byteordercheck,sizeof(byteordercheck));
- hello << ';';
-
-
ss.add_callback(new_connection,bind(&test_hello::send_hello, boost::ref(*this),
hello.str(),&ss, _1));
-
- // max 10 sec
- for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
- command_client cc(&sc);
- }
+ default:
+ // parent
+ {
+ string data;
+
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
+ command_client cc(&sc);
+
+ // All fine we reached this point
+ BOOST_CHECK(true);
}
}
+}
- void BadTag()
+BOOST_AUTO_TEST_CASE(BadTag)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- socket_server ss("./socket");
-
- ostringstream hello;
- hello << "XYZ 123";
+ socket_server ss("./socket");
-
ss.add_callback(new_connection,bind(&test_hello::send_hello, boost::ref(*this),
hello.str(),&ss, _1));
+ ostringstream hello;
+ hello << "XYZ 123";
- // max 10 sec
- for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
+
ss.add_callback(new_connection,bind(&test_hello::BadTag::send_hello,
boost::ref(*this), hello.str(),&ss, _1));
- // don't call atexit and stuff
- _exit(0);
+ // max 10 sec
+ for (int i=0; i < 10; i++)
+ ss.fill_buffer(1000000);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ default:
+ // parent
+ {
+ string data;
- command_client cc(&sc);
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- t2n_exception* ep=cc.get_constuctor_exception();
+ command_client cc(&sc);
- string errormsg;
- if (ep)
- errormsg=ep->what();
+ t2n_exception* ep=cc.get_constuctor_exception();
- CPPUNIT_ASSERT_EQUAL(string("illegal hello received
(T2N)"),errormsg);
- }
+ string errormsg;
+ if (ep)
+ errormsg=ep->what();
+
+ BOOST_CHECK_EQUAL(string("illegal hello received (T2N)"),errormsg);
}
}
+}
- void BadVersion()
+BOOST_AUTO_TEST_CASE(BadVersion)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ socket_server ss("./socket");
+
+ ostringstream hello;
+ // lets hope we don't ever get near such a version number...
+ hello << "T2Nv" << 4982271 << ';';
+ int byteordercheck=1;
+ hello.write((char*)&byteordercheck,sizeof(byteordercheck));
+ hello << ';';
+
+
ss.add_callback(new_connection,bind(&test_hello::BadVersion::send_hello,
boost::ref(*this), hello.str(),&ss, _1));
+
+ // max 10 sec
+ for (int i=0; i < 10; i++)
+ ss.fill_buffer(1000000);
+ } catch(...)
{
- try
- {
- socket_server ss("./socket");
-
- ostringstream hello;
- // lets hope we don't ever get near such a version
number...
- hello << "T2Nv" << 4982271 << ';';
- int byteordercheck=1;
- hello.write((char*)&byteordercheck,sizeof(byteordercheck));
- hello << ';';
-
-
ss.add_callback(new_connection,bind(&test_hello::send_hello, boost::ref(*this),
hello.str(),&ss, _1));
-
- // max 10 sec
- for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
+ // don't call atexit and stuff
+ _exit(0);
+ }
+
+ default:
+ // parent
+ {
+ string data;
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- command_client cc(&sc);
+ command_client cc(&sc);
- t2n_exception* ep=cc.get_constuctor_exception();
+ t2n_exception* ep=cc.get_constuctor_exception();
- string errormsg;
- if (ep)
- errormsg=ep->what();
+ string errormsg;
+ if (ep)
+ errormsg=ep->what();
- CPPUNIT_ASSERT_EQUAL(string("not compatible with the server
protocol version"),errormsg);
- }
+ BOOST_CHECK_EQUAL(string("not compatible with the server protocol
version"),errormsg);
}
}
+}
- void SeparatorMissing()
+BOOST_AUTO_TEST_CASE(SeparatorMissing)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ socket_server ss("./socket");
+
+ ostringstream hello;
+ hello << "T2Nv" << PROTOCOL_VERSION;
+ int byteordercheck=1;
+ hello.write((char*)&byteordercheck,sizeof(byteordercheck));
+ hello << ';';
+
+
ss.add_callback(new_connection,bind(&test_hello::SeparatorMissing::send_hello,
boost::ref(*this), hello.str(),&ss, _1));
+
+ // max 10 sec
+ for (int i=0; i < 10; i++)
+ ss.fill_buffer(1000000);
+ } catch(...)
{
- try
- {
- socket_server ss("./socket");
-
- ostringstream hello;
- hello << "T2Nv" << PROTOCOL_VERSION;
- int byteordercheck=1;
- hello.write((char*)&byteordercheck,sizeof(byteordercheck));
- hello << ';';
-
-
ss.add_callback(new_connection,bind(&test_hello::send_hello, boost::ref(*this),
hello.str(),&ss, _1));
-
- // max 10 sec
- for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ default:
+ // parent
+ {
+ string data;
- command_client cc(&sc);
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- t2n_exception* ep=cc.get_constuctor_exception();
+ command_client cc(&sc);
- string errormsg;
- if (ep)
- errormsg=ep->what();
+ t2n_exception* ep=cc.get_constuctor_exception();
- CPPUNIT_ASSERT_EQUAL(string("illegal hello received (1.
;)"),errormsg);
- }
+ string errormsg;
+ if (ep)
+ errormsg=ep->what();
+
+ BOOST_CHECK_EQUAL(string("illegal hello received (1.
;)"),errormsg);
}
}
+}
- void WrongByteOrder()
+BOOST_AUTO_TEST_CASE(WrongByteOrder)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
+ {
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
{
- case -1:
+ try
{
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ socket_server ss("./socket");
+
+ ostringstream hello;
+ hello << "T2Nv" << PROTOCOL_VERSION << ';';
+ int byteordercheck=1;
+ int dst;
+ char* si=(char*)&byteordercheck;
+ char* di=(char*)&dst;
+
+ di[0]=si[3];
+ di[1]=si[2];
+ di[2]=si[1];
+ di[3]=si[0];
+
+ hello.write((char*)&dst,sizeof(dst));
+ hello << ';';
+
+
ss.add_callback(new_connection,bind(&test_hello::WrongByteOrder::send_hello,
boost::ref(*this), hello.str(),&ss, _1));
+
+ // max 10 sec
+ for (int i=0; i < 10; i++)
+ ss.fill_buffer(1000000);
+ } catch(...)
{
- try
- {
- socket_server ss("./socket");
-
- ostringstream hello;
- hello << "T2Nv" << PROTOCOL_VERSION << ';';
- int byteordercheck=1;
- int dst;
- char* si=(char*)&byteordercheck;
- char* di=(char*)&dst;
-
- di[0]=si[3];
- di[1]=si[2];
- di[2]=si[1];
- di[3]=si[0];
-
- hello.write((char*)&dst,sizeof(dst));
- hello << ';';
-
-
ss.add_callback(new_connection,bind(&test_hello::send_hello, boost::ref(*this),
hello.str(),&ss, _1));
-
- // max 10 sec
- for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ default:
+ // parent
+ {
+ string data;
- command_client cc(&sc);
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- t2n_exception* ep=cc.get_constuctor_exception();
+ command_client cc(&sc);
- string errormsg;
- if (ep)
- errormsg=ep->what();
+ t2n_exception* ep=cc.get_constuctor_exception();
- CPPUNIT_ASSERT_EQUAL(string("host byte order not
matching"),errormsg);
- }
+ string errormsg;
+ if (ep)
+ errormsg=ep->what();
+
+ BOOST_CHECK_EQUAL(string("host byte order not matching"),errormsg);
}
}
+}
- void OtherServerBig()
+BOOST_AUTO_TEST_CASE(OtherServerBig)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
+ {
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
{
- case -1:
+ try
{
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ socket_server ss("./socket");
+
+ ostringstream hello;
+ // hmm, we got the wrong socket
+ hello << "* OK intradev.net.lan Cyrus IMAP4 v2.2.13 server
ready";
+
+
ss.add_callback(new_connection,bind(&test_hello::OtherServerBig::send_raw_socket,
boost::ref(*this), hello.str(),&ss, _1));
+
+ // max 3 sec
+ for (int i=0; i < 3; i++)
+ ss.fill_buffer(1000000);
+ } catch(...)
{
- try
- {
- socket_server ss("./socket");
-
- ostringstream hello;
- // hmm, we got the wrong socket
- hello << "* OK intradev.net.lan Cyrus IMAP4 v2.2.13 server
ready";
-
-
ss.add_callback(new_connection,bind(&test_hello::send_raw_socket,
boost::ref(*this), hello.str(),&ss, _1));
-
- // max 3 sec
- for (int i=0; i < 3; i++)
- ss.fill_buffer(1000000);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ default:
+ // parent
+ {
+ string data;
- command_client cc(&sc);
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- t2n_exception* ep=cc.get_constuctor_exception();
+ command_client cc(&sc);
- string errormsg;
- if (ep)
- errormsg=ep->what();
+ t2n_exception* ep=cc.get_constuctor_exception();
- CPPUNIT_ASSERT_EQUAL(string("illegal hello received
(T2N)"),errormsg);
- }
+ string errormsg;
+ if (ep)
+ errormsg=ep->what();
+
+ BOOST_CHECK_EQUAL(string("illegal hello received (T2N)"),errormsg);
}
}
+}
- void OtherServerSmall()
+BOOST_AUTO_TEST_CASE(OtherServerSmall)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ socket_server ss("./socket");
+
+ ostringstream hello;
+ // hmm, we got the wrong socket
+ hello << "READY";
+
+
ss.add_callback(new_connection,bind(&test_hello::OtherServerSmall::send_raw_socket,
boost::ref(*this), hello.str(),&ss, _1));
+
+ // max 3 sec
+ for (int i=0; i < 3; i++)
+ ss.fill_buffer(1000000);
+ } catch(...)
{
- try
- {
- socket_server ss("./socket");
-
- ostringstream hello;
- // hmm, we got the wrong socket
- hello << "READY";
-
-
ss.add_callback(new_connection,bind(&test_hello::send_raw_socket,
boost::ref(*this), hello.str(),&ss, _1));
-
- // max 3 sec
- for (int i=0; i < 3; i++)
- ss.fill_buffer(1000000);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ default:
+ // parent
+ {
+ string data;
- command_client cc(&sc);
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- t2n_exception* ep=cc.get_constuctor_exception();
+ command_client cc(&sc);
- string errormsg;
- if (ep)
- errormsg=ep->what();
+ t2n_exception* ep=cc.get_constuctor_exception();
- CPPUNIT_ASSERT_EQUAL(string("illegal hello received
(T2N)"),errormsg);
- }
+ string errormsg;
+ if (ep)
+ errormsg=ep->what();
+
+ BOOST_CHECK_EQUAL(string("illegal hello received (T2N)"),errormsg);
}
}
+}
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(test_hello);
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/newserver.cpp b/test/newserver.cpp
index bce1213..32f4d96 100644
--- a/test/newserver.cpp
+++ b/test/newserver.cpp
@@ -30,9 +30,9 @@ on this file might be covered by the GNU General Public
License.
#include <sstream>
#include <stdexcept>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <cppunit/ui/text/TestRunner.h>
-#include <cppunit/extensions/HelperMacros.h>
+#define BOOST_TEST_MAIN
+#define BOOST_TEST_DYN_LINK
+#include <boost/test/unit_test.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
@@ -46,12 +46,12 @@ on this file might be covered by the GNU General Public
License.
#include <command_client.hxx>
#include <command_server.hxx>
+#include "test_fixtures.hxx"
+
using namespace std;
-using namespace CppUnit;
int newserver_func(int i)
{
-
return 1;
}
@@ -119,117 +119,96 @@ BOOST_CLASS_EXPORT(newserver_res)
using namespace libt2n;
-class test_newserver : public TestFixture
-{
- CPPUNIT_TEST_SUITE(test_newserver);
-
- CPPUNIT_TEST(NewServerSocket);
-
- CPPUNIT_TEST_SUITE_END();
-
- pid_t child_pid;
-
- public:
-
- void setUp()
- { }
-
- void tearDown()
- {
- // make sure the server-child is dead before the next test runs
- kill(child_pid,SIGKILL);
- sleep(1);
- }
+BOOST_FIXTURE_TEST_SUITE(test_newserver, KillChildOnShutdownFixture)
- void NewServerSocket()
+BOOST_AUTO_TEST_CASE(NewServerSocket)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- {
- socket_server ss("./socket");
- // ss.set_logging(&cerr,debug);
- command_server cs(ss);
-
- // handle new connection and just one command
- cs.handle(10000000);
- cs.handle(10000000);
- }
-
- sleep(1);
-
- // close socket, create new one
- {
- socket_server ss("./socket");
- // ss.set_logging(&cerr,debug);
- command_server cs(ss);
-
- // max 30 sec
- for (int i=0; i < 30; i++)
- cs.handle(1000000);
- }
- } catch(...)
{
- std::cerr << "exception in child. ignoring\n";
+ socket_server ss("./socket");
+ // ss.set_logging(&cerr,debug);
+ command_server cs(ss);
+
+ // handle new connection and just one command
+ cs.handle(10000000);
+ cs.handle(10000000);
}
- // don't call atexit and stuff
- _exit(0);
- }
+ sleep(1);
+
+ // close socket, create new one
+ {
+ socket_server ss("./socket");
+ // ss.set_logging(&cerr,debug);
+ command_server cs(ss);
- default:
- // parent
+ // max 30 sec
+ for (int i=0; i < 30; i++)
+ cs.handle(1000000);
+ }
+ } catch(...)
{
- // don't kill us on broken pipe
- signal(SIGPIPE, SIG_IGN);
+ std::cerr << "exception in child. ignoring\n";
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
- sc.set_logging(&cerr,debug);
- command_client cc(&sc);
+ // don't call atexit and stuff
+ _exit(0);
+ }
- result_container rc;
- cc.send_command(new newserver_cmd(1),rc);
+ default:
+ // parent
+ {
+ // don't kill us on broken pipe
+ signal(SIGPIPE, SIG_IGN);
- // very short sleep to make sure new server socket is up
- sleep(1);
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
+ sc.set_logging(&cerr,debug);
+ command_client cc(&sc);
- // still has connection to the old server-socket
- string errormsg;
+ result_container rc;
+ cc.send_command(new newserver_cmd(1),rc);
- try
- {
- sc.write("some stuff");
- }
- catch(t2n_transfer_error &e)
- { errormsg=e.what(); }
- catch(...)
- { throw; }
+ // very short sleep to make sure new server socket is up
+ sleep(1);
- bool test_fine=false;
- if (errormsg == "write() returned Bad file descriptor"
- || errormsg == "write() returned Broken pipe")
- test_fine = true;
+ // still has connection to the old server-socket
+ string errormsg;
- if (!test_fine)
- {
- std::cerr << "NewServerSocket() test failed. ignoring as
the test is very fragile.\n";
- }
+ try
+ {
+ sc.write("some stuff");
+ }
+ catch(t2n_transfer_error &e)
+ { errormsg=e.what(); }
+ catch(...)
+ { throw; }
- CPPUNIT_ASSERT_EQUAL(1, 1);
+ bool test_fine=false;
+ if (errormsg == "write() returned Bad file descriptor"
+ || errormsg == "write() returned Broken pipe")
+ test_fine = true;
+
+ if (!test_fine)
+ {
+ std::cerr << "NewServerSocket() test failed. ignoring as the
test is very fragile.\n";
}
+
+ BOOST_CHECK_EQUAL(1, 1);
}
}
-};
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_newserver);
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/reconnect.cpp b/test/reconnect.cpp
index f078a95..6c70458 100644
--- a/test/reconnect.cpp
+++ b/test/reconnect.cpp
@@ -31,20 +31,20 @@ on this file might be covered by the GNU General Public
License.
#include <sstream>
#include <stdexcept>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <cppunit/ui/text/TestRunner.h>
-#include <cppunit/extensions/HelperMacros.h>
+#define BOOST_TEST_DYN_LINK
+#include <boost/test/unit_test.hpp>
#include <socket_client.hxx>
#include <socket_server.hxx>
+#include "test_fixtures.hxx"
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
using namespace std;
using namespace libt2n;
-using namespace CppUnit;
// this is an evil hack to get access to real_write, don't ever do this in an
app!!!
class real_write_connection: public socket_server_connection
@@ -54,33 +54,9 @@ class real_write_connection: public socket_server_connection
{ socket_write(data); }
};
-class test_reconnect : public TestFixture
+class test_reconnectFixture : public KillChildOnShutdownFixture
{
- CPPUNIT_TEST_SUITE(test_reconnect);
-
- CPPUNIT_TEST(simple_reconnect);
- CPPUNIT_TEST(reconnect_with_close);
- CPPUNIT_TEST(reconnect_buffer_complete);
- CPPUNIT_TEST(reconnect_buffer_several_complete);
- CPPUNIT_TEST(reconnect_buffer_no_incomplete1);
- CPPUNIT_TEST(reconnect_buffer_no_incomplete2);
-
- CPPUNIT_TEST_SUITE_END();
-
- pid_t child_pid;
-
- public:
-
- void setUp()
- { }
-
- void tearDown()
- {
- // make sure the server-child is dead before the next test runs
- kill(child_pid,SIGKILL);
- sleep(1);
- }
-
+protected:
void send_raw_socket(string hello_string, socket_server* ss, int conn_id)
{
socket_server_connection
*ssc=dynamic_cast<socket_server_connection*>(ss->get_connection(conn_id));
@@ -90,506 +66,516 @@ class test_reconnect : public TestFixture
rwc->real_write(hello_string);
}
- void simple_reconnect()
+public:
+ test_reconnectFixture()
{
- switch(child_pid=fork())
+ }
+
+ ~test_reconnectFixture()
+ {
+ }
+};
+
+BOOST_FIXTURE_TEST_SUITE(test_reconnect, test_reconnectFixture)
+
+BOOST_AUTO_TEST_CASE(simple_reconnect)
+{
+ switch(child_pid=fork())
+ {
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- socket_server ss("./socket");
+ socket_server ss("./socket");
- time_t t0 = time(NULL);
+ time_t t0 = time(NULL);
- // max 10 sec
- while (time(NULL) < t0 + 10 )
- {
- ss.fill_buffer(1000000);
+ // max 10 sec
+ while (time(NULL) < t0 + 10 )
+ {
+ ss.fill_buffer(1000000);
- string data;
- unsigned int cid;
+ string data;
+ unsigned int cid;
- if(ss.get_packet(data,cid))
- {
- server_connection* con=ss.get_connection(cid);
+ if(ss.get_packet(data,cid))
+ {
+ server_connection* con=ss.get_connection(cid);
- if (data=="QUIT")
- break;
+ if (data=="QUIT")
+ break;
- if (data=="x")
- con->write(string().insert(0,100,'X'));
- else
- con->write(string().insert(0,100,'Y'));
- }
+ if (data=="x")
+ con->write(string().insert(0,100,'X'));
+ else
+ con->write(string().insert(0,100,'Y'));
}
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
}
-
- // don't call atexit and stuff
- _exit(0);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- // don't kill us on broken pipe
- signal(SIGPIPE, SIG_IGN);
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ default:
+ // parent
+ {
+ // don't kill us on broken pipe
+ signal(SIGPIPE, SIG_IGN);
- sc.write("abc");
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- string data;
+ sc.write("abc");
- while (!sc.get_packet(data))
- sc.fill_buffer(1000000);
+ string data;
- sc.reconnect();
+ while (!sc.get_packet(data))
+ sc.fill_buffer(1000000);
- sc.write("x");
+ sc.reconnect();
- while (!sc.get_packet(data))
- sc.fill_buffer(1000000);
+ sc.write("x");
- CPPUNIT_ASSERT_EQUAL(string().insert(0,100,'X'),data);
- }
+ while (!sc.get_packet(data))
+ sc.fill_buffer(1000000);
+
+ BOOST_CHECK_EQUAL(string().insert(0,100,'X'),data);
}
}
+}
- void reconnect_with_close()
+BOOST_AUTO_TEST_CASE(reconnect_with_close)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- socket_server ss("./socket");
+ socket_server ss("./socket");
- time_t t0 = time(NULL);
+ time_t t0 = time(NULL);
- // max 10 sec
- while (time(NULL) < t0 + 10 )
- {
- ss.fill_buffer(1000000);
+ // max 10 sec
+ while (time(NULL) < t0 + 10 )
+ {
+ ss.fill_buffer(1000000);
- string data;
- unsigned int cid;
+ string data;
+ unsigned int cid;
- if(ss.get_packet(data,cid))
- {
- server_connection* con=ss.get_connection(cid);
+ if(ss.get_packet(data,cid))
+ {
+ server_connection* con=ss.get_connection(cid);
- if (data=="QUIT")
- break;
+ if (data=="QUIT")
+ break;
- if (data=="x")
- con->write(string().insert(0,100,'X'));
- else
- con->write(string().insert(0,100,'Y'));
- }
+ if (data=="x")
+ con->write(string().insert(0,100,'X'));
+ else
+ con->write(string().insert(0,100,'Y'));
}
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
}
-
- // don't call atexit and stuff
- _exit(0);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- // don't kill us on broken pipe
- signal(SIGPIPE, SIG_IGN);
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ default:
+ // parent
+ {
+ // don't kill us on broken pipe
+ signal(SIGPIPE, SIG_IGN);
- sc.write("abc");
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- string data;
+ sc.write("abc");
- while (!sc.get_packet(data))
- sc.fill_buffer(1000000);
+ string data;
- sc.close();
+ while (!sc.get_packet(data))
+ sc.fill_buffer(1000000);
- // empty buffer
- sc.get_packet(data);
+ sc.close();
- sc.reconnect();
+ // empty buffer
+ sc.get_packet(data);
- sc.write("x");
+ sc.reconnect();
- while (!sc.get_packet(data))
- sc.fill_buffer(1000000);
+ sc.write("x");
- CPPUNIT_ASSERT_EQUAL(string().insert(0,100,'X'),data);
- }
+ while (!sc.get_packet(data))
+ sc.fill_buffer(1000000);
+
+ BOOST_CHECK_EQUAL(string().insert(0,100,'X'),data);
}
}
+}
- void reconnect_buffer_complete()
+BOOST_AUTO_TEST_CASE(reconnect_buffer_complete)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- socket_server ss("./socket");
+ socket_server ss("./socket");
- time_t t0 = time(NULL);
+ time_t t0 = time(NULL);
- // max 10 sec
- while (time(NULL) < t0 + 10 )
- {
- ss.fill_buffer(1000000);
+ // max 10 sec
+ while (time(NULL) < t0 + 10 )
+ {
+ ss.fill_buffer(1000000);
- string data;
- unsigned int cid;
+ string data;
+ unsigned int cid;
- if(ss.get_packet(data,cid))
- {
- server_connection* con=ss.get_connection(cid);
+ if(ss.get_packet(data,cid))
+ {
+ server_connection* con=ss.get_connection(cid);
- if (data=="QUIT")
- break;
+ if (data=="QUIT")
+ break;
- if (data=="x")
- con->write(string().insert(0,100,'X'));
- }
+ if (data=="x")
+ con->write(string().insert(0,100,'X'));
}
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
}
-
- // don't call atexit and stuff
- _exit(0);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- // don't kill us on broken pipe
- signal(SIGPIPE, SIG_IGN);
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ default:
+ // parent
+ {
+ // don't kill us on broken pipe
+ signal(SIGPIPE, SIG_IGN);
- sc.write("x");
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- string data;
+ sc.write("x");
- while (!sc.packet_available())
- sc.fill_buffer(1000000);
+ string data;
- sc.reconnect();
+ while (!sc.packet_available())
+ sc.fill_buffer(1000000);
- CPPUNIT_ASSERT_EQUAL_MESSAGE("packet not
there",true,sc.get_packet(data));
+ sc.reconnect();
- CPPUNIT_ASSERT_EQUAL_MESSAGE("data
incorrect",string().insert(0,100,'X'),data);
- }
+ BOOST_CHECK_MESSAGE(sc.get_packet(data) == true, "packet not
there");
+
+ BOOST_CHECK_MESSAGE(data == string().insert(0,100,'X'), "data
incorrect");
}
}
+}
- void reconnect_buffer_several_complete()
- {
- const int packets=3;
+BOOST_AUTO_TEST_CASE(reconnect_buffer_several_complete)
+{
+ const int packets=3;
- switch(child_pid=fork())
+ switch(child_pid=fork())
+ {
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
+ socket_server ss("./socket");
+
+ time_t t0 = time(NULL);
+
+ // max 10 sec
+ while (time(NULL) < t0 + 10 )
{
- socket_server ss("./socket");
+ ss.fill_buffer(1000000);
- time_t t0 = time(NULL);
+ string data;
+ unsigned int cid;
- // max 10 sec
- while (time(NULL) < t0 + 10 )
+ if(ss.get_packet(data,cid))
{
- ss.fill_buffer(1000000);
+ server_connection* con=ss.get_connection(cid);
- string data;
- unsigned int cid;
+ if (data=="QUIT")
+ break;
- if(ss.get_packet(data,cid))
+ if (data=="x")
{
- server_connection* con=ss.get_connection(cid);
-
- if (data=="QUIT")
- break;
-
- if (data=="x")
- {
- for (int i=0; i<packets; i++)
- con->write(string().insert(0,100,'X'));
- }
+ for (int i=0; i<packets; i++)
+ con->write(string().insert(0,100,'X'));
}
}
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
}
-
- // don't call atexit and stuff
- _exit(0);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- // don't kill us on broken pipe
- signal(SIGPIPE, SIG_IGN);
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ default:
+ // parent
+ {
+ // don't kill us on broken pipe
+ signal(SIGPIPE, SIG_IGN);
- sc.write("x");
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- // retrieve packets for 3 seconds
- time_t t0 = time(NULL);
+ sc.write("x");
- // max 3 sec
- while (time(NULL) < t0 + 3 )
- sc.fill_buffer(1000000);
+ // retrieve packets for 3 seconds
+ time_t t0 = time(NULL);
- // we now should have packets complete packets in the buffer
+ // max 3 sec
+ while (time(NULL) < t0 + 3 )
+ sc.fill_buffer(1000000);
- sc.reconnect();
+ // we now should have packets complete packets in the buffer
- // are these packets still there?
+ sc.reconnect();
- for (int i=0; i < packets; i++)
- {
- string data;
+ // are these packets still there?
- ostringstream os;
- os << "packet " << i << " not there";
+ for (int i=0; i < packets; i++)
+ {
+ string data;
-
CPPUNIT_ASSERT_EQUAL_MESSAGE(os.str(),true,sc.get_packet(data));
+ ostringstream os;
+ os << "packet " << i << " not there";
- os.str("");
- os << "packet " << i << " incorrect";
+ BOOST_CHECK_MESSAGE(sc.get_packet(data) == true, os.str());
-
CPPUNIT_ASSERT_EQUAL_MESSAGE(os.str(),string().insert(0,100,'X'),data);
- }
+ os.str("");
+ os << "packet " << i << " incorrect";
+
+ BOOST_CHECK_MESSAGE(string().insert(0,100,'X') == data,
os.str());
}
}
}
+}
- void reconnect_buffer_no_incomplete1()
+BOOST_AUTO_TEST_CASE(reconnect_buffer_no_incomplete1)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
+ socket_server ss("./socket");
+
+ time_t t0 = time(NULL);
+
+ // max 10 sec
+ while (time(NULL) < t0 + 10 )
{
- socket_server ss("./socket");
+ ss.fill_buffer(1000000);
- time_t t0 = time(NULL);
+ string data;
+ unsigned int cid;
- // max 10 sec
- while (time(NULL) < t0 + 10 )
+ if(ss.get_packet(data,cid))
{
- ss.fill_buffer(1000000);
+ server_connection* con=ss.get_connection(cid);
- string data;
- unsigned int cid;
+ if (data=="QUIT")
+ break;
- if(ss.get_packet(data,cid))
+ if (data=="x")
{
- server_connection* con=ss.get_connection(cid);
-
- if (data=="QUIT")
- break;
-
- if (data=="x")
- {
- con->write(string().insert(0,100,'X'));
- send_raw_socket("aaaab",&ss,cid);
- }
+ con->write(string().insert(0,100,'X'));
+ send_raw_socket("aaaab",&ss,cid);
}
}
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
}
-
- // don't call atexit and stuff
- _exit(0);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- // don't kill us on broken pipe
- signal(SIGPIPE, SIG_IGN);
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ default:
+ // parent
+ {
+ // don't kill us on broken pipe
+ signal(SIGPIPE, SIG_IGN);
- sc.write("x");
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- // retrieve packets for 3 seconds
- time_t t0 = time(NULL);
+ sc.write("x");
- // max 3 sec
- while (time(NULL) < t0 + 3 )
- sc.fill_buffer(1000000);
+ // retrieve packets for 3 seconds
+ time_t t0 = time(NULL);
- // we now should have one complete packet and some stuff in
the buffer
+ // max 3 sec
+ while (time(NULL) < t0 + 3 )
+ sc.fill_buffer(1000000);
- string data;
- sc.get_packet(data);
+ // we now should have one complete packet and some stuff in the
buffer
- CPPUNIT_ASSERT_EQUAL_MESSAGE("no incomplete
packet",true,(sc.peek_packet(data))>0);
+ string data;
+ sc.get_packet(data);
- sc.reconnect();
+ BOOST_CHECK_MESSAGE((sc.peek_packet(data))>0, "no incomplete
packet");
- CPPUNIT_ASSERT_EQUAL_MESSAGE("incomplete packet not
removed",0,(int)sc.peek_packet(data));
- }
+ sc.reconnect();
+
+ BOOST_CHECK_MESSAGE((int)sc.peek_packet(data) == 0, "incomplete
packet not removed");
}
}
+}
- void reconnect_buffer_no_incomplete2()
+BOOST_AUTO_TEST_CASE(reconnect_buffer_no_incomplete2)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
+ socket_server ss("./socket");
+
+ time_t t0 = time(NULL);
+
+ // max 10 sec
+ while (time(NULL) < t0 + 10 )
{
- socket_server ss("./socket");
+ ss.fill_buffer(1000000);
- time_t t0 = time(NULL);
+ string data;
+ unsigned int cid;
- // max 10 sec
- while (time(NULL) < t0 + 10 )
+ if(ss.get_packet(data,cid))
{
- ss.fill_buffer(1000000);
+ server_connection* con=ss.get_connection(cid);
- string data;
- unsigned int cid;
+ if (data=="QUIT")
+ break;
- if(ss.get_packet(data,cid))
+ if (data=="x")
{
- server_connection* con=ss.get_connection(cid);
+ con->write(string().insert(0,100,'X'));
- if (data=="QUIT")
- break;
+ string blob=string().insert(0,100,'Y');
- if (data=="x")
- {
- con->write(string().insert(0,100,'X'));
-
- string blob=string().insert(0,100,'Y');
-
- // one byte will be missing...
- int size=blob.size()+1;
- char sizetransfer[sizeof(int)+1];
- memcpy(sizetransfer,(void*)&size,sizeof(int));
- sizetransfer[sizeof(int)+1]=0;
+ // one byte will be missing...
+ int size=blob.size()+1;
+ char sizetransfer[sizeof(int)+1];
+ memcpy(sizetransfer,(void*)&size,sizeof(int));
+ sizetransfer[sizeof(int)+1]=0;
- string packet=string(sizetransfer)+blob;
+ string packet=string(sizetransfer)+blob;
- send_raw_socket(packet,&ss,cid);
- }
+ send_raw_socket(packet,&ss,cid);
}
}
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
}
-
- // don't call atexit and stuff
- _exit(0);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- // don't kill us on broken pipe
- signal(SIGPIPE, SIG_IGN);
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ default:
+ // parent
+ {
+ // don't kill us on broken pipe
+ signal(SIGPIPE, SIG_IGN);
- sc.write("x");
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- // retrieve packets for 3 seconds
- time_t t0 = time(NULL);
+ sc.write("x");
- // max 3 sec
- while (time(NULL) < t0 + 3 )
- sc.fill_buffer(1000000);
+ // retrieve packets for 3 seconds
+ time_t t0 = time(NULL);
- // we now should have one complete packet and some stuff in
the buffer
+ // max 3 sec
+ while (time(NULL) < t0 + 3 )
+ sc.fill_buffer(1000000);
- sc.reconnect();
+ // we now should have one complete packet and some stuff in the
buffer
- string data;
+ sc.reconnect();
- CPPUNIT_ASSERT_EQUAL_MESSAGE("packet not
there",true,sc.get_packet(data));
- CPPUNIT_ASSERT_EQUAL_MESSAGE("data
incorrect",string().insert(0,100,'X'),data);
+ string data;
- CPPUNIT_ASSERT_EQUAL_MESSAGE("incomplete packet not
removed",0,(int)sc.peek_packet(data));
- }
+ BOOST_CHECK_MESSAGE(sc.get_packet(data) == true, "packet not
there");
+ BOOST_CHECK_MESSAGE(string().insert(0,100,'X') == data, "data
incorrect");
+
+ BOOST_CHECK_MESSAGE((int)sc.peek_packet(data) == 0, "incomplete
packet not removed");
}
}
+}
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(test_reconnect);
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/reentrant.cpp b/test/reentrant.cpp
index c69facc..204e741 100644
--- a/test/reentrant.cpp
+++ b/test/reentrant.cpp
@@ -30,9 +30,8 @@ on this file might be covered by the GNU General Public
License.
#include <sstream>
#include <stdexcept>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <cppunit/ui/text/TestRunner.h>
-#include <cppunit/extensions/HelperMacros.h>
+#define BOOST_TEST_DYN_LINK
+#include <boost/test/unit_test.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
@@ -47,7 +46,6 @@ on this file might be covered by the GNU General Public
License.
#include <command_server.hxx>
using namespace std;
-using namespace CppUnit;
using namespace libt2n;
namespace reentrant
@@ -144,111 +142,94 @@ BOOST_CLASS_EXPORT(reentrant::testfunc_res)
using namespace reentrant;
-class test_reentrant : public TestFixture
-{
- CPPUNIT_TEST_SUITE(test_reentrant);
-
- CPPUNIT_TEST(ReentrantServer);
-
- CPPUNIT_TEST_SUITE_END();
-
- public:
+BOOST_AUTO_TEST_SUITE(test_reentrant)
- void setUp()
- { }
-
- void tearDown()
- { }
-
- void ReentrantServer()
+BOOST_AUTO_TEST_CASE(ReentrantServer)
+{
+ switch(fork())
{
- switch(fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
- {
- // wait till server is up
- sleep(2);
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ // wait till server is up
+ sleep(2);
- // hammer the server
- for (int i = 0; i < fork_count; i++)
- fork();
+ // hammer the server
+ for (int i = 0; i < fork_count; i++)
+ fork();
- try
+ try
+ {
+ for (int i=0; i < requests_per_child; i++)
{
- for (int i=0; i < requests_per_child; i++)
+ socket_client_connection sc("./socket");
+ // sc.set_logging(&cerr,debug);
+ command_client cc(&sc);
+
+ result_container rc;
+ cc.send_command(new testfunc_cmd("hello"),rc);
+
+ testfunc_res *res =
dynamic_cast<testfunc_res*>(rc.get_result());
+ if (res)
{
- socket_client_connection sc("./socket");
- // sc.set_logging(&cerr,debug);
- command_client cc(&sc);
-
- result_container rc;
- cc.send_command(new testfunc_cmd("hello"),rc);
-
- testfunc_res *res =
dynamic_cast<testfunc_res*>(rc.get_result());
- if (res)
- {
- string ret = res->get_data();
- if (ret != "hello, testfunc() was here")
- std::cout << "ERROR reentrant server
testfunc_res failed, res: \"" << ret << "\"\n";
- }
- else
- {
- std::cout << "ERROR result from reentrant server
empty (" << rc.get_result() << ")\n";
- }
+ string ret = res->get_data();
+ if (ret != "hello, testfunc() was here")
+ std::cout << "ERROR reentrant server testfunc_res
failed, res: \"" << ret << "\"\n";
+ }
+ else
+ {
+ std::cout << "ERROR result from reentrant server empty
(" << rc.get_result() << ")\n";
}
- } catch (exception &e)
- {
- cerr << "caught exception: " << e.what() << endl;
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
}
-
- // don't call atexit and stuff
- _exit(0);
+ } catch (exception &e)
+ {
+ cerr << "caught exception: " << e.what() << endl;
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- // don't kill us on broken pipe
- signal(SIGPIPE, SIG_IGN);
+ // don't call atexit and stuff
+ _exit(0);
+ }
- socket_server ss("./socket");
- command_server cs(ss);
+ default:
+ // parent
+ {
+ // don't kill us on broken pipe
+ signal(SIGPIPE, SIG_IGN);
- global_server=&cs;
+ socket_server ss("./socket");
+ command_server cs(ss);
- // Wait until all requests have successed
- int safety_check = 0;
- while (seen_client_requests < all_requests)
- {
- ++safety_check;
- if (safety_check > 10) {
- std::cerr << "reached safety check, aborting.\n";
- break;
- }
+ global_server=&cs;
- long long maxtime=1000000;
- while(maxtime > 0)
- cs.handle(maxtime,&maxtime);
+ // Wait until all requests have successed
+ int safety_check = 0;
+ while (seen_client_requests < all_requests)
+ {
+ ++safety_check;
+ if (safety_check > 10) {
+ std::cerr << "reached safety check, aborting.\n";
+ break;
}
- global_server = NULL;
+ long long maxtime=1000000;
+ while(maxtime > 0)
+ cs.handle(maxtime,&maxtime);
}
- // we are still alive, everything is ok
- CPPUNIT_ASSERT_EQUAL(all_requests, seen_client_requests);
+ global_server = NULL;
}
- }
-
-};
+ // we are still alive, everything is ok
+ BOOST_CHECK_EQUAL(all_requests, seen_client_requests);
+ }
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_reentrant);
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/serialize.cpp b/test/serialize.cpp
index 634c01a..598ac4b 100644
--- a/test/serialize.cpp
+++ b/test/serialize.cpp
@@ -30,9 +30,10 @@ on this file might be covered by the GNU General Public
License.
#include <sstream>
#include <stdexcept>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <cppunit/ui/text/TestRunner.h>
-#include <cppunit/extensions/HelperMacros.h>
+#include "test_fixtures.hxx"
+
+#define BOOST_TEST_DYN_LINK
+#include <boost/test/unit_test.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
@@ -47,7 +48,6 @@ on this file might be covered by the GNU General Public
License.
#include <command_server.hxx>
using namespace std;
-using namespace CppUnit;
string testfunc3(const string& str)
{
@@ -119,88 +119,64 @@ class testfunc3_cmd : public libt2n::command
using namespace libt2n;
-class test_serialize : public TestFixture
-{
- CPPUNIT_TEST_SUITE(test_serialize);
-
- CPPUNIT_TEST(ClientSerializeErr);
-
- // TODO: Server Deserialization Error
- // TODO: Server Serialization Error
- // TODO: Client Deserialization Error
- // but those probably need separate client/server binaries
-
- CPPUNIT_TEST_SUITE_END();
-
- pid_t child_pid;
-
- public:
-
- void setUp()
- {
- }
-
- void tearDown()
- {
- // make sure the server-child is dead before the next test runs
- kill(child_pid,SIGKILL);
- sleep(1);
- }
+BOOST_FIXTURE_TEST_SUITE(test_serialize, KillChildOnShutdownFixture)
+// TODO: Server Deserialization Error
+// TODO: Server Serialization Error
+// TODO: Client Deserialization Error
+// but those probably need separate client/server binaries
- void ClientSerializeErr()
+BOOST_AUTO_TEST_CASE(ClientSerializeErr)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
+ {
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
{
- case -1:
+ try
{
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ socket_server ss("./socket");
+ command_server cs(ss);
+
+ // max 10 sec
+ for (int i=0; i < 10; i++)
+ cs.handle(1000000);
+ } catch(...)
{
- try
- {
- socket_server ss("./socket");
- command_server cs(ss);
-
- // max 10 sec
- for (int i=0; i < 10; i++)
- cs.handle(1000000);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
+ // don't call atexit and stuff
+ _exit(0);
+ }
+
+ default:
+ // parent
+ {
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
+ command_client cc(&sc);
+
+ string errormsg;
+
+ result_container rc;
+ try
{
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
- command_client cc(&sc);
-
- string errormsg;
-
- result_container rc;
- try
- {
- cc.send_command(new testfunc3_cmd("xyz"),rc);
- }
- catch(t2n_serialization_error &e)
- { errormsg=e.what(); }
- catch(...)
- { throw; }
-
- CPPUNIT_ASSERT_EQUAL(string("archive_exception while
serializing on client-side, code 2 (unregistered class)"),errormsg);
+ cc.send_command(new testfunc3_cmd("xyz"),rc);
}
+ catch(t2n_serialization_error &e)
+ { errormsg=e.what(); }
+ catch(...)
+ { throw; }
+
+ BOOST_CHECK_EQUAL(string("archive_exception while serializing on
client-side, code 2 (unregistered class)"),errormsg);
}
}
+}
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(test_serialize);
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/simplecmd.cpp b/test/simplecmd.cpp
index 03071de..11de9ca 100644
--- a/test/simplecmd.cpp
+++ b/test/simplecmd.cpp
@@ -30,9 +30,8 @@ on this file might be covered by the GNU General Public
License.
#include <sstream>
#include <stdexcept>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <cppunit/ui/text/TestRunner.h>
-#include <cppunit/extensions/HelperMacros.h>
+#define BOOST_TEST_DYN_LINK
+#include <boost/test/unit_test.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
@@ -46,8 +45,9 @@ on this file might be covered by the GNU General Public
License.
#include <command_client.hxx>
#include <command_server.hxx>
+#include "test_fixtures.hxx"
+
using namespace std;
-using namespace CppUnit;
string testfunc(const string& str)
{
@@ -125,231 +125,206 @@ BOOST_CLASS_EXPORT(testfunc_res)
using namespace libt2n;
-class test_simplecmd : public TestFixture
+BOOST_FIXTURE_TEST_SUITE(test_simplecmd, KillChildOnShutdownFixture)
+
+BOOST_AUTO_TEST_CASE(SimpleCmd)
{
- CPPUNIT_TEST_SUITE(test_simplecmd);
+ switch(child_pid=fork())
+ {
+ case -1:
+ {
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
+ {
+ socket_server ss("./socket");
+ command_server cs(ss);
- CPPUNIT_TEST(SimpleCmd);
- CPPUNIT_TEST(SimpleException);
- CPPUNIT_TEST(BigReturn);
- CPPUNIT_TEST(BigParameter);
+ // max 10 sec
+ for (int i=0; i < 10; i++)
+ cs.handle(1000000);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
+ }
- CPPUNIT_TEST_SUITE_END();
+ // don't call atexit and stuff
+ _exit(0);
+ }
- pid_t child_pid;
+ default:
+ // parent
+ {
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
+ sc.set_logging(&cerr,debug);
+ command_client cc(&sc);
- public:
+ result_container rc;
+ cc.send_command(new testfunc_cmd("hello"),rc);
- void setUp()
- { }
+ string
ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
- void tearDown()
- {
- // make sure the server-child is dead before the next test runs
- kill(child_pid,SIGKILL);
- sleep(1);
+ BOOST_CHECK_EQUAL(string("hello, testfunc() was here"),ret);
+ }
}
+}
- void SimpleCmd()
+BOOST_AUTO_TEST_CASE(SimpleException)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
+ {
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
{
- case -1:
+ try
{
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ socket_server ss("./socket");
+ command_server cs(ss);
+
+ // max 10 sec
+ for (int i=0; i < 10; i++)
+ cs.handle(1000000);
+ } catch(...)
{
- try
- {
- socket_server ss("./socket");
- command_server cs(ss);
-
- // max 10 sec
- for (int i=0; i < 10; i++)
- cs.handle(1000000);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
- sc.set_logging(&cerr,debug);
- command_client cc(&sc);
+ // don't call atexit and stuff
+ _exit(0);
+ }
- result_container rc;
- cc.send_command(new testfunc_cmd("hello"),rc);
+ default:
+ // parent
+ {
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
+ sc.set_logging(&cerr,debug);
+ command_client cc(&sc);
- string
ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
+ result_container rc;
+ cc.send_command(new testfunc_cmd("throw"),rc);
- CPPUNIT_ASSERT_EQUAL(string("hello, testfunc() was here"),ret);
- }
- }
- }
+ string ret;
- void SimpleException()
- {
- switch(child_pid=fork())
- {
- case -1:
+ try
{
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
- {
- try
- {
- socket_server ss("./socket");
- command_server cs(ss);
-
- // max 10 sec
- for (int i=0; i < 10; i++)
- cs.handle(1000000);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
+ ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
}
+ catch(t2n_runtime_error &e)
+ { ret=e.what(); }
+ catch(...)
+ { throw; }
- default:
- // parent
- {
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
- sc.set_logging(&cerr,debug);
- command_client cc(&sc);
-
- result_container rc;
- cc.send_command(new testfunc_cmd("throw"),rc);
-
- string ret;
-
- try
- {
-
ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
- }
- catch(t2n_runtime_error &e)
- { ret=e.what(); }
- catch(...)
- { throw; }
-
- CPPUNIT_ASSERT_EQUAL(string("throw me around"),ret);
- }
+ BOOST_CHECK_EQUAL(string("throw me around"),ret);
}
}
+}
- void BigReturn()
+BOOST_AUTO_TEST_CASE(BigReturn)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
+ {
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
{
- case -1:
+ try
{
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ socket_server ss("./socket");
+ command_server cs(ss);
+
+ // max 10 sec
+ for (int i=0; i < 10; i++)
+ cs.handle(1000000);
+ } catch(...)
{
- try
- {
- socket_server ss("./socket");
- command_server cs(ss);
-
- // max 10 sec
- for (int i=0; i < 10; i++)
- cs.handle(1000000);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
- command_client cc(&sc);
+ // don't call atexit and stuff
+ _exit(0);
+ }
- result_container rc;
- cc.send_command(new testfunc_cmd("big"),rc);
+ default:
+ // parent
+ {
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
+ command_client cc(&sc);
- string
ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
+ result_container rc;
+ cc.send_command(new testfunc_cmd("big"),rc);
- CPPUNIT_ASSERT_EQUAL(string().insert(0,100*1024,'x'),ret);
- }
+ string
ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
+
+ BOOST_CHECK_EQUAL(string().insert(0,100*1024,'x'),ret);
}
}
+}
- void BigParameter()
+BOOST_AUTO_TEST_CASE(BigParameter)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- CPPUNIT_FAIL("fork error");
- break;
+ socket_server ss("./socket");
+ command_server cs(ss);
+
+ // max 60 sec - we need atleast 28 handle calls to transfer
the buffer
+ for (int i=0; i < 60; i++) {
+ cs.handle(1000000);
}
- case 0:
- // child
+ } catch(...)
{
- try
- {
- socket_server ss("./socket");
- command_server cs(ss);
-
- // max 60 sec - we need atleast 28 handle calls to
transfer the buffer
- for (int i=0; i < 60; i++) {
- cs.handle(1000000);
- }
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
- command_client cc(&sc);
+ // don't call atexit and stuff
+ _exit(0);
+ }
+
+ default:
+ // parent
+ {
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
+ command_client cc(&sc);
- result_container rc;
- cc.send_command(new
testfunc_cmd(string().insert(0,100*1024,'y')),rc);
+ result_container rc;
+ cc.send_command(new
testfunc_cmd(string().insert(0,100*1024,'y')),rc);
- string
ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
+ string
ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
- CPPUNIT_ASSERT_EQUAL(string().insert(0,100*1024,'y')+",
testfunc() was here",ret);
- }
+ BOOST_CHECK_EQUAL(string().insert(0,100*1024,'y')+", testfunc()
was here",ret);
}
}
+}
-};
-
-CPPUNIT_TEST_SUITE_REGISTRATION(test_simplecmd);
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/test.cpp b/test/test.cpp
deleted file mode 100644
index 2298980..0000000
--- a/test/test.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
-Copyright (C) 2004 by Intra2net AG
-
-The software in this package is distributed under the GNU General
-Public License version 2 (with a special exception described below).
-
-A copy of GNU General Public License (GPL) is included in this distribution,
-in the file COPYING.GPL.
-
-As a special exception, if other files instantiate templates or use macros
-or inline functions from this file, or you compile this file and link it
-with other works to produce a work based on this file, this file
-does not by itself cause the resulting work to be covered
-by the GNU General Public License.
-
-However the source code for this file must still be made available
-in accordance with section (3) of the GNU General Public License.
-
-This exception does not invalidate any other reasons why a work based
-on this file might be covered by the GNU General Public License.
-*/
-#include <iostream>
-#include <iomanip>
-#include <string>
-
-#include <time.h>
-#include <sys/timeb.h>
-
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <cppunit/ui/text/TestRunner.h>
-#include <cppunit/TestListener.h>
-#include <cppunit/TestFailure.h>
-#include <cppunit/TestResult.h>
-#include <cppunit/CompilerOutputter.h>
-
-class VerboseTimingListener : public CppUnit::TestListener
-{
- private:
- double start_time;
- std::string resultstr;
-
- double get_time(void)
- {
- struct timeb tb;
- ftime(&tb);
- return tb.time+(static_cast<float>(tb.millitm)/1000);
- }
-
- public:
-
- void startTest( CppUnit::Test *test )
- {
- resultstr="OK";
- std::cout << test->getName() << ": ";
- start_time=get_time();
- }
-
- void endTest( CppUnit::Test *test )
- {
- double timediff=get_time()-start_time;
-
- // fix clock unpreciseness for small timespans
- if (timediff < 0) timediff=0;
-
- std::cout << resultstr << " ("
- << std::fixed << std::setprecision(3)
- << timediff << " sec)" << std::endl;
- }
-
- void addFailure(const CppUnit::TestFailure &failure)
- {
- if(failure.isError())
- resultstr="ERROR";
- else
- resultstr="FAIL";
- }
-};
-
-int main(int argc, char **argv)
-{
- CppUnit::TextTestRunner runner;
- CppUnit::TestFactoryRegistry ®istry =
CppUnit::TestFactoryRegistry::getRegistry();
-
- // set output format that KDevelop can catch errors
- CppUnit::CompilerOutputter
*op=CppUnit::CompilerOutputter::defaultOutputter(&runner.result(),std::cout);
- op->setLocationFormat("%p:%l: error: ");
- runner.setOutputter(op);
-
- // show every test with timing
- VerboseTimingListener listener;
- runner.eventManager().addListener(&listener);
-
- runner.addTest(registry.makeTest());
-
- // run all tests in registry (not using the default progress listener)
- bool wasSucessful = runner.run("",false,true,false);
-
- return (wasSucessful ? 0 : 1);
-}
diff --git a/test/test_fixtures.hxx b/test/test_fixtures.hxx
new file mode 100644
index 0000000..882457c
--- /dev/null
+++ b/test/test_fixtures.hxx
@@ -0,0 +1,57 @@
+/*
+Copyright (C) 2010 by Intra2net AG - Thomas Jarosch
+
+The software in this package is distributed under the GNU General
+Public License version 2 (with a special exception described below).
+
+A copy of GNU General Public License (GPL) is included in this distribution,
+in the file COPYING.GPL.
+
+As a special exception, if other files instantiate templates or use macros
+or inline functions from this file, or you compile this file and link it
+with other works to produce a work based on this file, this file
+does not by itself cause the resulting work to be covered
+by the GNU General Public License.
+
+However the source code for this file must still be made available
+in accordance with section (3) of the GNU General Public License.
+
+This exception does not invalidate any other reasons why a work based
+on this file might be covered by the GNU General Public License.
+*/
+#ifndef __LIBT2N_TEST_FIXTURES
+#define __LIBT2N_TEST_FIXTURES
+
+#include <sys/wait.h>
+#include <sys/types.h>
+#include <signal.h>
+
+class KillChildOnShutdownFixture
+{
+protected:
+ pid_t child_pid;
+
+public:
+ KillChildOnShutdownFixture()
+ : child_pid(0)
+ {
+ // Work around Boost.test reporting killed childs as "fatal error".
+ // Can be ignored with boost 1.40.0+, need to check after upgrade
+ signal(SIGCHLD, SIG_IGN);
+ }
+
+ ~KillChildOnShutdownFixture()
+ {
+ // make sure the server-child is dead before the next test runs
+ if (child_pid)
+ {
+ // std::cout << "Killing child with pid: " << child_pid <<
std::endl;
+ kill(child_pid, SIGKILL);
+
+ int status = 0;
+ waitpid(child_pid, &status, 0);
+ }
+ }
+};
+
+#endif
diff --git a/test/timeout.cpp b/test/timeout.cpp
index 509d88d..3434c0b 100644
--- a/test/timeout.cpp
+++ b/test/timeout.cpp
@@ -32,9 +32,8 @@ on this file might be covered by the GNU General Public
License.
#include <boost/bind.hpp>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <cppunit/ui/text/TestRunner.h>
-#include <cppunit/extensions/HelperMacros.h>
+#define BOOST_TEST_DYN_LINK
+#include <boost/test/unit_test.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
@@ -48,13 +47,14 @@ on this file might be covered by the GNU General Public
License.
#include <command_client.hxx>
#include <command_server.hxx>
+#include "test_fixtures.hxx"
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
using namespace std;
using namespace libt2n;
-using namespace CppUnit;
string testfunc2(const string& str)
{
@@ -143,38 +143,12 @@ class real_write_client_connection: public
socket_client_connection
{ socket_write(data); }
};
-class test_timeout : public TestFixture
-{
- CPPUNIT_TEST_SUITE(test_timeout);
-
- CPPUNIT_TEST(ConnectTimeout);
- CPPUNIT_TEST(HelloTimeoutNothing);
- CPPUNIT_TEST(HelloTimeoutSlowData);
- CPPUNIT_TEST(CommandTimeout);
- CPPUNIT_TEST(CommandSlowResponse);
- CPPUNIT_TEST(DisconnectOnWrite);
- CPPUNIT_TEST(WriteTwice);
- CPPUNIT_TEST(DisconnectOnRead);
- CPPUNIT_TEST(BreakAccept);
-
- CPPUNIT_TEST_SUITE_END();
-
- pid_t child_pid;
-
- public:
+class test_timeoutFixture : public KillChildOnShutdownFixture
+{
+protected:
typedef uint32_t packet_size_indicator;
- void setUp()
- { }
-
- void tearDown()
- {
- // make sure the server-child is dead before the next test runs
- kill(child_pid,SIGKILL);
- sleep(1);
- }
-
void send_hello(string hello_string, socket_server* ss, unsigned int
conn_id)
{
server_connection *sc=ss->get_connection(conn_id);
@@ -198,626 +172,639 @@ class test_timeout : public TestFixture
}
}
- void ConnectTimeout()
+public:
+ test_timeoutFixture()
+ {
+ }
+
+ ~test_timeoutFixture()
+ {
+ }
+};
+
+BOOST_FIXTURE_TEST_SUITE(test_timeout, test_timeoutFixture)
+
+BOOST_AUTO_TEST_CASE(ConnectTimeout)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ socket_server ss("./socket");
+ } catch(...)
{
- try
- {
- socket_server ss("./socket");
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
+ default:
+ // parent
+ {
+ string data;
- string errormsg;
+ // wait till server is up
+ sleep(1);
- socket_client_connection sc("./socket");
+ string errormsg;
- CPPUNIT_ASSERT_EQUAL_MESSAGE("connection not
closed",true,sc.connection::is_closed());
+ socket_client_connection sc("./socket");
- CPPUNIT_ASSERT_EQUAL_MESSAGE("wrong errormessage",string("no
more retries left after connect error"),sc.get_last_error_msg());
- }
+ BOOST_CHECK_MESSAGE(sc.connection::is_closed() == true,
"connection not closed");
+
+ BOOST_CHECK_MESSAGE(sc.get_last_error_msg() == string("no more
retries left after connect error"), "wrong errormessage");
}
}
+}
- void HelloTimeoutNothing()
+BOOST_AUTO_TEST_CASE(HelloTimeoutNothing)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- socket_server ss("./socket");
-
- // max 10 sec
- for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
+ socket_server ss("./socket");
- // don't call atexit and stuff
- _exit(0);
+ // max 10 sec
+ for (int i=0; i < 10; i++)
+ ss.fill_buffer(1000000);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
- command_client cc(&sc,1000000,1000000);
+ default:
+ // parent
+ {
+ string data;
- t2n_exception* ep=cc.get_constuctor_exception();
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
+ command_client cc(&sc,1000000,1000000);
- string errormsg;
- if (ep)
- errormsg=ep->what();
+ t2n_exception* ep=cc.get_constuctor_exception();
- CPPUNIT_ASSERT_EQUAL(string("timeout exceeded"),errormsg);
- }
+ string errormsg;
+ if (ep)
+ errormsg=ep->what();
+
+ BOOST_CHECK_EQUAL(string("timeout exceeded"),errormsg);
}
}
+}
- void HelloTimeoutSlowData()
+BOOST_AUTO_TEST_CASE(HelloTimeoutSlowData)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- socket_server ss("./socket");
+ socket_server ss("./socket");
- // create a valid packet
- ostringstream hello;
- hello << "T2Nv" << PROTOCOL_VERSION << ';';
- int byteordercheck=1;
- hello.write((char*)&byteordercheck,sizeof(byteordercheck));
- hello << ';';
+ // create a valid packet
+ ostringstream hello;
+ hello << "T2Nv" << PROTOCOL_VERSION << ';';
+ int byteordercheck=1;
+ hello.write((char*)&byteordercheck,sizeof(byteordercheck));
+ hello << ';';
- packet_size_indicator psize=htonl(hello.str().size());
- std::string send_data(hello.str());
-
send_data.insert(0,(char*)&psize,sizeof(packet_size_indicator));
+ packet_size_indicator psize=htonl(hello.str().size());
+ std::string send_data(hello.str());
+
send_data.insert(0,(char*)&psize,sizeof(packet_size_indicator));
-
ss.add_callback(new_connection,bind(&test_timeout::send_slow_raw_socket,
boost::ref(*this), send_data,&ss, _1));
+
ss.add_callback(new_connection,bind(&test_timeout::HelloTimeoutSlowData::send_slow_raw_socket,
boost::ref(*this), send_data,&ss, _1));
- // max 10 sec
- for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
+ // max 10 sec
+ for (int i=0; i < 10; i++)
+ ss.fill_buffer(1000000);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
- command_client cc(&sc,1000000,1000000);
+ default:
+ // parent
+ {
+ string data;
- t2n_exception* ep=cc.get_constuctor_exception();
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
+ command_client cc(&sc,1000000,1000000);
- string errormsg;
- if (ep)
- errormsg=ep->what();
+ t2n_exception* ep=cc.get_constuctor_exception();
- CPPUNIT_ASSERT_EQUAL(string("timeout exceeded"),errormsg);
- }
+ string errormsg;
+ if (ep)
+ errormsg=ep->what();
+
+ BOOST_CHECK_EQUAL(string("timeout exceeded"),errormsg);
}
}
+}
- void CommandTimeout()
+BOOST_AUTO_TEST_CASE(CommandTimeout)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- socket_server ss("./socket");
-
- ostringstream hello;
- hello << "T2Nv" << PROTOCOL_VERSION << ';';
- int byteordercheck=1;
- hello.write((char*)&byteordercheck,sizeof(byteordercheck));
- hello << ';';
+ socket_server ss("./socket");
-
ss.add_callback(new_connection,bind(&test_timeout::send_hello,
boost::ref(*this), hello.str(),&ss, _1));
+ ostringstream hello;
+ hello << "T2Nv" << PROTOCOL_VERSION << ';';
+ int byteordercheck=1;
+ hello.write((char*)&byteordercheck,sizeof(byteordercheck));
+ hello << ';';
- // max 10 sec
- for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
+
ss.add_callback(new_connection,bind(&test_timeout::CommandTimeout::send_hello,
boost::ref(*this), hello.str(),&ss, _1));
- // don't call atexit and stuff
- _exit(0);
+ // max 10 sec
+ for (int i=0; i < 10; i++)
+ ss.fill_buffer(1000000);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ default:
+ // parent
+ {
+ string data;
- command_client cc(&sc,1000000,1000000);
- result_container rc;
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- string errormsg;
+ command_client cc(&sc,1000000,1000000);
+ result_container rc;
- try
- {
- cc.send_command(new testfunc2_cmd("hello"),rc);
- }
- catch(t2n_transfer_error &e)
- { errormsg=e.what(); }
- catch(...)
- { throw; }
+ string errormsg;
- CPPUNIT_ASSERT_EQUAL(string("timeout exceeded"),errormsg);
+ try
+ {
+ cc.send_command(new testfunc2_cmd("hello"),rc);
}
+ catch(t2n_transfer_error &e)
+ { errormsg=e.what(); }
+ catch(...)
+ { throw; }
+
+ BOOST_CHECK_EQUAL(string("timeout exceeded"),errormsg);
}
}
+}
- void CommandSlowResponse()
+BOOST_AUTO_TEST_CASE(CommandSlowResponse)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- socket_server ss("./socket");
+ socket_server ss("./socket");
- ostringstream hello;
- hello << "T2Nv" << PROTOCOL_VERSION << ';';
- int byteordercheck=1;
- hello.write((char*)&byteordercheck,sizeof(byteordercheck));
- hello << ';';
+ ostringstream hello;
+ hello << "T2Nv" << PROTOCOL_VERSION << ';';
+ int byteordercheck=1;
+ hello.write((char*)&byteordercheck,sizeof(byteordercheck));
+ hello << ';';
-
ss.add_callback(new_connection,bind(&test_timeout::send_hello,
boost::ref(*this), hello.str(),&ss, _1));
+
ss.add_callback(new_connection,bind(&test_timeout::CommandSlowResponse::send_hello,
boost::ref(*this), hello.str(),&ss, _1));
- // max 10 sec
- for (int i=0; i < 10; i++)
- {
- ss.fill_buffer(1000000);
+ // max 10 sec
+ for (int i=0; i < 10; i++)
+ {
+ ss.fill_buffer(1000000);
- string data;
- unsigned int cid;
-
- if(ss.get_packet(data,cid))
- {
- // create a valid packet & send
- string response="abcdefghijklmnopqrstuvwxyz";
- packet_size_indicator psize=htonl(response.size());
- std::string send_data(response);
-
send_data.insert(0,(char*)&psize,sizeof(packet_size_indicator));
- send_slow_raw_socket(send_data,&ss,cid);
- }
+ string data;
+ unsigned int cid;
+
+ if(ss.get_packet(data,cid))
+ {
+ // create a valid packet & send
+ string response="abcdefghijklmnopqrstuvwxyz";
+ packet_size_indicator psize=htonl(response.size());
+ std::string send_data(response);
+
send_data.insert(0,(char*)&psize,sizeof(packet_size_indicator));
+ send_slow_raw_socket(send_data,&ss,cid);
}
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
}
-
- // don't call atexit and stuff
- _exit(0);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ default:
+ // parent
+ {
+ string data;
- command_client cc(&sc,1000000,1000000);
- result_container rc;
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- string errormsg;
+ command_client cc(&sc,1000000,1000000);
+ result_container rc;
- try
- {
- cc.send_command(new testfunc2_cmd("hello"),rc);
- }
- catch(t2n_transfer_error &e)
- { errormsg=e.what(); }
- catch(...)
- { throw; }
+ string errormsg;
- CPPUNIT_ASSERT_EQUAL(string("timeout exceeded"),errormsg);
+ try
+ {
+ cc.send_command(new testfunc2_cmd("hello"),rc);
}
+ catch(t2n_transfer_error &e)
+ { errormsg=e.what(); }
+ catch(...)
+ { throw; }
+
+ BOOST_CHECK_EQUAL(string("timeout exceeded"),errormsg);
}
}
+}
- void DisconnectOnWrite()
+BOOST_AUTO_TEST_CASE(DisconnectOnWrite)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- socket_server ss("./socket");
-
- // bail out as soon as we get something
- ss.fill_buffer(-1);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
+ socket_server ss("./socket");
- // don't call atexit and stuff
- _exit(0);
+ // bail out as soon as we get something
+ ss.fill_buffer(-1);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // don't kill us on broken pipe
- signal(SIGPIPE, SIG_IGN);
+ default:
+ // parent
+ {
+ string data;
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ // don't kill us on broken pipe
+ signal(SIGPIPE, SIG_IGN);
- string errormsg;
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- string huge(5000000,'x');
+ string errormsg;
- try
- {
- sc.write(huge);
- }
- catch(t2n_transfer_error &e)
- { errormsg=e.what(); }
- catch(...)
- { throw; }
+ string huge(5000000,'x');
- CPPUNIT_ASSERT_EQUAL(string("write() returned Broken
pipe"),errormsg);
+ try
+ {
+ sc.write(huge);
}
+ catch(t2n_transfer_error &e)
+ { errormsg=e.what(); }
+ catch(...)
+ { throw; }
+
+ BOOST_CHECK_EQUAL(string("write() returned Broken pipe"),errormsg);
}
}
+}
- void WriteTwice()
+BOOST_AUTO_TEST_CASE(WriteTwice)
+{
+ switch(child_pid=fork())
{
- switch(child_pid=fork())
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- socket_server ss("./socket");
-
- // bail out as soon as we get something
- ss.fill_buffer(-1);
- ss.fill_buffer(-1);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
+ socket_server ss("./socket");
- // don't call atexit and stuff
- _exit(0);
+ // bail out as soon as we get something
+ ss.fill_buffer(-1);
+ ss.fill_buffer(-1);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string data;
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // don't kill us on broken pipe
- signal(SIGPIPE, SIG_IGN);
+ default:
+ // parent
+ {
+ string data;
- // wait till server is up
- sleep(1);
- socket_client_connection sc("./socket");
+ // don't kill us on broken pipe
+ signal(SIGPIPE, SIG_IGN);
- string errormsg;
+ // wait till server is up
+ sleep(1);
+ socket_client_connection sc("./socket");
- sc.write("somedata");
+ string errormsg;
- sleep(1);
+ sc.write("somedata");
- // server should disconnect now
- try
- {
- sc.write("other data");
- }
- catch(t2n_transfer_error &e)
- { errormsg=e.what(); }
- catch(...)
- { throw; }
+ sleep(1);
- CPPUNIT_ASSERT_EQUAL(string("write() returned Broken
pipe"),errormsg);
+ // server should disconnect now
+ try
+ {
+ sc.write("other data(2)");
+ sleep(1);
+ sc.write("other data(3)");
}
+ catch(t2n_transfer_error &e)
+ { errormsg=e.what(); }
+ catch(...)
+ { throw; }
+
+ BOOST_CHECK_EQUAL(string("write() returned Broken pipe"),errormsg);
}
}
+}
- void DisconnectOnRead()
- {
- pid_t pid2;
+BOOST_AUTO_TEST_CASE(DisconnectOnRead)
+{
+ pid_t pid2;
- switch(child_pid=fork())
+ switch(child_pid=fork())
+ {
+ case -1:
+ {
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
{
- case -1:
+ try
{
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ // wait till server is up
+ sleep(1);
+
+ socket_client_connection sc("./socket");
+
+ // this is an evil hack to get access to real_write, don't
ever do this in an app!!!
+ real_write_client_connection
*rwc=(real_write_client_connection*)≻
+ rwc->real_write(string(10000,'x'));
+ } catch(...)
{
- try
- {
- // wait till server is up
- sleep(1);
+ std::cerr << "exception in child. ignoring\n";
+ }
- socket_client_connection sc("./socket");
+ // don't call atexit and stuff
+ _exit(0);
+ }
- // this is an evil hack to get access to real_write, don't
ever do this in an app!!!
- real_write_client_connection
*rwc=(real_write_client_connection*)≻
- rwc->real_write(string(10000,'x'));
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
+ default:
+ // parent
+ {
+ // don't kill us on broken pipe
+ signal(SIGPIPE, SIG_IGN);
- // don't call atexit and stuff
- _exit(0);
- }
+ socket_server ss("./socket");
+
+ time_t t0 = time(NULL);
- default:
- // parent
+ // max 5 sec
+ while (time(NULL) < t0 + 5 )
{
- // don't kill us on broken pipe
- signal(SIGPIPE, SIG_IGN);
+ ss.fill_buffer(1000000);
- socket_server ss("./socket");
+ string data;
+ ss.get_packet(data);
+ }
- time_t t0 = time(NULL);
+ // are we still alive and able to process data?
- // max 5 sec
- while (time(NULL) < t0 + 5 )
+ switch(pid2=fork())
+ {
+ case -1:
{
- ss.fill_buffer(1000000);
-
- string data;
- ss.get_packet(data);
+ BOOST_FAIL("fork error");
+ break;
}
-
- // are we still alive and able to process data?
-
- switch(pid2=fork())
+ case 0:
+ // child
{
- case -1:
+ try
{
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ socket_client_connection *sc=new
socket_client_connection("./socket");
+ sc->write(string(10000,'x'));
+ // socket is closed regularly
+ delete sc;
+ } catch(...)
{
- try
- {
- socket_client_connection *sc=new
socket_client_connection("./socket");
- sc->write(string(10000,'x'));
- // socket is closed regularly
- delete sc;
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't run regular cleanup, otherwise cppunit stuff
gets called
- _exit(0);
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string received;
+ // don't run regular cleanup, otherwise cppunit stuff gets
called
+ _exit(0);
+ }
- t0 = time(NULL);
+ default:
+ // parent
+ {
+ string received;
- // max 10 sec
- while (time(NULL) < t0 + 10 )
- {
- ss.fill_buffer(1000000);
+ t0 = time(NULL);
- if (ss.get_packet(received))
- break;
- }
+ // max 10 sec
+ while (time(NULL) < t0 + 10 )
+ {
+ ss.fill_buffer(1000000);
- CPPUNIT_ASSERT_EQUAL(string(10000,'x'),received);
+ if (ss.get_packet(received))
+ break;
}
+
+ BOOST_CHECK_EQUAL(string(10000,'x'),received);
}
}
}
- kill(pid2,SIGKILL);
}
+ kill(pid2,SIGKILL);
+}
- void BreakAccept()
- {
- pid_t pid2;
+BOOST_AUTO_TEST_CASE(BreakAccept)
+{
+ pid_t pid2;
- switch(child_pid=fork())
+ switch(child_pid=fork())
+ {
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- // wait till server is really up and waiting
- sleep(2);
+ // wait till server is really up and waiting
+ sleep(2);
- // connect with very tight timeout and only 1 retry
- socket_client_connection sc("./socket",50,1);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't call atexit and stuff
- _exit(0);
+ // connect with very tight timeout and only 1 retry
+ socket_client_connection sc("./socket",50,1);
+ } catch(...)
+ {
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- // don't kill us on broken pipe
- signal(SIGPIPE, SIG_IGN);
+ // don't call atexit and stuff
+ _exit(0);
+ }
- socket_server ss("./socket");
+ default:
+ // parent
+ {
+ // don't kill us on broken pipe
+ signal(SIGPIPE, SIG_IGN);
- // server is "working" while client wants to connect
- sleep(5);
+ socket_server ss("./socket");
- time_t t0 = time(NULL);
+ // server is "working" while client wants to connect
+ sleep(5);
- // max 5 sec
- while (time(NULL) < t0 + 5 )
- {
- ss.fill_buffer(1000000);
+ time_t t0 = time(NULL);
- string data;
- ss.get_packet(data);
- }
+ // max 5 sec
+ while (time(NULL) < t0 + 5 )
+ {
+ ss.fill_buffer(1000000);
- // are we still alive and able to process data?
+ string data;
+ ss.get_packet(data);
+ }
- switch(pid2=fork())
+ // are we still alive and able to process data?
+
+ switch(pid2=fork())
+ {
+ case -1:
{
- case -1:
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ socket_client_connection *sc=new
socket_client_connection("./socket");
+ sc->write(string(10000,'x'));
+ delete sc;
+ // socket is closed regularly
+ } catch(...)
{
- try
- {
- socket_client_connection *sc=new
socket_client_connection("./socket");
- sc->write(string(10000,'x'));
- delete sc;
- // socket is closed regularly
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
-
- // don't run regular cleanup, otherwise cppunit stuff
gets called
- _exit(0);
+ std::cerr << "exception in child. ignoring\n";
}
- default:
- // parent
- {
- string received;
+ // don't run regular cleanup, otherwise cppunit stuff gets
called
+ _exit(0);
+ }
- t0 = time(NULL);
+ default:
+ // parent
+ {
+ string received;
- // max 10 sec
- while (time(NULL) < t0 + 10 )
- {
- ss.fill_buffer(1000000);
+ t0 = time(NULL);
- if (ss.get_packet(received))
- break;
- }
+ // max 10 sec
+ while (time(NULL) < t0 + 10 )
+ {
+ ss.fill_buffer(1000000);
- CPPUNIT_ASSERT_EQUAL(string(10000,'x'),received);
+ if (ss.get_packet(received))
+ break;
}
+
+ BOOST_CHECK_EQUAL(string(10000,'x'),received);
}
}
}
- kill(pid2,SIGKILL);
}
-};
+ kill(pid2,SIGKILL);
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_timeout);
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/wrapper.cpp b/test/wrapper.cpp
index 49041d8..e4bffb6 100644
--- a/test/wrapper.cpp
+++ b/test/wrapper.cpp
@@ -30,9 +30,8 @@ on this file might be covered by the GNU General Public
License.
#include <sstream>
#include <stdexcept>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <cppunit/ui/text/TestRunner.h>
-#include <cppunit/extensions/HelperMacros.h>
+#define BOOST_TEST_DYN_LINK
+#include <boost/test/unit_test.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
@@ -49,13 +48,14 @@ on this file might be covered by the GNU General Public
License.
#include <client_wrapper.hxx>
#include <socket_wrapper.hxx>
+#include "test_fixtures.hxx"
+
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
using namespace std;
using namespace libt2n;
-using namespace CppUnit;
// the server part
@@ -238,26 +238,11 @@ std::auto_ptr<wraptype> wraptype::SingletonObject =
std::auto_ptr<wraptype>();
template<>
std::auto_ptr<ConnectionWrapper> wraptype::WrappedConnection =
std::auto_ptr<ConnectionWrapper>();
-class test_wrapper : public TestFixture
-{
- CPPUNIT_TEST_SUITE(test_wrapper);
-
- CPPUNIT_TEST(no_init_exception); // must be called first!!!
- CPPUNIT_TEST(simple_wrap);
- CPPUNIT_TEST(double_use);
- CPPUNIT_TEST(double_use_with_close);
- CPPUNIT_TEST(reconnect_after_close);
- CPPUNIT_TEST(reconnect_not_possible);
- CPPUNIT_TEST(ignore_server_disconnect);
- CPPUNIT_TEST(ignore_handler_reconnects);
-
- CPPUNIT_TEST_SUITE_END();
-
- public:
-
- pid_t child_pid;
- void setUp()
+class test_wrapperFixture : public KillChildOnShutdownFixture
+{
+public:
+ test_wrapperFixture()
{
close_server=false;
kill_server=false;
@@ -266,7 +251,7 @@ class test_wrapper : public TestFixture
{
case -1:
{
- CPPUNIT_FAIL("fork error");
+ BOOST_FAIL("fork error");
break;
}
case 0:
@@ -299,319 +284,302 @@ class test_wrapper : public TestFixture
default:
// parent
{
+ // don't kill us on broken pipe
+ signal(SIGPIPE, SIG_IGN);
+
// wait till server is up
sleep(1);
-
}
}
}
- void tearDown()
+ ~test_wrapperFixture()
{
- // make sure the server-child is dead before the next test runs
- kill(child_pid,SIGKILL);
- sleep(1);
}
+};
- void no_init_exception()
- {
-
CPPUNIT_ASSERT_THROW(t2n_exec(&cmd_group_x_client::serverfunc)(1),std::logic_error);
- }
+BOOST_FIXTURE_TEST_SUITE(test_wrapper, test_wrapperFixture)
- void simple_wrap()
- {
- wraptype::set_connection(auto_ptr<ConnectionWrapper>
- (new BasicSocketWrapper("./socket")));
+BOOST_AUTO_TEST_CASE(no_init_exception) // must be called first!
+{
+
BOOST_REQUIRE_THROW(t2n_exec(&cmd_group_x_client::serverfunc)(1),std::logic_error);
+}
- int i=t2n_exec(&cmd_group_x_client::serverfunc)(1);
+BOOST_AUTO_TEST_CASE(simple_wrap)
+{
+ wraptype::set_connection(auto_ptr<ConnectionWrapper>
+ (new BasicSocketWrapper("./socket")));
- CPPUNIT_ASSERT_EQUAL(2,i);
- }
+ int i=t2n_exec(&cmd_group_x_client::serverfunc)(1);
- void double_use()
- {
- // only one connection used?
- wraptype::set_connection(auto_ptr<ConnectionWrapper>
- (new BasicSocketWrapper("./socket")));
+ BOOST_CHECK_EQUAL(2,i);
+}
- t2n_exec(&cmd_group_x_client::serverfunc)(17);
- string out=t2n_exec(&cmd_group_x_client::getserverlog)();
+BOOST_AUTO_TEST_CASE(double_use)
+{
+ // only one connection used?
+ wraptype::set_connection(auto_ptr<ConnectionWrapper>
+ (new BasicSocketWrapper("./socket")));
- // count the number of times that "new connection accepted" appears in
the server log
- string::size_type p=0;
- int cnt=0;
- while ((p=out.find("new connection accepted",p))++ != string::npos)
- cnt++;
+ t2n_exec(&cmd_group_x_client::serverfunc)(17);
+ string out=t2n_exec(&cmd_group_x_client::getserverlog)();
- CPPUNIT_ASSERT_EQUAL(1,cnt);
- }
+ // count the number of times that "new connection accepted" appears in the
server log
+ string::size_type p=0;
+ int cnt=0;
+ while ((p=out.find("new connection accepted",p))++ != string::npos)
+ cnt++;
- void double_use_with_close()
- {
- wraptype::set_connection(auto_ptr<ConnectionWrapper>
- (new BasicSocketWrapper("./socket")));
+ BOOST_CHECK_EQUAL(1,cnt);
+}
- t2n_exec(&cmd_group_x_client::serverfunc)(17);
+BOOST_AUTO_TEST_CASE(double_use_with_close)
+{
+ wraptype::set_connection(auto_ptr<ConnectionWrapper>
+ (new BasicSocketWrapper("./socket")));
- // closes the connection from the client side
- wraptype::set_connection(auto_ptr<ConnectionWrapper>
- (new BasicSocketWrapper("./socket")));
+ t2n_exec(&cmd_group_x_client::serverfunc)(17);
- string out=t2n_exec(&cmd_group_x_client::getserverlog)();
+ // closes the connection from the client side
+ wraptype::set_connection(auto_ptr<ConnectionWrapper>
+ (new BasicSocketWrapper("./socket")));
- // count the number of times that "new connection accepted" appears in
the server log
- string::size_type p=0;
- int cnt=0;
- while ((p=out.find("new connection accepted",p))++ != string::npos)
- cnt++;
+ string out=t2n_exec(&cmd_group_x_client::getserverlog)();
- CPPUNIT_ASSERT_EQUAL(2,cnt);
- }
+ // count the number of times that "new connection accepted" appears in the
server log
+ string::size_type p=0;
+ int cnt=0;
+ while ((p=out.find("new connection accepted",p))++ != string::npos)
+ cnt++;
- void reconnect_after_close()
- {
- wraptype::set_connection(auto_ptr<ConnectionWrapper>
- (new ReconnectSocketWrapper("./socket")));
+ BOOST_CHECK_EQUAL(2,cnt);
+}
- wraptype::get_connection_wrapper()->set_command_timeout_usec(3000000);
- wraptype::get_connection_wrapper()->set_hello_timeout_usec(3000000);
+BOOST_AUTO_TEST_CASE(reconnect_after_close)
+{
+ wraptype::set_connection(auto_ptr<ConnectionWrapper>
+ (new ReconnectSocketWrapper("./socket")));
- // 42 closes connection on the server side
- t2n_exec(&cmd_group_x_client::serverfunc)(42);
+ wraptype::get_connection_wrapper()->set_command_timeout_usec(3000000);
+ wraptype::get_connection_wrapper()->set_hello_timeout_usec(3000000);
- string out=t2n_exec(&cmd_group_x_client::getserverlog)();
+ // 42 closes connection on the server side
+ t2n_exec(&cmd_group_x_client::serverfunc)(42);
- // count the number of times that "new connection accepted" appears in
the server log
- string::size_type p=0;
- int cnt=0;
- while ((p=out.find("new connection accepted",p))++ != string::npos)
- cnt++;
+ string out=t2n_exec(&cmd_group_x_client::getserverlog)();
- CPPUNIT_ASSERT_EQUAL(2,cnt);
- }
+ // count the number of times that "new connection accepted" appears in the
server log
+ string::size_type p=0;
+ int cnt=0;
+ while ((p=out.find("new connection accepted",p))++ != string::npos)
+ cnt++;
- void reconnect_not_possible()
- {
- wraptype::set_connection(auto_ptr<ConnectionWrapper>
- (new ReconnectSocketWrapper("./socket")));
+ BOOST_CHECK_EQUAL(2,cnt);
+}
- // the server doens't like the beast
- t2n_exec(&cmd_group_x_client::serverfunc)(666);
+BOOST_AUTO_TEST_CASE(reconnect_not_possible)
+{
+ wraptype::set_connection(auto_ptr<ConnectionWrapper>
+ (new ReconnectSocketWrapper("./socket")));
-
CPPUNIT_ASSERT_THROW(t2n_exec(&cmd_group_x_client::serverfunc)(1),t2n_communication_error);
- }
+ // the server doens't like the beast
+ t2n_exec(&cmd_group_x_client::serverfunc)(666);
- void ignore_server_disconnect()
- {
- wraptype::set_connection(auto_ptr<ConnectionWrapper>
- (new ReconnectIgnoreFailureSocketWrapper("./socket")));
+
BOOST_REQUIRE_THROW(t2n_exec(&cmd_group_x_client::serverfunc)(1),t2n_communication_error);
+}
- // the server doens't like the beast
- t2n_exec(&cmd_group_x_client::serverfunc)(666);
+BOOST_AUTO_TEST_CASE(ignore_server_disconnect)
+{
+ wraptype::set_connection(auto_ptr<ConnectionWrapper>
+ (new ReconnectIgnoreFailureSocketWrapper("./socket")));
- int i=t2n_exec(&cmd_group_x_client::serverfunc)(1);
+ // the server doens't like the beast
+ t2n_exec(&cmd_group_x_client::serverfunc)(666);
- // result is constructed with default constructor on error-and-ignore
-> i=0
+ int i=t2n_exec(&cmd_group_x_client::serverfunc)(1);
- CPPUNIT_ASSERT_EQUAL(0,i);
- }
+ // result is constructed with default constructor on error-and-ignore ->
i=0
- void ignore_handler_reconnects()
- {
- wraptype::set_connection(auto_ptr<ConnectionWrapper>
- (new ReconnectIgnoreFailureSocketWrapper("./socket")));
+ BOOST_CHECK_EQUAL(0,i);
+}
- wraptype::get_connection_wrapper()->set_command_timeout_usec(3000000);
- wraptype::get_connection_wrapper()->set_hello_timeout_usec(3000000);
+BOOST_AUTO_TEST_CASE(ignore_handler_reconnects)
+{
+ wraptype::set_connection(auto_ptr<ConnectionWrapper>
+ (new ReconnectIgnoreFailureSocketWrapper("./socket")));
- // 42 closes connection on the server side
- t2n_exec(&cmd_group_x_client::serverfunc)(42);
+ wraptype::get_connection_wrapper()->set_command_timeout_usec(3000000);
+ wraptype::get_connection_wrapper()->set_hello_timeout_usec(3000000);
- string out=t2n_exec(&cmd_group_x_client::getserverlog)();
+ // 42 closes connection on the server side
+ t2n_exec(&cmd_group_x_client::serverfunc)(42);
- // count the number of times that "new connection accepted" appears in
the server log
- string::size_type p=0;
- int cnt=0;
- while ((p=out.find("new connection accepted",p))++ != string::npos)
- cnt++;
+ string out=t2n_exec(&cmd_group_x_client::getserverlog)();
- CPPUNIT_ASSERT_EQUAL(2,cnt);
- }
+ // count the number of times that "new connection accepted" appears in the
server log
+ string::size_type p=0;
+ int cnt=0;
+ while ((p=out.find("new connection accepted",p))++ != string::npos)
+ cnt++;
-};
+ BOOST_CHECK_EQUAL(2,cnt);
+}
+BOOST_AUTO_TEST_SUITE_END()
-CPPUNIT_TEST_SUITE_REGISTRATION(test_wrapper);
-class test_wrapper_noserver : public TestFixture
+class test_wrapper_noserverFixture : public KillChildOnShutdownFixture
{
- CPPUNIT_TEST_SUITE(test_wrapper_noserver);
-
- CPPUNIT_TEST(ignore_noserver);
- CPPUNIT_TEST(ignore_finds_lateserver);
- CPPUNIT_TEST(ignore_wrongserver);
-
- CPPUNIT_TEST_SUITE_END();
-
- public:
-
- pid_t child_pid;
-
- void setUp()
+protected:
+ void send_hello(string hello_string, socket_server* ss, int conn_id)
{
- child_pid=0;
+ server_connection *sc=ss->get_connection(conn_id);
+ sc->write(hello_string);
}
- void tearDown()
+public:
+ test_wrapper_noserverFixture()
{
- // make sure the server-child is dead before the next test runs
- if (child_pid != 0)
- {
- kill(child_pid,SIGKILL);
- sleep(1);
- }
}
- void ignore_noserver()
+ ~test_wrapper_noserverFixture()
{
- wraptype::set_connection(auto_ptr<ConnectionWrapper>
- (new ReconnectIgnoreFailureSocketWrapper("./socket")));
+ }
+};
- // wraptype::get_connection_wrapper()->set_logging(&cerr,debug);
+BOOST_FIXTURE_TEST_SUITE(test_wrapper_noserver, test_wrapper_noserverFixture)
- // there is no server
+BOOST_AUTO_TEST_CASE(ignore_noserver)
+{
+ wraptype::set_connection(auto_ptr<ConnectionWrapper>
+ (new ReconnectIgnoreFailureSocketWrapper("./socket")));
- int i=t2n_exec(&cmd_group_x_client::serverfunc)(1);
+ // wraptype::get_connection_wrapper()->set_logging(&cerr,debug);
- // result is constructed with default constructor on error-and-ignore
-> i=0
+ // there is no server
- CPPUNIT_ASSERT_EQUAL(0,i);
- }
+ int i=t2n_exec(&cmd_group_x_client::serverfunc)(1);
- void ignore_finds_lateserver()
- {
- wraptype::set_connection(auto_ptr<ConnectionWrapper>
- (new ReconnectIgnoreFailureSocketWrapper("./socket")));
+ // result is constructed with default constructor on error-and-ignore ->
i=0
- // there is no server
- t2n_exec(&cmd_group_x_client::serverfunc)(1);
+ BOOST_CHECK_EQUAL(0,i);
+}
- // launch a server
- close_server=false;
- kill_server=false;
+BOOST_AUTO_TEST_CASE(ignore_finds_lateserver)
+{
+ wraptype::set_connection(auto_ptr<ConnectionWrapper>
+ (new ReconnectIgnoreFailureSocketWrapper("./socket")));
- switch(child_pid=fork())
+ // there is no server
+ t2n_exec(&cmd_group_x_client::serverfunc)(1);
+
+ // launch a server
+ close_server=false;
+ kill_server=false;
+
+ switch(child_pid=fork())
+ {
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
+ int i=0;
+ while(i < 10 && !kill_server)
{
- int i=0;
- while(i < 10 && !kill_server)
- {
- close_server=false;
+ close_server=false;
- socket_server ss("./socket");
- group_command_server<cmd_group_x> cs(ss);
- ss.set_logging(&logstream,debug);
+ socket_server ss("./socket");
+ group_command_server<cmd_group_x> cs(ss);
+ ss.set_logging(&logstream,debug);
- // max 10 sec
- for (; !close_server && !kill_server && i < 10; i++)
- cs.handle(1000000);
- }
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
+ // max 10 sec
+ for (; !close_server && !kill_server && i < 10; i++)
+ cs.handle(1000000);
}
-
- // don't call atexit and stuff
- _exit(0);
- }
-
- default:
- // parent
+ } catch(...)
{
- // wait till server is up
- sleep(1);
+ std::cerr << "exception in child. ignoring\n";
}
- }
- // server should be active
- int i=t2n_exec(&cmd_group_x_client::serverfunc)(1);
+ // don't call atexit and stuff
+ _exit(0);
+ }
- CPPUNIT_ASSERT_EQUAL(2,i);
+ default:
+ // parent
+ {
+ // wait till server is up
+ sleep(1);
+ }
}
- void send_hello(string hello_string, socket_server* ss, int conn_id)
- {
- server_connection *sc=ss->get_connection(conn_id);
- sc->write(hello_string);
- }
+ // server should be active
+ int i=t2n_exec(&cmd_group_x_client::serverfunc)(1);
- void ignore_wrongserver()
- {
- wraptype::set_connection(auto_ptr<ConnectionWrapper>
- (new ReconnectIgnoreFailureSocketWrapper("./socket")));
+ BOOST_CHECK_EQUAL(2,i);
+}
- // launch a server
+BOOST_AUTO_TEST_CASE(ignore_wrongserver)
+{
+ wraptype::set_connection(auto_ptr<ConnectionWrapper>
+ (new ReconnectIgnoreFailureSocketWrapper("./socket")));
- switch(child_pid=fork())
+ // launch a server
+
+ switch(child_pid=fork())
+ {
+ case -1:
{
- case -1:
- {
- CPPUNIT_FAIL("fork error");
- break;
- }
- case 0:
- // child
+ BOOST_FAIL("fork error");
+ break;
+ }
+ case 0:
+ // child
+ {
+ try
{
- try
- {
- socket_server ss("./socket");
+ socket_server ss("./socket");
- // server sends garbage
+ // server sends garbage
- ostringstream hello;
- hello << "XYZ 123";
-
-
ss.add_callback(new_connection,bind(&test_wrapper_noserver::send_hello,
boost::ref(*this), hello.str(),&ss, _1));
-
- // max 10 sec
- for (int i=0; i < 10; i++)
- ss.fill_buffer(1000000);
- } catch(...)
- {
- std::cerr << "exception in child. ignoring\n";
- }
+ ostringstream hello;
+ hello << "XYZ 123";
- // don't call atexit and stuff
- _exit(0);
- }
+
ss.add_callback(new_connection,bind(&test_wrapper_noserver::ignore_wrongserver::send_hello,
boost::ref(*this), hello.str(),&ss, _1));
- default:
- // parent
+ // max 10 sec
+ for (int i=0; i < 10; i++)
+ ss.fill_buffer(1000000);
+ } catch(...)
{
- // wait till server is up
- sleep(1);
+ std::cerr << "exception in child. ignoring\n";
}
- }
- // there is no valid server
+ // don't call atexit and stuff
+ _exit(0);
+ }
- int i=t2n_exec(&cmd_group_x_client::serverfunc)(1);
+ default:
+ // parent
+ {
+ // wait till server is up
+ sleep(1);
+ }
+ }
- // result is constructed with default constructor on error-and-ignore
-> i=0
+ // there is no valid server
- CPPUNIT_ASSERT_EQUAL(0,i);
- }
+ int i=t2n_exec(&cmd_group_x_client::serverfunc)(1);
+ // result is constructed with default constructor on error-and-ignore ->
i=0
-};
+ BOOST_CHECK_EQUAL(0,i);
+}
-CPPUNIT_TEST_SUITE_REGISTRATION(test_wrapper_noserver);
+BOOST_AUTO_TEST_SUITE_END()
hooks/post-receive
--
C++ inter-process communication library
--
libt2n-git - see http://www.intra2net.com/en/developer/libt2n for details.
To unsubscribe send a mail to libt2n-git+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
|