1 /***************************************************************************
2 * Copyright (C) 2004 by Intra2net AG *
5 ***************************************************************************/
18 #include <cppunit/extensions/TestFactoryRegistry.h>
19 #include <cppunit/ui/text/TestRunner.h>
20 #include <cppunit/extensions/HelperMacros.h>
22 #include <boost/archive/binary_oarchive.hpp>
23 #include <boost/archive/binary_iarchive.hpp>
24 #include <boost/archive/xml_oarchive.hpp>
25 #include <boost/archive/xml_iarchive.hpp>
26 #include <boost/serialization/serialization.hpp>
28 #include <container.hxx>
29 #include <socket_client.hxx>
30 #include <socket_server.hxx>
31 #include <command_client.hxx>
32 #include <command_server.hxx>
35 using namespace CppUnit;
37 int newserver_func(int i)
43 class newserver_res : public libt2n::result
48 friend class boost::serialization::access;
49 template<class Archive>
50 void serialize(Archive & ar, const unsigned int version)
52 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::result);
53 ar & BOOST_SERIALIZATION_NVP(res);
72 class newserver_cmd : public libt2n::command
77 friend class boost::serialization::access;
78 template<class Archive>
79 void serialize(Archive & ar, const unsigned int version)
81 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::command);
82 ar & BOOST_SERIALIZATION_NVP(param);
94 libt2n::result* operator()()
96 return new newserver_res(newserver_func(param));
100 #include <boost/serialization/export.hpp>
102 BOOST_CLASS_EXPORT(newserver_cmd)
103 BOOST_CLASS_EXPORT(newserver_res)
105 using namespace libt2n;
107 class test_newserver : public TestFixture
109 CPPUNIT_TEST_SUITE(test_newserver);
111 CPPUNIT_TEST(NewServerSocket);
113 CPPUNIT_TEST_SUITE_END();
124 // make sure the server-child is dead before the next test runs
125 kill(child_pid,SIGKILL);
129 void NewServerSocket()
131 switch(child_pid=fork())
135 CPPUNIT_FAIL("fork error");
142 socket_server ss("./socket");
143 command_server cs(ss);
145 // handle new connection and just one command
149 // close socket, create new one
151 socket_server ss("./socket");
152 ss.set_logging(&cerr,debug);
153 command_server cs(ss);
156 for (int i=0; i < 30; i++)
160 // don't call atexit and stuff
167 // wait till server is up
169 socket_client_connection sc("./socket");
170 sc.set_logging(&cerr,debug);
171 command_client cc(&sc);
174 cc.send_command(new newserver_cmd(1),rc);
176 // very short sleep to make sure new server socket is up
179 // still has connection to the old server-socket
184 sc.write("some stuff");
186 catch(t2n_transfer_error &e)
187 { errormsg=e.what(); }
191 CPPUNIT_ASSERT_EQUAL(string("error reading from socket : Connection reset by peer"),errormsg);
197 CPPUNIT_TEST_SUITE_REGISTRATION(test_newserver);