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 <boost/archive/binary_oarchive.hpp>
38 #include <boost/archive/binary_iarchive.hpp>
39 #include <boost/archive/xml_oarchive.hpp>
40 #include <boost/archive/xml_iarchive.hpp>
41 #include <boost/serialization/serialization.hpp>
43 #include <container.hxx>
44 #include <socket_client.hxx>
45 #include <socket_server.hxx>
46 #include <command_client.hxx>
47 #include <command_server.hxx>
49 #include "test_fixtures.hxx"
55 bool check_sockets(const int& test_socket)
58 set<int>::iterator it;
59 for (it = SocketSet.begin(); it != SocketSet.end(); it++)
61 if (test_socket == *it)
70 class checkfunc_res : public libt2n::result
75 friend class boost::serialization::access;
76 template<class Archive>
77 void serialize(Archive & ar, const unsigned int version)
79 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::result);
80 ar & BOOST_SERIALIZATION_NVP(res);
87 checkfunc_res(const bool& value)
99 class checkfunc_cmd : public libt2n::command
104 friend class boost::serialization::access;
105 template<class Archive>
106 void serialize(Archive & ar, const unsigned int version)
108 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::command);
109 ar & BOOST_SERIALIZATION_NVP(param);
116 checkfunc_cmd(const int& value)
121 libt2n::result* operator()()
123 return new checkfunc_res(check_sockets(param));
127 #include <boost/serialization/export.hpp>
129 BOOST_CLASS_EXPORT(checkfunc_cmd)
130 BOOST_CLASS_EXPORT(checkfunc_res)
132 using namespace libt2n;
134 BOOST_FIXTURE_TEST_SUITE(test_getsocket, KillChildOnShutdownFixture)
136 BOOST_AUTO_TEST_CASE(SocketCheck)
138 switch(child_pid=fork())
142 BOOST_FAIL("fork error");
150 socket_server ss("./socket");
151 command_server cs(ss);
154 for (int i=0; i < 10; i++)
156 SocketSet = ss.get_sockets_set();
161 std::cerr << "exception in child. ignoring\n";
164 // don't call atexit and stuff
171 // wait till server is up
173 socket_client_connection sc("./socket");
174 sc.set_logging(&cerr,debug);
175 command_client cc(&sc);
178 int socket_fd = sc.get_socket();
179 // Next line causes problem
180 cc.send_command(new checkfunc_cmd(socket_fd),rc);
182 bool ret=dynamic_cast<checkfunc_res*>(rc.get_result())->get_data();
190 BOOST_AUTO_TEST_SUITE_END()