Migrate from cppunit to Boost.test
[libt2n] / test / timeout.cpp
index 509d88d..3434c0b 100644 (file)
@@ -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*)&sc;
+                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*)&sc;
-                    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()