*/
/** @file
*
- * (c) Copyright 2007-2009 by Intra2net AG
+ * (c) Copyright 2007-2010 by Intra2net AG
*/
//#define NOISEDEBUG
#include <iomanip>
#include <vector>
-#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <cppunit/ui/text/TestRunner.h>
-#include <cppunit/extensions/HelperMacros.h>
-
#include <async_io.hpp>
#include <async_pipe.hpp>
#include <async_process.hpp>
#include <async_socket.hpp>
#include <asyncio_system_tools.hpp>
#include <asyncio_containerfunc.hpp>
+
#include <boost/signal.hpp>
#include <boost/bind.hpp>
#include <boost/random.hpp>
+#define BOOST_TEST_MAIN
+#define BOOST_TEST_DYN_LINK
+#include <boost/test/unit_test.hpp>
#ifdef NOISEDEBUG
#define DOUT(msg) std::cout << msg << std::endl
using namespace I2n;
using namespace AsyncIo;
-
-using namespace CppUnit;
-
namespace {
} // eo namespace <anonymous>
-
-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<std::string> used_check_files;
- Backend *backend;
- std::set<std::string> used_check_files;
-
-
- template<class Callable>
- bool backendLoopUntil( Callable condition, int maxLoops=100 )
+ template<class Callable>
+ 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<std::string>::iterator it= used_check_files.begin();
+ it != used_check_files.end();
+ ++it)
{
- for(std::set<std::string>::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<std::string, std::vector >()("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<std::string, std::vector >()("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<std::string, std::vector >()
- ("-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<std::string, std::vector >()
+ ("-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()