X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=test%2Fnewserver.cpp;fp=test%2Fnewserver.cpp;h=32f4d966e53ced56e55c0cd3843aefbf74be44b4;hp=bce1213d4da3fad3cff13a93e66b41bbcf13f08c;hb=307b5e74c506b609d5c407be0943f45255ab5122;hpb=3d9c0861e86edcbfad10b84da332093fd6438f32 diff --git a/test/newserver.cpp b/test/newserver.cpp index bce1213..32f4d96 100644 --- a/test/newserver.cpp +++ b/test/newserver.cpp @@ -30,9 +30,9 @@ on this file might be covered by the GNU General Public License. #include #include -#include -#include -#include +#define BOOST_TEST_MAIN +#define BOOST_TEST_DYN_LINK +#include #include #include @@ -46,12 +46,12 @@ on this file might be covered by the GNU General Public License. #include #include +#include "test_fixtures.hxx" + using namespace std; -using namespace CppUnit; int newserver_func(int i) { - return 1; } @@ -119,117 +119,96 @@ BOOST_CLASS_EXPORT(newserver_res) using namespace libt2n; -class test_newserver : public TestFixture -{ - CPPUNIT_TEST_SUITE(test_newserver); - - CPPUNIT_TEST(NewServerSocket); - - CPPUNIT_TEST_SUITE_END(); - - pid_t child_pid; - - public: - - void setUp() - { } - - void tearDown() - { - // make sure the server-child is dead before the next test runs - kill(child_pid,SIGKILL); - sleep(1); - } +BOOST_FIXTURE_TEST_SUITE(test_newserver, KillChildOnShutdownFixture) - void NewServerSocket() +BOOST_AUTO_TEST_CASE(NewServerSocket) +{ + switch(child_pid=fork()) { - switch(child_pid=fork()) + case -1: { - case -1: - { - CPPUNIT_FAIL("fork error"); - break; - } - case 0: - // child + BOOST_FAIL("fork error"); + break; + } + case 0: + // child + { + try { - try - { - { - socket_server ss("./socket"); - // ss.set_logging(&cerr,debug); - command_server cs(ss); - - // handle new connection and just one command - cs.handle(10000000); - cs.handle(10000000); - } - - sleep(1); - - // close socket, create new one - { - socket_server ss("./socket"); - // ss.set_logging(&cerr,debug); - command_server cs(ss); - - // max 30 sec - for (int i=0; i < 30; i++) - cs.handle(1000000); - } - } catch(...) { - std::cerr << "exception in child. ignoring\n"; + socket_server ss("./socket"); + // ss.set_logging(&cerr,debug); + command_server cs(ss); + + // handle new connection and just one command + cs.handle(10000000); + cs.handle(10000000); } - // don't call atexit and stuff - _exit(0); - } + sleep(1); + + // close socket, create new one + { + socket_server ss("./socket"); + // ss.set_logging(&cerr,debug); + command_server cs(ss); - default: - // parent + // max 30 sec + for (int i=0; i < 30; i++) + cs.handle(1000000); + } + } catch(...) { - // don't kill us on broken pipe - signal(SIGPIPE, SIG_IGN); + std::cerr << "exception in child. ignoring\n"; + } - // wait till server is up - sleep(1); - socket_client_connection sc("./socket"); - sc.set_logging(&cerr,debug); - command_client cc(&sc); + // don't call atexit and stuff + _exit(0); + } - result_container rc; - cc.send_command(new newserver_cmd(1),rc); + default: + // parent + { + // don't kill us on broken pipe + signal(SIGPIPE, SIG_IGN); - // very short sleep to make sure new server socket is up - sleep(1); + // wait till server is up + sleep(1); + socket_client_connection sc("./socket"); + sc.set_logging(&cerr,debug); + command_client cc(&sc); - // still has connection to the old server-socket - string errormsg; + result_container rc; + cc.send_command(new newserver_cmd(1),rc); - try - { - sc.write("some stuff"); - } - catch(t2n_transfer_error &e) - { errormsg=e.what(); } - catch(...) - { throw; } + // very short sleep to make sure new server socket is up + sleep(1); - bool test_fine=false; - if (errormsg == "write() returned Bad file descriptor" - || errormsg == "write() returned Broken pipe") - test_fine = true; + // still has connection to the old server-socket + string errormsg; - if (!test_fine) - { - std::cerr << "NewServerSocket() test failed. ignoring as the test is very fragile.\n"; - } + try + { + sc.write("some stuff"); + } + catch(t2n_transfer_error &e) + { errormsg=e.what(); } + catch(...) + { throw; } - CPPUNIT_ASSERT_EQUAL(1, 1); + bool test_fine=false; + if (errormsg == "write() returned Bad file descriptor" + || errormsg == "write() returned Broken pipe") + test_fine = true; + + if (!test_fine) + { + std::cerr << "NewServerSocket() test failed. ignoring as the test is very fragile.\n"; } + + BOOST_CHECK_EQUAL(1, 1); } } -}; +} -CPPUNIT_TEST_SUITE_REGISTRATION(test_newserver); +BOOST_AUTO_TEST_SUITE_END()