2 Copyright (C) 2004 by Intra2net AG
4 The software in this package is distributed under the GNU General
5 Public License version 2 (with a special exception described below).
7 A copy of GNU General Public License (GPL) is included in this distribution,
8 in the file COPYING.GPL.
10 As a special exception, if other files instantiate templates or use macros
11 or inline functions from this file, or you compile this file and link it
12 with other works to produce a work based on this file, this file
13 does not by itself cause the resulting work to be covered
14 by the GNU General Public License.
16 However the source code for this file must still be made available
17 in accordance with section (3) of the GNU General Public License.
19 This exception does not invalidate any other reasons why a work based
20 on this file might be covered by the GNU General Public License.
22 #include <sys/types.h>
34 #define BOOST_TEST_DYN_LINK
35 #include <boost/test/unit_test.hpp>
37 #include <socket_client.hxx>
38 #include <socket_server.hxx>
40 #include "test_fixtures.hxx"
43 using namespace libt2n;
45 BOOST_FIXTURE_TEST_SUITE(test_comm, KillChildOnShutdownFixture)
47 BOOST_AUTO_TEST_CASE(UnixCommToServer)
51 switch(child_pid=fork())
55 BOOST_FAIL("fork error");
63 // wait till server is up
65 socket_client_connection sc("./socket");
69 std::cerr << "exception in child. ignoring\n";
72 // don't call atexit and stuff
79 socket_server ss("./socket");
81 time_t t0 = time(NULL);
84 while (time(NULL) < t0 + 10 )
86 ss.fill_buffer(1000000);
88 if(ss.get_packet(data))
93 BOOST_CHECK_EQUAL(string("hello"),data);
96 BOOST_AUTO_TEST_CASE(UnixCommToServerAndBack)
98 switch(child_pid=fork())
102 BOOST_FAIL("fork error");
110 socket_server ss("./socket");
111 ss.set_logging(&cerr,debug);
113 time_t t0 = time(NULL);
116 while (time(NULL) < t0 + 10 )
118 ss.fill_buffer(1000000);
123 if(ss.get_packet(data,cid))
125 server_connection* con=ss.get_connection(cid);
138 std::cerr << "exception in child. ignoring\n";
141 // don't call atexit and stuff
150 // wait till server is up
152 socket_client_connection sc("./socket");
156 sc.fill_buffer(1000000);
159 BOOST_CHECK_EQUAL(string("DEF"),data);
163 sc.fill_buffer(1000000);
166 BOOST_CHECK_EQUAL(string("xyz"),data);
173 BOOST_AUTO_TEST_CASE(UnixCommToServerAndBackBig)
175 switch(child_pid=fork())
179 BOOST_FAIL("fork error");
187 socket_server ss("./socket");
188 ss.set_logging(&cerr,debug);
190 time_t t0 = time(NULL);
193 while (time(NULL) < t0 + 10 )
195 ss.fill_buffer(1000000);
200 if(ss.get_packet(data,cid))
202 server_connection* con=ss.get_connection(cid);
207 con->write(string().insert(0,100*1024,'y'));
210 std::cerr << "child: OVER" << std::endl;
213 std::cerr << "exception in child. ignoring\n";
216 // don't call atexit and stuff
225 // wait till server is up
227 socket_client_connection sc("./socket");
229 sc.write(string().insert(0,100*1024,'x'));
231 while (!sc.get_packet(data))
232 sc.fill_buffer(1000000);
234 BOOST_CHECK_EQUAL(string().insert(0,100*1024,'y'),data);
241 BOOST_AUTO_TEST_CASE(IPCommToServer)
245 switch(child_pid=fork())
249 BOOST_FAIL("fork error");
257 // wait till server is up
259 socket_client_connection sc(6666);
263 std::cerr << "exception in child. ignoring\n";
266 // don't call atexit and stuff
273 socket_server ss(6666);
275 time_t t0 = time(NULL);
278 while (time(NULL) < t0 + 10 )
280 ss.fill_buffer(1000000);
282 if(ss.get_packet(data))
287 BOOST_CHECK_EQUAL(string("hello"),data);
290 BOOST_AUTO_TEST_CASE(IPCommToServerAndBack)
292 switch(child_pid=fork())
296 BOOST_FAIL("fork error");
304 socket_server ss(6666);
305 ss.set_logging(&cerr,debug);
307 time_t t0 = time(NULL);
310 while (time(NULL) < t0 + 10 )
312 ss.fill_buffer(1000000);
317 if(ss.get_packet(data,cid))
319 server_connection* con=ss.get_connection(cid);
332 std::cerr << "exception in child. ignoring\n";
334 // don't call atexit and stuff
343 // wait till server is up
345 socket_client_connection sc(6666);
348 sc.fill_buffer(1000000);
351 BOOST_CHECK_EQUAL(string("DEF"),data);
355 sc.fill_buffer(1000000);
358 BOOST_CHECK_EQUAL(string("xyz"),data);
366 BOOST_AUTO_TEST_CASE(IPCommToServerAndBackBig)
368 switch(child_pid=fork())
372 BOOST_FAIL("fork error");
380 socket_server ss(6666);
381 ss.set_logging(&cerr,debug);
383 time_t t0 = time(NULL);
386 while (time(NULL) < t0 + 10 )
388 ss.fill_buffer(1000000);
393 if(ss.get_packet(data,cid))
395 server_connection* con=ss.get_connection(cid);
397 socket_handler* alias= dynamic_cast< socket_handler* >(con);
402 alias->set_write_block_size( 4093 );
403 con->write(string().insert(0,2048*1024,'y'));
408 std::cerr << "exception in child. ignoring\n";
410 // don't call atexit and stuff
419 // wait till server is up
421 socket_client_connection sc(6666);
423 sc.write(string().insert(0,100*1024,'x'));
425 while (!sc.get_packet(data))
426 sc.fill_buffer(1000000);
428 BOOST_CHECK_EQUAL(string().insert(0,2048*1024,'y'),data);
433 } // eo IPCommToServerAndBackBig()
435 BOOST_AUTO_TEST_SUITE_END()