From 436fb1445d6bed8690d7e8e2fe146249d9d7afa5 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Tue, 2 Feb 2010 20:52:42 +0100 Subject: [PATCH] Migrate from cppunit to boost::test --- configure.in | 6 +- libasyncio.spec.in | 1 + m4macros/ax_boost_unit_test_framework.m4 | 131 ++++ unittest/Makefile.am | 6 +- unittest/test.cpp | 100 --- unittest/test_simpleio_basics.cpp | 1057 ++++++++++++++---------------- 6 files changed, 641 insertions(+), 660 deletions(-) create mode 100644 m4macros/ax_boost_unit_test_framework.m4 delete mode 100644 unittest/test.cpp diff --git a/configure.in b/configure.in index 688c9ff..38207bc 100644 --- a/configure.in +++ b/configure.in @@ -47,13 +47,15 @@ PKG_CHECK_MODULES(LIBI2NCOMMON, libi2ncommon, ]) AM_CONDITIONAL([HAVE_LIBI2NCOMMON],[test x$have_i2ncommon = xyes]) -AM_PATH_CPPUNIT(1.8.0) - AX_BOOST_BASE([1.34]) AX_BOOST_SIGNALS +AX_BOOST_UNIT_TEST_FRAMEWORK if test "x$BOOST_SIGNALS_LIB" = "x"; then AC_MSG_ERROR([Sorry, we need the Signals-Lib from Boost.]) fi +if test "x$BOOST_UNIT_TEST_FRAMEWORK_LIB" = "x"; then + AC_MSG_ERROR([Sorry, we need the unit test framework from Boost.]) +fi LIBT2N_CHECK(libt2n,[ have_libt2n=yes diff --git a/libasyncio.spec.in b/libasyncio.spec.in index 5ecd4af..acfe250 100644 --- a/libasyncio.spec.in +++ b/libasyncio.spec.in @@ -92,6 +92,7 @@ for dir in utils asyncio; do make -C $dir headerlist done +export BOOST_TEST_LOG_LEVEL=test_suite make check %install diff --git a/m4macros/ax_boost_unit_test_framework.m4 b/m4macros/ax_boost_unit_test_framework.m4 new file mode 100644 index 0000000..5333da3 --- /dev/null +++ b/m4macros/ax_boost_unit_test_framework.m4 @@ -0,0 +1,131 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/ax_boost_unit_test_framework.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_BOOST_UNIT_TEST_FRAMEWORK +# +# DESCRIPTION +# +# Test for Unit_Test_Framework library from the Boost C++ libraries. The +# macro requires a preceding call to AX_BOOST_BASE. Further documentation +# is available at . +# +# This macro calls: +# +# AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB) +# +# And sets: +# +# HAVE_BOOST_UNIT_TEST_FRAMEWORK +# +# LICENSE +# +# Copyright (c) 2008 Thomas Porschberg +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. + +AC_DEFUN([AX_BOOST_UNIT_TEST_FRAMEWORK], +[ + AC_ARG_WITH([boost-unit-test-framework], + AS_HELP_STRING([--with-boost-unit-test-framework@<:@=special-lib@:>@], + [use the Unit_Test_Framework library from boost - it is possible to specify a certain library for the linker + e.g. --with-boost-unit-test-framework=boost_unit_test_framework-gcc ]), + [ + if test "$withval" = "no"; then + want_boost="no" + elif test "$withval" = "yes"; then + want_boost="yes" + ax_boost_user_unit_test_framework_lib="" + else + want_boost="yes" + ax_boost_user_unit_test_framework_lib="$withval" + fi + ], + [want_boost="yes"] + ) + + if test "x$want_boost" = "xyes"; then + AC_REQUIRE([AC_PROG_CC]) + CPPFLAGS_SAVED="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" + export CPPFLAGS + + LDFLAGS_SAVED="$LDFLAGS" + LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" + export LDFLAGS + + AC_CACHE_CHECK(whether the Boost::Unit_Test_Framework library is available, + ax_cv_boost_unit_test_framework, + [AC_LANG_PUSH([C++]) + AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include ]], + [[using boost::unit_test::test_suite; + test_suite* test= BOOST_TEST_SUITE( "Unit test example 1" ); return 0;]]), + ax_cv_boost_unit_test_framework=yes, ax_cv_boost_unit_test_framework=no) + AC_LANG_POP([C++]) + ]) + if test "x$ax_cv_boost_unit_test_framework" = "xyes"; then + AC_DEFINE(HAVE_BOOST_UNIT_TEST_FRAMEWORK,,[define if the Boost::Unit_Test_Framework library is available]) + BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` + + if test "x$ax_boost_user_unit_test_framework_lib" = "x"; then + saved_ldflags="${LDFLAGS}" + for monitor_library in `ls $BOOSTLIBDIR/libboost_unit_test_framework*.{so,a}* 2>/dev/null` ; do + if test -r $monitor_library ; then + libextension=`echo $monitor_library | sed 's,.*/,,' | sed -e 's;^lib\(boost_unit_test_framework.*\)\.so.*$;\1;' -e 's;^lib\(boost_unit_test_framework.*\)\.a*$;\1;'` + ax_lib=${libextension} + link_unit_test_framework="yes" + else + link_unit_test_framework="no" + fi + + if test "x$link_unit_test_framework" = "xyes"; then + BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib" + AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB) + break + fi + done + if test "x$link_unit_test_framework" != "xyes"; then + for libextension in `ls $BOOSTLIBDIR/boost_unit_test_framework*.{dll,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_unit_test_framework.*\)\.dll.*$;\1;' -e 's;^\(boost_unit_test_framework.*\)\.a*$;\1;'` ; do + ax_lib=${libextension} + AC_CHECK_LIB($ax_lib, exit, + [BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib"; AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB) link_unit_test_framework="yes"; break], + [link_unit_test_framework="no"]) + done + fi + else + link_unit_test_framework="no" + saved_ldflags="${LDFLAGS}" + for ax_lib in boost_unit_test_framework-$ax_boost_user_unit_test_framework_lib $ax_boost_user_unit_test_framework_lib ; do + if test "x$link_unit_test_framework" = "xyes"; then + break; + fi + for unittest_library in `ls $BOOSTLIBDIR/lib${ax_lib}.{so,a}* 2>/dev/null` ; do + if test -r $unittest_library ; then + libextension=`echo $unittest_library | sed 's,.*/,,' | sed -e 's;^lib\(boost_unit_test_framework.*\)\.so.*$;\1;' -e 's;^lib\(boost_unit_test_framework.*\)\.a*$;\1;'` + ax_lib=${libextension} + link_unit_test_framework="yes" + else + link_unit_test_framework="no" + fi + + if test "x$link_unit_test_framework" = "xyes"; then + BOOST_UNIT_TEST_FRAMEWORK_LIB="-l$ax_lib" + AC_SUBST(BOOST_UNIT_TEST_FRAMEWORK_LIB) + break + fi + done + done + fi + if test "x$link_unit_test_framework" != "xyes"; then + AC_MSG_ERROR(Could not link against $ax_lib !) + fi + fi + + CPPFLAGS="$CPPFLAGS_SAVED" + LDFLAGS="$LDFLAGS_SAVED" + fi +]) diff --git a/unittest/Makefile.am b/unittest/Makefile.am index 00320f0..d52328f 100644 --- a/unittest/Makefile.am +++ b/unittest/Makefile.am @@ -1,9 +1,9 @@ INCLUDES = -I$(top_srcdir)/. -I$(top_srcdir)/asyncio -I$(top_srcdir)/utils \ - @BOOST_CPPFLAGS@ @CPPUNIT_CFLAGS@ @LIBI2NCOMMON_CFLAGS@ + @BOOST_CPPFLAGS@ @LIBI2NCOMMON_CFLAGS@ METASOURCES = AUTO check_PROGRAMS = testsimpleio -testsimpleio_SOURCES = test.cpp test_simpleio_basics.cpp +testsimpleio_SOURCES = test_simpleio_basics.cpp testsimpleio_LDADD = $(top_builddir)/utils/libasyncio_utils.la \ - $(top_builddir)/asyncio/libasyncio.la @BOOST_LDFLAGS@ @BOOST_SIGNALS_LIB@ @CPPUNIT_LIBS@ @LIBI2NCOMMON_LIBS@ + $(top_builddir)/asyncio/libasyncio.la @BOOST_LDFLAGS@ @BOOST_SIGNALS_LIB@ @BOOST_UNIT_TEST_FRAMEWORK_LIB@ @LIBI2NCOMMON_LIBS@ TESTS = testsimpleio diff --git a/unittest/test.cpp b/unittest/test.cpp deleted file mode 100644 index f434fa7..0000000 --- a/unittest/test.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* -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. - -Copyright (c) 2004 by Intra2net AG -*/ - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - -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(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/unittest/test_simpleio_basics.cpp b/unittest/test_simpleio_basics.cpp index 51549bb..c964eb6 100644 --- a/unittest/test_simpleio_basics.cpp +++ b/unittest/test_simpleio_basics.cpp @@ -19,7 +19,7 @@ on this file might be covered by the GNU General Public License. */ /** @file * - * (c) Copyright 2007-2009 by Intra2net AG + * (c) Copyright 2007-2010 by Intra2net AG */ //#define NOISEDEBUG @@ -29,10 +29,6 @@ on this file might be covered by the GNU General Public License. #include #include -#include -#include -#include - #include #include #include @@ -41,10 +37,14 @@ on this file might be covered by the GNU General Public License. #include #include #include + #include #include #include +#define BOOST_TEST_MAIN +#define BOOST_TEST_DYN_LINK +#include #ifdef NOISEDEBUG #define DOUT(msg) std::cout << msg << std::endl @@ -56,9 +56,6 @@ on this file might be covered by the GNU General Public License. using namespace I2n; using namespace AsyncIo; - -using namespace CppUnit; - namespace { @@ -318,713 +315,663 @@ std::string makeRandomAsciiString(std::string::size_type len) } // eo namespace - -class TestSimpleioBasics : public TestFixture +class SimpleioBasicsFixture { - CPPUNIT_TEST_SUITE(TestSimpleioBasics); - - CPPUNIT_TEST(EmptyBackendStepCall); - CPPUNIT_TEST(NonEmptyBackendStepCall); - CPPUNIT_TEST(SingleTimerShot); - CPPUNIT_TEST(SimpleTimerShot); - CPPUNIT_TEST(SimpleTimerShot2); - - CPPUNIT_TEST(EmptyWantTest); - CPPUNIT_TEST(SimplePipeTest); - CPPUNIT_TEST(SimplePipePump); - - CPPUNIT_TEST(SimpleProcessTestBinTrue); - CPPUNIT_TEST(SimpleProcessTestBinFalse); - CPPUNIT_TEST(SimpleProcessTestEcho); - CPPUNIT_TEST(SimpleProcessTestStderr); - CPPUNIT_TEST(SignaledProcessTermination); - - - CPPUNIT_TEST(CallOut1); - CPPUNIT_TEST(CallOut2); - CPPUNIT_TEST(RemoveCallOut1); - - CPPUNIT_TEST(FrozenCall_Thaw); - CPPUNIT_TEST(FrozenCall_Decay); - - - CPPUNIT_TEST(UnixSockets_ClientServer); - - - //CPPUNIT_TEST(Dummy); - CPPUNIT_TEST_SUITE_END(); - - protected: +protected: + Backend *backend; + std::set used_check_files; - Backend *backend; - std::set used_check_files; - - - template - bool backendLoopUntil( Callable condition, int maxLoops=100 ) + template + bool backendLoopUntil( Callable condition, int maxLoops=100 ) + { + for (int i=std::max(maxLoops,1); i-->0 && ! condition();) { - for (int i=std::max(maxLoops,1); i-->0 && ! condition();) - { - backend->doOneStep(10); - } - return condition(); - } // eo backendLoopUntil + backend->doOneStep(10); + } + return condition(); + } // eo backendLoopUntil - bool backendStep(int msTimeout= 10, int count=1) + bool backendStep(int msTimeout= 10, int count=1) + { + bool res= true; + for(;count-->0 && res;) { - bool res= true; - for(;count-->0 && res;) - { - res= backend->doOneStep(msTimeout); - } - return res; - } // eo backendStep + res= backend->doOneStep(msTimeout); + } + return res; + } // eo backendStep - std::string getCheckFilepath(std::string tag) - { - std::string result; - result= "__unittest__" + tag + ".dat"; - used_check_files.insert(result); - return result; - } // eo get_check_file_path + std::string getCheckFilepath(std::string tag) + { + std::string result; + result= "__unittest__" + tag + ".dat"; + used_check_files.insert(result); + return result; + } // eo get_check_file_path - void removeCheckFiles() + void removeCheckFiles() + { + for(std::set::iterator it= used_check_files.begin(); + it != used_check_files.end(); + ++it) { - for(std::set::iterator it= used_check_files.begin(); - it != used_check_files.end(); - ++it) + std::string filepath(*it); + if (Utils::FileStat(filepath)) { - std::string filepath(*it); - if (Utils::FileStat(filepath)) - { - Utils::unlink(filepath); - } + Utils::unlink(filepath); } - used_check_files.clear(); - } // eo removeCheckFiles - - - - public: - - void setUp() - { - backend = Backend::getBackend(); - installChildHandler(); - used_check_files.clear(); - } // eo setUp - + } + used_check_files.clear(); + } // eo removeCheckFiles - void tearDown() - { - restoreChildHandler(); - removeCheckFiles(); - } // eo tearDown +public: + SimpleioBasicsFixture() + { + backend = Backend::getBackend(); + installChildHandler(); + used_check_files.clear(); + } + ~SimpleioBasicsFixture() + { + restoreChildHandler(); + removeCheckFiles(); + } +}; - /* - * the tests: - */ +BOOST_FIXTURE_TEST_SUITE(TestSimpleioBasics, SimpleioBasicsFixture) +BOOST_AUTO_TEST_CASE(EmptyBackendStepCall) +{ + BOOST_REQUIRE( backend ); - /* - ** basics: - */ + // a backend call without active objects should return false: + bool result = backend->doOneStep(0); + BOOST_CHECK_EQUAL( false, result ); +} // eo EmptyBackendStepCall - void EmptyBackendStepCall() - { - CPPUNIT_ASSERT( backend ); - // a backend call without active objects should return false: - bool result = backend->doOneStep(0); - CPPUNIT_ASSERT_EQUAL( false, result ); - } // eo EmptyBackendStepCall +BOOST_AUTO_TEST_CASE(NonEmptyBackendStepCall) +{ + BOOST_REQUIRE(backend); + { + TestTimer timer; + timer.setDelta(10); + // with an active object, a step should return true: + bool result = backend->doOneStep(0); + BOOST_CHECK_EQUAL( true, result ); + // the timer should not be executed: + BOOST_CHECK_EQUAL( 0u, timer.m_counter ); + } + // now it should return false: + bool result = backend->doOneStep(0); + BOOST_CHECK_EQUAL( false, result ); +} // eo NonEmptyBackendStepCall - void NonEmptyBackendStepCall() - { - CPPUNIT_ASSERT(backend); - - { - TestTimer timer; - timer.setDelta(10); - // with an active object, a step should return true: - bool result = backend->doOneStep(0); - CPPUNIT_ASSERT_EQUAL( true, result ); - // the timer should not be executed: - CPPUNIT_ASSERT_EQUAL( 0u, timer.m_counter ); - } - // now it should return false: - bool result = backend->doOneStep(0); - CPPUNIT_ASSERT_EQUAL( false, result ); - } // eo NonEmptyBackendStepCall +/** + * check for timer to execute immediatly. + */ +BOOST_AUTO_TEST_CASE(SingleTimerShot) +{ + BOOST_REQUIRE(backend); + TestTimer timer; + timer.setDelta(0); // shot now! - /** - * check for timer to execute immediatly. - */ - void SingleTimerShot() - { - CPPUNIT_ASSERT(backend); + bool result = backend->doOneStep(10); - TestTimer timer; - timer.setDelta(0); // shot now! + BOOST_CHECK_EQUAL( true, result ); + // the timer should be executed once: + BOOST_CHECK_EQUAL( 1u, timer.m_counter ); - bool result = backend->doOneStep(10); + result = backend->doOneStep(0); - CPPUNIT_ASSERT_EQUAL( true, result ); - // the timer should be executed once: - CPPUNIT_ASSERT_EQUAL( 1u, timer.m_counter ); + BOOST_CHECK_EQUAL( false, result ); + // the timer should not be executed again: + BOOST_CHECK_EQUAL( 1u, timer.m_counter ); - result = backend->doOneStep(0); +} // eo SingleTimerShot() - CPPUNIT_ASSERT_EQUAL( false, result ); - // the timer should not be executed again: - CPPUNIT_ASSERT_EQUAL( 1u, timer.m_counter ); - } // eo SingleTimerShot() +/** + * tests a simple timer class to be executed with a timeout. + */ +BOOST_AUTO_TEST_CASE(SimpleTimerShot) +{ + bool res; + BOOST_REQUIRE(backend); + SimpleTimer timer1; + Counter counter1; + timer1.addAction( boost::bind(&Counter::advance,&counter1) ); + BOOST_CHECK_EQUAL(false, timer1.active()); - /** - * tests a simple timer class to be executed with a timeout. - */ - void SimpleTimerShot() - { - bool res; - CPPUNIT_ASSERT(backend); + timer1.startTimerMS( 100 ); + BOOST_CHECK_EQUAL(true, timer1.active()); - SimpleTimer timer1; - Counter counter1; - timer1.addAction( boost::bind(&Counter::advance,&counter1) ); - CPPUNIT_ASSERT_EQUAL(false, timer1.active()); + res=backend->doOneStep( 1000 ); + BOOST_CHECK_EQUAL( true, res ); - timer1.startTimerMS( 100 ); - CPPUNIT_ASSERT_EQUAL(true, timer1.active()); + BOOST_CHECK_EQUAL( 1, counter1.value ); +} // eo SimpleTimerShot - res=backend->doOneStep( 1000 ); - CPPUNIT_ASSERT_EQUAL( true, res ); - CPPUNIT_ASSERT_EQUAL( 1, counter1.value ); - } // eo SimpleTimerShot +/** + * tests 3 timers; after the first was active, disable another and check if the remaining one fires. + */ +BOOST_AUTO_TEST_CASE(SimpleTimerShot2) +{ + bool res; + BOOST_REQUIRE(backend); + SimpleTimer timer1, timer2, timer3; + Counter counter1, counter2, counter3; + timer1.addAction( boost::bind(&Counter::advance,&counter1) ); + timer2.addAction( boost::bind(&Counter::advance,&counter2) ); + timer3.addAction( boost::bind(&Counter::advance,&counter3) ); + BOOST_CHECK_EQUAL(false, timer1.active()); + BOOST_CHECK_EQUAL(false, timer2.active()); + BOOST_CHECK_EQUAL(false, timer3.active()); - /** - * tests 3 timers; after the first was active, disable another and check if the remaining one fires. - */ - void SimpleTimerShot2() - { - bool res; - CPPUNIT_ASSERT(backend); + timer1.startTimerMS( 100 ); + timer2.startTimerMS( 500 ); + timer3.startTimerMS( 400 ); + BOOST_CHECK_EQUAL(true, timer1.active()); + BOOST_CHECK_EQUAL(true, timer2.active()); + BOOST_CHECK_EQUAL(true, timer3.active()); - SimpleTimer timer1, timer2, timer3; - Counter counter1, counter2, counter3; - timer1.addAction( boost::bind(&Counter::advance,&counter1) ); - timer2.addAction( boost::bind(&Counter::advance,&counter2) ); - timer3.addAction( boost::bind(&Counter::advance,&counter3) ); - CPPUNIT_ASSERT_EQUAL(false, timer1.active()); - CPPUNIT_ASSERT_EQUAL(false, timer2.active()); - CPPUNIT_ASSERT_EQUAL(false, timer3.active()); + res=backend->doOneStep( 1000 ); + BOOST_CHECK_EQUAL( true, res ); - timer1.startTimerMS( 100 ); - timer2.startTimerMS( 500 ); - timer3.startTimerMS( 400 ); - CPPUNIT_ASSERT_EQUAL(true, timer1.active()); - CPPUNIT_ASSERT_EQUAL(true, timer2.active()); - CPPUNIT_ASSERT_EQUAL(true, timer3.active()); + BOOST_CHECK_EQUAL(false, timer1.active()); + BOOST_CHECK_EQUAL(true, timer2.active()); + BOOST_CHECK_EQUAL(true, timer3.active()); - res=backend->doOneStep( 1000 ); - CPPUNIT_ASSERT_EQUAL( true, res ); + BOOST_CHECK_EQUAL( 1, counter1.value ); + BOOST_CHECK_EQUAL( 0, counter2.value ); + BOOST_CHECK_EQUAL( 0, counter3.value ); - CPPUNIT_ASSERT_EQUAL(false, timer1.active()); - CPPUNIT_ASSERT_EQUAL(true, timer2.active()); - CPPUNIT_ASSERT_EQUAL(true, timer3.active()); + // now stop the next timer: + timer3.stopTimer(); + BOOST_CHECK_EQUAL(false, timer3.active()); - CPPUNIT_ASSERT_EQUAL( 1, counter1.value ); - CPPUNIT_ASSERT_EQUAL( 0, counter2.value ); - CPPUNIT_ASSERT_EQUAL( 0, counter3.value ); + res=backend->doOneStep( 1000 ); + BOOST_CHECK_EQUAL( true, res ); - // now stop the next timer: - timer3.stopTimer(); - CPPUNIT_ASSERT_EQUAL(false, timer3.active()); + BOOST_CHECK_EQUAL( 1, counter1.value ); + BOOST_CHECK_EQUAL( 1, counter2.value ); + BOOST_CHECK_EQUAL( 0, counter3.value ); +} // eo SimpleTimerShot2 - res=backend->doOneStep( 1000 ); - CPPUNIT_ASSERT_EQUAL( true, res ); - CPPUNIT_ASSERT_EQUAL( 1, counter1.value ); - CPPUNIT_ASSERT_EQUAL( 1, counter2.value ); - CPPUNIT_ASSERT_EQUAL( 0, counter3.value ); - } // eo SimpleTimerShot2 +/* +** I/O tests: +*/ +BOOST_AUTO_TEST_CASE(EmptyWantTest) +{ + IOImplementation io; - /* - ** I/O tests: - */ + BOOST_CHECK_EQUAL(false, io.wantRead() ); + BOOST_CHECK_EQUAL(false, io.wantWrite() ); +} // eo EmptyWantTest - void EmptyWantTest() - { - IOImplementation io; - - CPPUNIT_ASSERT_EQUAL(false, io.wantRead() ); - CPPUNIT_ASSERT_EQUAL(false, io.wantWrite() ); - } // eo EmptyWantTest - - - /** - * a simple pipe (and io) test. - * - * This test basically tests the io framework. - * It opens two connected pipes and sends a test string in each direction. - * It tests the following functionalities of the base classes: - * - set write marks in backend step (enabling direct send of data) - * - low send data - * - construct and interpret poll() data structures - * - receive data - * - signal chains for received data - * - eof detection - * . - * - */ - void SimplePipeTest() - { - static const std::string test_string("a test string"); - static const std::string test_string2("only another short test string"); - CPPUNIT_ASSERT(backend); +/** + * a simple pipe (and io) test. + * + * This test basically tests the io framework. + * It opens two connected pipes and sends a test string in each direction. + * It tests the following functionalities of the base classes: + * - set write marks in backend step (enabling direct send of data) + * - low send data + * - construct and interpret poll() data structures + * - receive data + * - signal chains for received data + * - eof detection + * . + * + */ +BOOST_AUTO_TEST_CASE(SimplePipeTest) +{ + static const std::string test_string("a test string"); + static const std::string test_string2("only another short test string"); - TestPipe pipe1, pipe2; + BOOST_REQUIRE(backend); - bool res= pipe1.makePipe(pipe2); + TestPipe pipe1, pipe2; - CPPUNIT_ASSERT_EQUAL(true, res); - CPPUNIT_ASSERT_EQUAL(true, pipe1.opened()); - CPPUNIT_ASSERT_EQUAL(true, pipe2.opened()); + bool res= pipe1.makePipe(pipe2); - res= backend->doOneStep(0); - CPPUNIT_ASSERT_EQUAL(true, res); + BOOST_CHECK_EQUAL(true, res); + BOOST_CHECK_EQUAL(true, pipe1.opened()); + BOOST_CHECK_EQUAL(true, pipe2.opened()); - pipe1.sendString(test_string); + res= backend->doOneStep(0); + BOOST_CHECK_EQUAL(true, res); - res= backend->doOneStep(0); - CPPUNIT_ASSERT_EQUAL(true, res); + pipe1.sendString(test_string); - CPPUNIT_ASSERT_EQUAL( test_string, pipe2.m_received_string ); + res= backend->doOneStep(0); + BOOST_CHECK_EQUAL(true, res); - pipe2.sendString(test_string2); + BOOST_CHECK_EQUAL( test_string, pipe2.m_received_string ); - res= backend->doOneStep(0); - CPPUNIT_ASSERT_EQUAL(true, res); + pipe2.sendString(test_string2); - CPPUNIT_ASSERT_EQUAL( test_string2, pipe1.m_received_string ); + res= backend->doOneStep(0); + BOOST_CHECK_EQUAL(true, res); - pipe1.close(); - CPPUNIT_ASSERT_EQUAL(false, pipe1.opened()); + BOOST_CHECK_EQUAL( test_string2, pipe1.m_received_string ); - res= backend->doOneStep(0); - CPPUNIT_ASSERT_EQUAL(true, res); + pipe1.close(); + BOOST_CHECK_EQUAL(false, pipe1.opened()); - CPPUNIT_ASSERT_EQUAL(true, pipe2.eof()); - } // eo SimplePipeTest + res= backend->doOneStep(0); + BOOST_CHECK_EQUAL(true, res); + BOOST_CHECK_EQUAL(true, pipe2.eof()); +} // eo SimplePipeTest - /** - * sends a larger data chunk through a pipe. - * This tests if sending and receiving data in (smaller internal) chunks works. - */ - void SimplePipePump() - { - CPPUNIT_ASSERT(backend); - TestPipe pipe1, pipe2; +/** + * sends a larger data chunk through a pipe. + * This tests if sending and receiving data in (smaller internal) chunks works. + */ +BOOST_AUTO_TEST_CASE(SimplePipePump) +{ + BOOST_REQUIRE(backend); - bool res= pipe1.makePipe(pipe2); + TestPipe pipe1, pipe2; - CPPUNIT_ASSERT_EQUAL(true, res); - CPPUNIT_ASSERT_EQUAL(true, pipe1.opened()); - CPPUNIT_ASSERT_EQUAL(true, pipe2.opened()); + bool res= pipe1.makePipe(pipe2); - res= backend->doOneStep(0); - CPPUNIT_ASSERT_EQUAL(true, res); + BOOST_CHECK_EQUAL(true, res); + BOOST_CHECK_EQUAL(true, pipe1.opened()); + BOOST_CHECK_EQUAL(true, pipe2.opened()); - std::string test_string= makeRandomAsciiString(256*1024); + res= backend->doOneStep(0); + BOOST_CHECK_EQUAL(true, res); - pipe1.sendString(test_string); + std::string test_string= makeRandomAsciiString(256*1024); - res= backend->doOneStep(0); - CPPUNIT_ASSERT_EQUAL(true, res); + pipe1.sendString(test_string); - // do some backend cycles to empty the pipe: - for (int i=64; i-->0 && res && !pipe1.empty(); ) - { - res= backend->doOneStep(100); - }; + res= backend->doOneStep(0); + BOOST_CHECK_EQUAL(true, res); - pipe1.close(); - CPPUNIT_ASSERT_EQUAL(false, pipe1.opened()); + // do some backend cycles to empty the pipe: + for (int i=64; i-->0 && res && !pipe1.empty(); ) + { + res= backend->doOneStep(100); + }; - // now read the remaining data until we recognize EOF: - for (int i=64; i-->0 && res && !pipe2.eof();) - { - res= backend->doOneStep(100); - } + pipe1.close(); + BOOST_CHECK_EQUAL(false, pipe1.opened()); - CPPUNIT_ASSERT_EQUAL( test_string.size(), pipe2.m_received_string.size() ); - CPPUNIT_ASSERT_EQUAL( test_string, pipe2.m_received_string ); + // now read the remaining data until we recognize EOF: + for (int i=64; i-->0 && res && !pipe2.eof();) + { + res= backend->doOneStep(100); + } - CPPUNIT_ASSERT_EQUAL(true, pipe2.eof()); - } // eo SimplePipePump + BOOST_CHECK_EQUAL( test_string.size(), pipe2.m_received_string.size() ); + BOOST_CHECK_EQUAL( test_string, pipe2.m_received_string ); + BOOST_CHECK_EQUAL(true, pipe2.eof()); +} // eo SimplePipePump - /** - * fork a subprocess (/bin/true) and test exit code. - */ - void SimpleProcessTestBinTrue() - { - bool res; - CPPUNIT_ASSERT(backend); - TestProcess proc("/bin/true"); +/** + * fork a subprocess (/bin/true) and test exit code. + */ +BOOST_AUTO_TEST_CASE(SimpleProcessTestBinTrue) +{ + bool res; + BOOST_REQUIRE(backend); - res= proc.startProcess(); - CPPUNIT_ASSERT_EQUAL(true, res); + TestProcess proc("/bin/true"); - res= backend->doOneStep(200); - CPPUNIT_ASSERT_EQUAL(true, res); + res= proc.startProcess(); + BOOST_CHECK_EQUAL(true, res); - for(int i=20; i-->0 && proc.processState() != ProcessState::stopped;) - { - backend->doOneStep(15); - } + res= backend->doOneStep(200); + BOOST_CHECK_EQUAL(true, res); - CPPUNIT_ASSERT_EQUAL( ProcessState(ProcessState::stopped), proc.processState() ); - CPPUNIT_ASSERT_EQUAL( true, proc.eof() ); - CPPUNIT_ASSERT_EQUAL( 0, proc.exitCode() ); - } // eo SimpleProcessTestBinTrue + for(int i=20; i-->0 && proc.processState() != ProcessState::stopped;) + { + backend->doOneStep(15); + } + BOOST_CHECK_EQUAL( ProcessState(ProcessState::stopped), proc.processState() ); + BOOST_CHECK_EQUAL( true, proc.eof() ); + BOOST_CHECK_EQUAL( 0, proc.exitCode() ); +} // eo SimpleProcessTestBinTrue - /** - * fork a subprocess (/bin/false) and test exit code. - */ - void SimpleProcessTestBinFalse() - { - bool res; - CPPUNIT_ASSERT(backend); - TestProcess proc("/bin/false"); +/** + * fork a subprocess (/bin/false) and test exit code. + */ +BOOST_AUTO_TEST_CASE(SimpleProcessTestBinFalse) +{ + bool res; + BOOST_REQUIRE(backend); - res= proc.startProcess(); - CPPUNIT_ASSERT_EQUAL(true, res); + TestProcess proc("/bin/false"); - res= backend->doOneStep(200); - CPPUNIT_ASSERT_EQUAL(true, res); - for(int i=20; i-->0 && proc.processState() != ProcessState::stopped;) - { - backend->doOneStep(15); - } + res= proc.startProcess(); + BOOST_CHECK_EQUAL(true, res); - CPPUNIT_ASSERT_EQUAL( ProcessState(ProcessState::stopped), proc.processState() ); - CPPUNIT_ASSERT_EQUAL( true, proc.eof() ); - CPPUNIT_ASSERT_EQUAL( 1, proc.exitCode() ); - DOUT("leave SimpleProcessTestBinFalse"); - } // eo SimpleProcessTestBinFalse + res= backend->doOneStep(200); + BOOST_CHECK_EQUAL(true, res); + for(int i=20; i-->0 && proc.processState() != ProcessState::stopped;) + { + backend->doOneStep(15); + } + BOOST_CHECK_EQUAL( ProcessState(ProcessState::stopped), proc.processState() ); + BOOST_CHECK_EQUAL( true, proc.eof() ); + BOOST_CHECK_EQUAL( 1, proc.exitCode() ); + DOUT("leave SimpleProcessTestBinFalse"); +} // eo SimpleProcessTestBinFalse - /** - * fork an echo subprocess and read back the output. - */ - void SimpleProcessTestEcho() - { - DOUT("enter SimpleProcessTestEcho"); - bool res; - CPPUNIT_ASSERT(backend); - TestProcess proc( - "/bin/echo", - TransientPushBackFiller()("Eine")("Zeichenkette") - ); +/** + * fork an echo subprocess and read back the output. + */ +BOOST_AUTO_TEST_CASE(SimpleProcessTestEcho) +{ + DOUT("enter SimpleProcessTestEcho"); + bool res; + BOOST_REQUIRE(backend); - res= proc.startProcess(); - CPPUNIT_ASSERT_EQUAL(true, res); + TestProcess proc( + "/bin/echo", + TransientPushBackFiller()("Eine")("Zeichenkette") + ); - res= backend->doOneStep(200); - CPPUNIT_ASSERT_EQUAL(true, res); - for(int i=20; i-->0 && (proc.processState()!= ProcessState::stopped || !proc.eof());) - { - backend->doOneStep(10); - } + res= proc.startProcess(); + BOOST_CHECK_EQUAL(true, res); - CPPUNIT_ASSERT_EQUAL( ProcessState(ProcessState::stopped), proc.processState() ); - CPPUNIT_ASSERT_EQUAL( true, proc.eof() ); - CPPUNIT_ASSERT_EQUAL( 0, proc.exitCode() ); - CPPUNIT_ASSERT_EQUAL( std::string("Eine Zeichenkette\n"), proc.m_received_string); - } // eo SimpleProcessTestEcho + res= backend->doOneStep(200); + BOOST_CHECK_EQUAL(true, res); + for(int i=20; i-->0 && (proc.processState()!= ProcessState::stopped || !proc.eof());) + { + backend->doOneStep(10); + } + BOOST_CHECK_EQUAL( ProcessState(ProcessState::stopped), proc.processState() ); + BOOST_CHECK_EQUAL( true, proc.eof() ); + BOOST_CHECK_EQUAL( 0, proc.exitCode() ); + BOOST_CHECK_EQUAL( std::string("Eine Zeichenkette\n"), proc.m_received_string); +} // eo SimpleProcessTestEcho - /** - * fork a bash subprocess, echo something on stderr and read back the output. - */ - void SimpleProcessTestStderr() - { - bool res; - CPPUNIT_ASSERT(backend); - - TestIO my_stderr; - - TestProcess proc( - "/bin/bash", - TransientPushBackFiller() - ("-c") - ("echo Eine Zeichenkette >&2") - ); - - // start with a seperate io object for stderr. - DOUT("## start process"); - res= proc.startProcess( &my_stderr ); - CPPUNIT_ASSERT_EQUAL(true, res); - CPPUNIT_ASSERT_EQUAL(true, my_stderr.opened()); - - DOUT("## do a backend step"); - res= backend->doOneStep(200); - CPPUNIT_ASSERT_EQUAL(true, res); - // wait until process stopped and both io's signal EOF (or until the loop ends ;-) ) - DOUT("## enter loop"); - for(int i=17; i-->0 && (proc.processState()!= ProcessState::stopped || !proc.eof() || !my_stderr.eof());) - { - DOUT("## round i=" << i); - backend->doOneStep(10); - } - DOUT("## loop left"); - CPPUNIT_ASSERT_EQUAL( ProcessState(ProcessState::stopped), proc.processState() ); - CPPUNIT_ASSERT_EQUAL( true, proc.eof() ); - CPPUNIT_ASSERT_EQUAL( true, my_stderr.eof() ); - CPPUNIT_ASSERT_EQUAL( 0, proc.exitCode() ); - CPPUNIT_ASSERT_EQUAL( std::string("Eine Zeichenkette\n"), my_stderr.m_received_string); - DOUT("leave Test SimpleProcessTestStderr"); - } // eo SimpleProcessTestStderr +/** + * fork a bash subprocess, echo something on stderr and read back the output. + */ +BOOST_AUTO_TEST_CASE(SimpleProcessTestStderr) +{ + bool res; + BOOST_REQUIRE(backend); + + TestIO my_stderr; + + TestProcess proc( + "/bin/bash", + TransientPushBackFiller() + ("-c") + ("echo Eine Zeichenkette >&2") + ); + + // start with a seperate io object for stderr. + DOUT("## start process"); + res= proc.startProcess( &my_stderr ); + BOOST_CHECK_EQUAL(true, res); + BOOST_CHECK_EQUAL(true, my_stderr.opened()); + + DOUT("## do a backend step"); + res= backend->doOneStep(200); + BOOST_CHECK_EQUAL(true, res); + // wait until process stopped and both io's signal EOF (or until the loop ends ;-) ) + DOUT("## enter loop"); + for(int i=17; i-->0 && (proc.processState()!= ProcessState::stopped || !proc.eof() || !my_stderr.eof());) + { + DOUT("## round i=" << i); + backend->doOneStep(10); + } + DOUT("## loop left"); + BOOST_CHECK_EQUAL( ProcessState(ProcessState::stopped), proc.processState() ); + BOOST_CHECK_EQUAL( true, proc.eof() ); + BOOST_CHECK_EQUAL( true, my_stderr.eof() ); + BOOST_CHECK_EQUAL( 0, proc.exitCode() ); + BOOST_CHECK_EQUAL( std::string("Eine Zeichenkette\n"), my_stderr.m_received_string); + DOUT("leave Test SimpleProcessTestStderr"); +} // eo SimpleProcessTestStderr - /** - * checks termination of process by signal and if the signal is returned. - */ - void SignaledProcessTermination() - { - bool res; - CPPUNIT_ASSERT(backend); - TestProcess proc("/bin/sleep","2"); - res= proc.startProcess(); - CPPUNIT_ASSERT_EQUAL(true, res); +/** + * checks termination of process by signal and if the signal is returned. + */ +BOOST_AUTO_TEST_CASE(SignaledProcessTermination) +{ + bool res; + BOOST_REQUIRE(backend); - res= backend->doOneStep(10); - CPPUNIT_ASSERT_EQUAL(true, res); - CPPUNIT_ASSERT_EQUAL( ProcessState(ProcessState::running), proc.processState() ); + TestProcess proc("/bin/sleep","2"); + res= proc.startProcess(); + BOOST_CHECK_EQUAL(true, res); - res= backend->doOneStep(50); + res= backend->doOneStep(10); + BOOST_CHECK_EQUAL(true, res); + BOOST_CHECK_EQUAL( ProcessState(ProcessState::running), proc.processState() ); - // now send the process an USR1 (which terminates the process) - res=proc.kill( Signal::USR1 ); - CPPUNIT_ASSERT_EQUAL(true, res); + res= backend->doOneStep(50); - // give the backend a chance to process the termination event: - for(int i=30; i-->0 && proc.processState()!=ProcessState::stopped;) backend->doOneStep(10); + // now send the process an USR1 (which terminates the process) + res=proc.kill( Signal::USR1 ); + BOOST_CHECK_EQUAL(true, res); - CPPUNIT_ASSERT_EQUAL( ProcessState(ProcessState::stopped), proc.processState() ); - CPPUNIT_ASSERT_EQUAL( true, proc.eof() ); - CPPUNIT_ASSERT_EQUAL( Signal::USR1 , proc.exitCode()>>8 ); - } // eo SignaledProcessTermination + // give the backend a chance to process the termination event: + for(int i=30; i-->0 && proc.processState()!=ProcessState::stopped;) backend->doOneStep(10); + BOOST_CHECK_EQUAL( ProcessState(ProcessState::stopped), proc.processState() ); + BOOST_CHECK_EQUAL( true, proc.eof() ); + BOOST_CHECK_EQUAL( Signal::USR1 , proc.exitCode()>>8 ); +} // eo SignaledProcessTermination - void CallOut1() - { - Counter count; - callOut( boost::bind(&Counter::advance, &count), 1 ); - backend->doOneStep( 10 ); +BOOST_AUTO_TEST_CASE(CallOut1) +{ + Counter count; - CPPUNIT_ASSERT_EQUAL( 0, count.value ); - backend->doOneStep( 1100 ); + callOut( boost::bind(&Counter::advance, &count), 1 ); + backend->doOneStep( 10 ); - CPPUNIT_ASSERT_EQUAL( 1, count.value ); - } // eo CallOut1() + BOOST_CHECK_EQUAL( 0, count.value ); + backend->doOneStep( 1100 ); + BOOST_CHECK_EQUAL( 1, count.value ); +} // eo CallOut1() - void CallOut2() - { - Counter count; - callOut( boost::bind(&Counter::advance, &count), 0.5 ); - backend->doOneStep( 10 ); +BOOST_AUTO_TEST_CASE(CallOut2) +{ + Counter count; - CPPUNIT_ASSERT_EQUAL( 0, count.value ); - backend->doOneStep( 800 ); + callOut( boost::bind(&Counter::advance, &count), 0.5 ); + backend->doOneStep( 10 ); - CPPUNIT_ASSERT_EQUAL( 1, count.value ); - } // eo CallOut2() + BOOST_CHECK_EQUAL( 0, count.value ); + backend->doOneStep( 800 ); + BOOST_CHECK_EQUAL( 1, count.value ); +} // eo CallOut2() - void RemoveCallOut1() - { - Counter count; - CallOutId id= callOut( boost::bind(&Counter::advance, &count), 1 ); - backend->doOneStep( 10 ); +BOOST_AUTO_TEST_CASE(RemoveCallOut1) +{ + Counter count; - CPPUNIT_ASSERT_EQUAL( 0, count.value ); - bool res1 = removeCallOut(id); - bool res2 = removeCallOut(id); + CallOutId id= callOut( boost::bind(&Counter::advance, &count), 1 ); + backend->doOneStep( 10 ); - CPPUNIT_ASSERT_EQUAL( true, res1 ); - CPPUNIT_ASSERT_EQUAL( false, res2 ); + BOOST_CHECK_EQUAL( 0, count.value ); + bool res1 = removeCallOut(id); + bool res2 = removeCallOut(id); - backend->doOneStep( 1100 ); + BOOST_CHECK_EQUAL( true, res1 ); + BOOST_CHECK_EQUAL( false, res2 ); - CPPUNIT_ASSERT_EQUAL( 0, count.value ); - } // eo RemoveCallOut1() + backend->doOneStep( 1100 ); + BOOST_CHECK_EQUAL( 0, count.value ); +} // eo RemoveCallOut1() - void FrozenCall_Thaw() - { - Counter count; - CallOutId id= frozenCall( boost::bind(&Counter::advance, &count), 1 ); - backend->doOneStep( 10 ); +BOOST_AUTO_TEST_CASE(FrozenCall_Thaw) +{ + Counter count; - CPPUNIT_ASSERT_EQUAL( 0, count.value ); - id.thaw(); + CallOutId id= frozenCall( boost::bind(&Counter::advance, &count), 1 ); + backend->doOneStep( 10 ); - backend->doOneStep( 1100 ); + BOOST_CHECK_EQUAL( 0, count.value ); + id.thaw(); - CPPUNIT_ASSERT_EQUAL( 1, count.value ); - } // eo FrozenCall_Thaw() + backend->doOneStep( 1100 ); + BOOST_CHECK_EQUAL( 1, count.value ); +} // eo FrozenCall_Thaw() - void FrozenCall_Decay() - { - Counter count; - CallOutId id= frozenCall( boost::bind(&Counter::advance, &count), 1 ); - backend->doOneStep( 10 ); +BOOST_AUTO_TEST_CASE(FrozenCall_Decay) +{ + Counter count; - CPPUNIT_ASSERT_EQUAL( 0, count.value ); - CPPUNIT_ASSERT_EQUAL( true, id.active() ); - backend->doOneStep( 1100 ); + CallOutId id= frozenCall( boost::bind(&Counter::advance, &count), 1 ); + backend->doOneStep( 10 ); - CPPUNIT_ASSERT_EQUAL( 0, count.value ); - CPPUNIT_ASSERT_EQUAL( false, id.active() ); - } // eo FrozenCall_Decay() + BOOST_CHECK_EQUAL( 0, count.value ); + BOOST_CHECK_EQUAL( true, id.active() ); + backend->doOneStep( 1100 ); + BOOST_CHECK_EQUAL( 0, count.value ); + BOOST_CHECK_EQUAL( false, id.active() ); +} // eo FrozenCall_Decay() - void UnixSockets_ClientServer() - { - std::string path= getCheckFilepath("UDS_CS"); - UnixIOSocketHolder server_holder; - UnixServerSocket< TestUnixIOSocket > server_port; - UnixIOSocketPtr server; - TestUnixIOSocket client0; - TestUnixIOSocket client1; +BOOST_AUTO_TEST_CASE(UnixSockets_ClientServer) +{ + std::string path= getCheckFilepath("UDS_CS"); - bool res1 = server_port.open(path, 0600); - CPPUNIT_ASSERT_EQUAL( true, res1 ); + UnixIOSocketHolder server_holder; + UnixServerSocket< TestUnixIOSocket > server_port; + UnixIOSocketPtr server; + TestUnixIOSocket client0; + TestUnixIOSocket client1; - { - AsyncIo::Utils::FileStat stat(path,false); - CPPUNIT_ASSERT( stat.is_socket() ); - CPPUNIT_ASSERT_EQUAL( 0600u, (stat.mode() & 0777)); - } + bool res1 = server_port.open(path, 0600); + BOOST_CHECK_EQUAL( true, res1 ); - server_port.setNewConnectionCallback( - boost::bind( &UnixIOSocketHolder::store, &server_holder, _1) - ); - - // open a first client - bool res2= client0.open(path); - CPPUNIT_ASSERT_EQUAL( true, res2 ); - - CPPUNIT_ASSERT_EQUAL(0u, server_holder.size() ); - backendStep(5,1); - CPPUNIT_ASSERT_EQUAL(1u, server_holder.size() ); - CPPUNIT_ASSERT( server_holder.get(0).get() ); - - client0.sendData("a simple test string."); - backendStep(3,2); - - CPPUNIT_ASSERT_EQUAL( - std::string("a simple test string."), - server_holder.get(0)->m_received_string - ); - server_holder.get(0)->sendData("reply 1"); - backendStep(3,2); - CPPUNIT_ASSERT_EQUAL( std::string("reply 1"), client0.m_received_string ); - - // open a second client - res2= client1.open(path); - CPPUNIT_ASSERT_EQUAL( true, res2 ); - backendStep(5,1); - CPPUNIT_ASSERT_EQUAL(2u, server_holder.size() ); - CPPUNIT_ASSERT( server_holder.get(1).get() ); - - server_holder.get(1)->sendData("::reply 2"); - backendStep(3,2); - CPPUNIT_ASSERT_EQUAL( std::string("::reply 2"), client1.m_received_string ); - - client1.sendData("another simple test string. 124"); - backendStep(3,2); - - CPPUNIT_ASSERT_EQUAL( - std::string("another simple test string. 124"), - server_holder.get(1)->m_received_string - ); - - // close first client - client0.close(); - CPPUNIT_ASSERT_EQUAL( false, server_holder.get(0)->eof() ); - backendStep(3,2); - CPPUNIT_ASSERT_EQUAL( true, server_holder.get(0)->eof() ); - server_holder.get(0)->close(); - - // close second connection from server side - CPPUNIT_ASSERT_EQUAL( false, client1.eof() ); - server_holder.get(1)->close(); - backendStep(3,2); - CPPUNIT_ASSERT_EQUAL( true, client1.eof() ); - client1.close(); - } // eo UnixSockets_ClientServer() - - - void Dummy() - { - using namespace std; - cout << endl << "Random strings:" << endl; - for (int i=10; i-->0;) - { - cout << " " << makeRandomAsciiString(70)<< endl; - } - } // eo Dummy + { + AsyncIo::Utils::FileStat stat(path,false); + BOOST_REQUIRE( stat.is_socket() ); + BOOST_CHECK_EQUAL( 0600u, (stat.mode() & 0777)); + } + server_port.setNewConnectionCallback( + boost::bind( &UnixIOSocketHolder::store, &server_holder, _1) + ); + + // open a first client + bool res2= client0.open(path); + BOOST_CHECK_EQUAL( true, res2 ); + + BOOST_CHECK_EQUAL(0u, server_holder.size() ); + backendStep(5,1); + BOOST_CHECK_EQUAL(1u, server_holder.size() ); + BOOST_REQUIRE( server_holder.get(0).get() ); + + client0.sendData("a simple test string."); + backendStep(3,2); + + BOOST_CHECK_EQUAL( + std::string("a simple test string."), + server_holder.get(0)->m_received_string + ); + server_holder.get(0)->sendData("reply 1"); + backendStep(3,2); + BOOST_CHECK_EQUAL( std::string("reply 1"), client0.m_received_string ); + + // open a second client + res2= client1.open(path); + BOOST_CHECK_EQUAL( true, res2 ); + backendStep(5,1); + BOOST_CHECK_EQUAL(2u, server_holder.size() ); + BOOST_REQUIRE( server_holder.get(1).get() ); + + server_holder.get(1)->sendData("::reply 2"); + backendStep(3,2); + BOOST_CHECK_EQUAL( std::string("::reply 2"), client1.m_received_string ); + + client1.sendData("another simple test string. 124"); + backendStep(3,2); + + BOOST_CHECK_EQUAL( + std::string("another simple test string. 124"), + server_holder.get(1)->m_received_string + ); + + // close first client + client0.close(); + BOOST_CHECK_EQUAL( false, server_holder.get(0)->eof() ); + backendStep(3,2); + BOOST_CHECK_EQUAL( true, server_holder.get(0)->eof() ); + server_holder.get(0)->close(); + + // close second connection from server side + BOOST_CHECK_EQUAL( false, client1.eof() ); + server_holder.get(1)->close(); + backendStep(3,2); + BOOST_CHECK_EQUAL( true, client1.eof() ); + client1.close(); +} // eo UnixSockets_ClientServer() -}; // eo class TestSimpleioBasics +/* +BOOST_AUTO_TEST_CASE(Dummy) +{ + using namespace std; + cout << endl << "Random strings:" << endl; + for (int i=10; i-->0;) + { + cout << " " << makeRandomAsciiString(70)<< endl; + } +} // eo Dummy +*/ -CPPUNIT_TEST_SUITE_REGISTRATION(TestSimpleioBasics); +BOOST_AUTO_TEST_SUITE_END() -- 1.7.1