X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=test%2Fcomm.cpp;h=55c5632daeaab7db410f35d811661957eb39ccb2;hp=60907b206656a260a21dc1dcb067396e47698068;hb=cc68aabb16ec32278df8b071c4c9efec7e9f0dce;hpb=9424729586fdb0aabb671d2f1266bdb07e0bed38 diff --git a/test/comm.cpp b/test/comm.cpp index 60907b2..55c5632 100644 --- a/test/comm.cpp +++ b/test/comm.cpp @@ -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);