X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=test%2Fserialize.cpp;h=598ac4b1bce95913bb207b6588c093efa0ce0fc9;hp=634c01ae0b3c385b9f05ac1c3a621496327691a7;hb=307b5e74c506b609d5c407be0943f45255ab5122;hpb=3d9c0861e86edcbfad10b84da332093fd6438f32 diff --git a/test/serialize.cpp b/test/serialize.cpp index 634c01a..598ac4b 100644 --- a/test/serialize.cpp +++ b/test/serialize.cpp @@ -30,9 +30,10 @@ on this file might be covered by the GNU General Public License. #include #include -#include -#include -#include +#include "test_fixtures.hxx" + +#define BOOST_TEST_DYN_LINK +#include #include #include @@ -47,7 +48,6 @@ on this file might be covered by the GNU General Public License. #include using namespace std; -using namespace CppUnit; string testfunc3(const string& str) { @@ -119,88 +119,64 @@ class testfunc3_cmd : public libt2n::command using namespace libt2n; -class test_serialize : public TestFixture -{ - CPPUNIT_TEST_SUITE(test_serialize); - - CPPUNIT_TEST(ClientSerializeErr); - - // TODO: Server Deserialization Error - // TODO: Server Serialization Error - // TODO: Client Deserialization Error - // but those probably need separate client/server binaries - - CPPUNIT_TEST_SUITE_END(); - - pid_t child_pid; - - public: - - void setUp() - { - } - - void tearDown() - { - // make sure the server-child is dead before the next test runs - kill(child_pid,SIGKILL); - sleep(1); - } +BOOST_FIXTURE_TEST_SUITE(test_serialize, KillChildOnShutdownFixture) +// TODO: Server Deserialization Error +// TODO: Server Serialization Error +// TODO: Client Deserialization Error +// but those probably need separate client/server binaries - void ClientSerializeErr() +BOOST_AUTO_TEST_CASE(ClientSerializeErr) +{ + switch(child_pid=fork()) { - switch(child_pid=fork()) + case -1: + { + BOOST_FAIL("fork error"); + break; + } + case 0: + // child { - case -1: + try { - CPPUNIT_FAIL("fork error"); - break; - } - case 0: - // child + socket_server ss("./socket"); + command_server cs(ss); + + // max 10 sec + for (int i=0; i < 10; i++) + cs.handle(1000000); + } catch(...) { - try - { - socket_server ss("./socket"); - command_server cs(ss); - - // max 10 sec - for (int i=0; i < 10; i++) - cs.handle(1000000); - } catch(...) - { - std::cerr << "exception in child. ignoring\n"; - } - - // don't call atexit and stuff - _exit(0); + std::cerr << "exception in child. ignoring\n"; } - default: - // parent + // don't call atexit and stuff + _exit(0); + } + + default: + // parent + { + // wait till server is up + sleep(1); + socket_client_connection sc("./socket"); + command_client cc(&sc); + + string errormsg; + + result_container rc; + try { - // wait till server is up - sleep(1); - socket_client_connection sc("./socket"); - command_client cc(&sc); - - string errormsg; - - result_container rc; - try - { - cc.send_command(new testfunc3_cmd("xyz"),rc); - } - catch(t2n_serialization_error &e) - { errormsg=e.what(); } - catch(...) - { throw; } - - CPPUNIT_ASSERT_EQUAL(string("archive_exception while serializing on client-side, code 2 (unregistered class)"),errormsg); + cc.send_command(new testfunc3_cmd("xyz"),rc); } + catch(t2n_serialization_error &e) + { errormsg=e.what(); } + catch(...) + { throw; } + + BOOST_CHECK_EQUAL(string("archive_exception while serializing on client-side, code 2 (unregistered class)"),errormsg); } } +} -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(test_serialize); +BOOST_AUTO_TEST_SUITE_END()