X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=test%2Fcomm.cpp;h=5bba916297461a5d437473453f882398f78d85c4;hp=60446931ba06b5f303c5edf259a77168907e8e72;hb=517d1214577af263bb4d6821e4e7ad9ba8c94901;hpb=7087e18783f91d2b889e880462d1d1da24831c28 diff --git a/test/comm.cpp b/test/comm.cpp index 6044693..5bba916 100644 --- a/test/comm.cpp +++ b/test/comm.cpp @@ -26,14 +26,17 @@ using namespace std; using namespace libt2n; using namespace CppUnit; + class test_comm : public TestFixture { CPPUNIT_TEST_SUITE(test_comm); CPPUNIT_TEST(UnixCommToServer); CPPUNIT_TEST(UnixCommToServerAndBack); + CPPUNIT_TEST(UnixCommToServerAndBackBig); CPPUNIT_TEST(IPCommToServer); CPPUNIT_TEST(IPCommToServerAndBack); + CPPUNIT_TEST(IPCommToServerAndBackBig); CPPUNIT_TEST_SUITE_END(); @@ -156,6 +159,66 @@ class test_comm : public TestFixture } } + void UnixCommToServerAndBackBig() + { + pid_t pid; + + switch(pid=fork()) + { + case -1: + { + CPPUNIT_FAIL("fork error"); + break; + } + case 0: + // child + { + socket_server ss("./socket"); + 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; + + con->write(string().insert(0,100*1024,'y')); + } + } + // don't call atexit and stuff + _exit(0); + } + + default: + // parent + { + string data; + + // wait till server is up + sleep(1); + socket_client_connection sc("./socket"); + + sc.write(string().insert(0,100*1024,'x')); + + while (!sc.get_packet(data)) + sc.fill_buffer(1000000); + + CPPUNIT_ASSERT_EQUAL(string().insert(0,100*1024,'y'),data); + + sc.write("QUIT"); + } + } + } + void IPCommToServer() { pid_t pid; @@ -173,7 +236,7 @@ class test_comm : public TestFixture { // wait till server is up sleep(1); - socket_client_connection sc("localhost",6666,socket_client_connection::max_retries_default); + socket_client_connection sc(6666); sc.write("hello"); // don't call atexit and stuff _exit(0); @@ -246,7 +309,7 @@ class test_comm : public TestFixture // wait till server is up sleep(1); - socket_client_connection sc("localhost",6666,socket_client_connection::max_retries_default); + socket_client_connection sc(6666); sc.write("ABC"); sc.fill_buffer(1000000); @@ -266,6 +329,72 @@ class test_comm : public TestFixture } } + + void IPCommToServerAndBackBig() + { + 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); + + socket_handler* alias= dynamic_cast< socket_handler* >(con); + + if (data=="QUIT") + break; + + alias->set_write_block_size( 4093 ); + con->write(string().insert(0,2048*1024,'y')); + } + } + // don't call atexit and stuff + _exit(0); + } + + default: + // parent + { + string data; + + // wait till server is up + sleep(1); + socket_client_connection sc(6666); + + sc.write(string().insert(0,100*1024,'x')); + + while (!sc.get_packet(data)) + sc.fill_buffer(1000000); + + CPPUNIT_ASSERT_EQUAL(string().insert(0,2048*1024,'y'),data); + + sc.write("QUIT"); + } + } + } // eo IPCommToServerAndBackBig() + + + }; CPPUNIT_TEST_SUITE_REGISTRATION(test_comm);