X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=test%2Fhello.cpp;h=1036e30908748276b947c5b0edbc83289090e652;hp=b9e1489f80cca11166f64cbdcefd87a5aa9ca7f8;hb=b592218402bfa779c024da2f32c4c782d52eaf88;hpb=fb3345ada7ea94225b78994fd50e3de693a2a3d5 diff --git a/test/hello.cpp b/test/hello.cpp index b9e1489..1036e30 100644 --- a/test/hello.cpp +++ b/test/hello.cpp @@ -56,13 +56,19 @@ class test_hello : public TestFixture 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); + } void send_hello(string hello_string, socket_server* ss, int conn_id) { @@ -81,9 +87,7 @@ class test_hello : public TestFixture void HelloOk() { - pid_t pid; - - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -125,9 +129,7 @@ class test_hello : public TestFixture void BadTag() { - pid_t pid; - - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -160,16 +162,13 @@ class test_hello : public TestFixture sleep(1); socket_client_connection sc("./socket"); - string errormsg; + command_client cc(&sc); + + t2n_exception* ep=cc.get_constuctor_exception(); - try - { - command_client cc(&sc); - } - catch(t2n_version_mismatch &e) - { errormsg=e.what(); } - catch(...) - { throw; } + string errormsg; + if (ep) + errormsg=ep->what(); CPPUNIT_ASSERT_EQUAL(string("illegal hello received (T2N)"),errormsg); } @@ -178,9 +177,7 @@ class test_hello : public TestFixture void BadVersion() { - pid_t pid; - - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -217,16 +214,13 @@ class test_hello : public TestFixture sleep(1); socket_client_connection sc("./socket"); - string errormsg; + command_client cc(&sc); - try - { - command_client cc(&sc); - } - catch(t2n_version_mismatch &e) - { errormsg=e.what(); } - catch(...) - { throw; } + t2n_exception* ep=cc.get_constuctor_exception(); + + string errormsg; + if (ep) + errormsg=ep->what(); CPPUNIT_ASSERT_EQUAL(string("not compatible with the server protocol version"),errormsg); } @@ -235,9 +229,7 @@ class test_hello : public TestFixture void SeparatorMissing() { - pid_t pid; - - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -273,16 +265,13 @@ class test_hello : public TestFixture sleep(1); socket_client_connection sc("./socket"); - string errormsg; + command_client cc(&sc); - try - { - command_client cc(&sc); - } - catch(t2n_version_mismatch &e) - { errormsg=e.what(); } - catch(...) - { throw; } + t2n_exception* ep=cc.get_constuctor_exception(); + + string errormsg; + if (ep) + errormsg=ep->what(); CPPUNIT_ASSERT_EQUAL(string("illegal hello received (1. ;)"),errormsg); } @@ -291,9 +280,7 @@ class test_hello : public TestFixture void WrongByteOrder() { - pid_t pid; - - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -338,16 +325,13 @@ class test_hello : public TestFixture sleep(1); socket_client_connection sc("./socket"); - string errormsg; + command_client cc(&sc); - try - { - command_client cc(&sc); - } - catch(t2n_version_mismatch &e) - { errormsg=e.what(); } - catch(...) - { throw; } + t2n_exception* ep=cc.get_constuctor_exception(); + + string errormsg; + if (ep) + errormsg=ep->what(); CPPUNIT_ASSERT_EQUAL(string("host byte order not matching"),errormsg); } @@ -356,9 +340,7 @@ class test_hello : public TestFixture void OtherServerBig() { - pid_t pid; - - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -392,16 +374,13 @@ class test_hello : public TestFixture sleep(1); socket_client_connection sc("./socket"); - string errormsg; + command_client cc(&sc); + + t2n_exception* ep=cc.get_constuctor_exception(); - try - { - command_client cc(&sc); - } - catch(t2n_version_mismatch &e) - { errormsg=e.what(); } - catch(...) - { throw; } + string errormsg; + if (ep) + errormsg=ep->what(); CPPUNIT_ASSERT_EQUAL(string("illegal hello received (T2N)"),errormsg); } @@ -410,9 +389,7 @@ class test_hello : public TestFixture void OtherServerSmall() { - pid_t pid; - - switch(pid=fork()) + switch(child_pid=fork()) { case -1: { @@ -446,16 +423,13 @@ class test_hello : public TestFixture sleep(1); socket_client_connection sc("./socket"); - string errormsg; + command_client cc(&sc); - try - { - command_client cc(&sc); - } - catch(t2n_version_mismatch &e) - { errormsg=e.what(); } - catch(...) - { throw; } + t2n_exception* ep=cc.get_constuctor_exception(); + + string errormsg; + if (ep) + errormsg=ep->what(); CPPUNIT_ASSERT_EQUAL(string("illegal hello received (T2N)"),errormsg); }