libt2n: (gerd) make sure no exception is thrown in command_client constructor, fix...
[libt2n] / test / hello.cpp
index 80bfec6..1036e30 100644 (file)
@@ -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:
             {
@@ -118,16 +122,14 @@ class test_hello : public TestFixture
                 // wait till server is up
                 sleep(1);
                 socket_client_connection sc("./socket");
-                command_client cc(sc);
+                command_client cc(&sc);
             }
         }
     }
 
     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);
 
-                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);
             }
@@ -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);
+
+                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);
             }