libt2n: (gerd) add ip communication
[libt2n] / test / comm.cpp
index 60907b2..55c5632 100644 (file)
@@ -32,6 +32,7 @@ class test_comm : public TestFixture
 
     CPPUNIT_TEST(UnixCommToServer);
     CPPUNIT_TEST(UnixCommToServerAndBack);
+    CPPUNIT_TEST(IPCommToServer);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -154,6 +155,47 @@ class test_comm : public TestFixture
         }
     }
 
+    void IPCommToServer()
+    {
+        pid_t pid;
+        string data;
+
+        switch(pid=fork())
+        {
+            case -1:
+            {
+                CPPUNIT_FAIL("fork error");
+                break;
+            }
+            case 0:
+            // child
+            {
+                // wait till server is up
+                sleep(1);
+                socket_client_connection sc("localhost",6666,socket_client_connection::max_retries_default);
+                sc.write("hello");
+                // don't call atexit and stuff
+                _exit(0);
+            }
+
+            default:
+            // parent
+            {
+                socket_server ss(6666);
+
+                // max 10 sec
+                for (int i=0; i < 10; i++)
+                {
+                    ss.fill_buffer(1000000);
+
+                    if(ss.get_packet(data))
+                        break;
+                }
+            }
+        }
+        CPPUNIT_ASSERT_EQUAL(string("hello"),data);
+    }
+
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(test_comm);