X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=test%2Fcomm.cpp;h=60446931ba06b5f303c5edf259a77168907e8e72;hp=55c5632daeaab7db410f35d811661957eb39ccb2;hb=7087e18783f91d2b889e880462d1d1da24831c28;hpb=cc68aabb16ec32278df8b071c4c9efec7e9f0dce diff --git a/test/comm.cpp b/test/comm.cpp index 55c5632..6044693 100644 --- a/test/comm.cpp +++ b/test/comm.cpp @@ -33,6 +33,7 @@ class test_comm : public TestFixture CPPUNIT_TEST(UnixCommToServer); CPPUNIT_TEST(UnixCommToServerAndBack); CPPUNIT_TEST(IPCommToServer); + CPPUNIT_TEST(IPCommToServerAndBack); CPPUNIT_TEST_SUITE_END(); @@ -196,6 +197,75 @@ class test_comm : public TestFixture CPPUNIT_ASSERT_EQUAL(string("hello"),data); } + void IPCommToServerAndBack() + { + pid_t pid; + + switch(pid=fork()) + { + case -1: + { + CPPUNIT_FAIL("fork error"); + break; + } + case 0: + // child + { + socket_server ss(6666); + ss.set_logging(&cerr,debug); + + // max 10 sec + for (int i=0; i < 10; i++) + { + ss.fill_buffer(1000000); + + string data; + unsigned int cid; + + if(ss.get_packet(data,cid)) + { + server_connection* con=ss.get_connection(cid); + + if (data=="QUIT") + break; + + if (data=="ABC") + con->write("DEF"); + else + con->write("xyz"); + } + } + // don't call atexit and stuff + _exit(0); + } + + default: + // parent + { + string data; + + // wait till server is up + sleep(1); + socket_client_connection sc("localhost",6666,socket_client_connection::max_retries_default); + sc.write("ABC"); + + sc.fill_buffer(1000000); + sc.get_packet(data); + + CPPUNIT_ASSERT_EQUAL(string("DEF"),data); + + sc.write("HAHA"); + + sc.fill_buffer(1000000); + sc.get_packet(data); + + CPPUNIT_ASSERT_EQUAL(string("xyz"),data); + + sc.write("QUIT"); + } + } + } + }; CPPUNIT_TEST_SUITE_REGISTRATION(test_comm);