1 /***************************************************************************
2 * Copyright (C) 2004 by Intra2net AG *
5 ***************************************************************************/
19 #include <cppunit/extensions/TestFactoryRegistry.h>
20 #include <cppunit/ui/text/TestRunner.h>
21 #include <cppunit/extensions/HelperMacros.h>
23 #include <socket_client.hxx>
24 #include <socket_server.hxx>
27 using namespace libt2n;
28 using namespace CppUnit;
31 class test_comm : public TestFixture
33 CPPUNIT_TEST_SUITE(test_comm);
35 CPPUNIT_TEST(UnixCommToServer);
36 CPPUNIT_TEST(UnixCommToServerAndBack);
37 CPPUNIT_TEST(UnixCommToServerAndBackBig);
38 CPPUNIT_TEST(IPCommToServer);
39 CPPUNIT_TEST(IPCommToServerAndBack);
40 CPPUNIT_TEST(IPCommToServerAndBackBig);
42 CPPUNIT_TEST_SUITE_END();
52 void UnixCommToServer()
61 CPPUNIT_FAIL("fork error");
67 // wait till server is up
69 socket_client_connection sc("./socket");
71 // don't call atexit and stuff
78 socket_server ss("./socket");
80 time_t t0 = time(NULL);
83 while (time(NULL) < t0 + 10 )
85 ss.fill_buffer(1000000);
87 if(ss.get_packet(data))
92 CPPUNIT_ASSERT_EQUAL(string("hello"),data);
95 void UnixCommToServerAndBack()
103 CPPUNIT_FAIL("fork error");
109 socket_server ss("./socket");
110 ss.set_logging(&cerr,debug);
112 time_t t0 = time(NULL);
115 while (time(NULL) < t0 + 10 )
117 ss.fill_buffer(1000000);
122 if(ss.get_packet(data,cid))
124 server_connection* con=ss.get_connection(cid);
135 // don't call atexit and stuff
144 // wait till server is up
146 socket_client_connection sc("./socket");
150 sc.fill_buffer(1000000);
153 CPPUNIT_ASSERT_EQUAL(string("DEF"),data);
157 sc.fill_buffer(1000000);
160 CPPUNIT_ASSERT_EQUAL(string("xyz"),data);
167 void UnixCommToServerAndBackBig()
175 CPPUNIT_FAIL("fork error");
181 socket_server ss("./socket");
182 ss.set_logging(&cerr,debug);
184 time_t t0 = time(NULL);
187 while (time(NULL) < t0 + 10 )
189 ss.fill_buffer(1000000);
194 if(ss.get_packet(data,cid))
196 server_connection* con=ss.get_connection(cid);
201 con->write(string().insert(0,100*1024,'y'));
204 std::cerr << "child: OVER" << std::endl;
205 // don't call atexit and stuff
214 // wait till server is up
216 socket_client_connection sc("./socket");
218 sc.write(string().insert(0,100*1024,'x'));
220 while (!sc.get_packet(data))
221 sc.fill_buffer(1000000);
223 CPPUNIT_ASSERT_EQUAL(string().insert(0,100*1024,'y'),data);
230 void IPCommToServer()
239 CPPUNIT_FAIL("fork error");
245 // wait till server is up
247 socket_client_connection sc(6666);
249 // don't call atexit and stuff
256 socket_server ss(6666);
258 time_t t0 = time(NULL);
261 while (time(NULL) < t0 + 10 )
263 ss.fill_buffer(1000000);
265 if(ss.get_packet(data))
270 CPPUNIT_ASSERT_EQUAL(string("hello"),data);
273 void IPCommToServerAndBack()
281 CPPUNIT_FAIL("fork error");
287 socket_server ss(6666);
288 ss.set_logging(&cerr,debug);
290 time_t t0 = time(NULL);
293 while (time(NULL) < t0 + 10 )
295 ss.fill_buffer(1000000);
300 if(ss.get_packet(data,cid))
302 server_connection* con=ss.get_connection(cid);
313 // don't call atexit and stuff
322 // wait till server is up
324 socket_client_connection sc(6666);
327 sc.fill_buffer(1000000);
330 CPPUNIT_ASSERT_EQUAL(string("DEF"),data);
334 sc.fill_buffer(1000000);
337 CPPUNIT_ASSERT_EQUAL(string("xyz"),data);
345 void IPCommToServerAndBackBig()
353 CPPUNIT_FAIL("fork error");
359 socket_server ss(6666);
360 ss.set_logging(&cerr,debug);
362 time_t t0 = time(NULL);
365 while (time(NULL) < t0 + 10 )
367 ss.fill_buffer(1000000);
372 if(ss.get_packet(data,cid))
374 server_connection* con=ss.get_connection(cid);
376 socket_handler* alias= dynamic_cast< socket_handler* >(con);
381 alias->set_write_block_size( 4093 );
382 con->write(string().insert(0,2048*1024,'y'));
385 // don't call atexit and stuff
394 // wait till server is up
396 socket_client_connection sc(6666);
398 sc.write(string().insert(0,100*1024,'x'));
400 while (!sc.get_packet(data))
401 sc.fill_buffer(1000000);
403 CPPUNIT_ASSERT_EQUAL(string().insert(0,2048*1024,'y'),data);
408 } // eo IPCommToServerAndBackBig()
414 CPPUNIT_TEST_SUITE_REGISTRATION(test_comm);