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>
33 #define BOOST_TEST_DYN_LINK
34 #include <boost/test/unit_test.hpp>
36 #include <boost/archive/binary_oarchive.hpp>
37 #include <boost/archive/binary_iarchive.hpp>
38 #include <boost/archive/xml_oarchive.hpp>
39 #include <boost/archive/xml_iarchive.hpp>
40 #include <boost/serialization/serialization.hpp>
42 #include <container.hxx>
43 #include <socket_client.hxx>
44 #include <socket_server.hxx>
45 #include <command_client.hxx>
46 #include <command_server.hxx>
48 #include "test_fixtures.hxx"
52 string testfunc(const string& str)
56 throw libt2n::t2n_runtime_error("throw me around");
58 ret.insert(0,100*1024,'x');
60 ret=str+", testfunc() was here";
64 class testfunc_res : public libt2n::result
69 friend class boost::serialization::access;
70 template<class Archive>
71 void serialize(Archive & ar, const unsigned int version)
73 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::result);
74 ar & BOOST_SERIALIZATION_NVP(res);
81 testfunc_res(const string& str)
93 class testfunc_cmd : public libt2n::command
98 friend class boost::serialization::access;
99 template<class Archive>
100 void serialize(Archive & ar, const unsigned int version)
102 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::command);
103 ar & BOOST_SERIALIZATION_NVP(param);
110 testfunc_cmd(const string& str)
115 libt2n::result* operator()()
117 return new testfunc_res(testfunc(param));
121 #include <boost/serialization/export.hpp>
123 BOOST_CLASS_EXPORT(testfunc_cmd)
124 BOOST_CLASS_EXPORT(testfunc_res)
126 using namespace libt2n;
128 BOOST_FIXTURE_TEST_SUITE(test_simplecmd, KillChildOnShutdownFixture)
130 BOOST_AUTO_TEST_CASE(SimpleCmd)
132 switch(child_pid=fork())
136 BOOST_FAIL("fork error");
144 socket_server ss("./socket");
145 command_server cs(ss);
148 for (int i=0; i < 10; i++)
152 std::cerr << "exception in child. ignoring\n";
155 // don't call atexit and stuff
162 // wait till server is up
164 socket_client_connection sc("./socket");
165 sc.set_logging(&cerr,debug);
166 command_client cc(&sc);
169 cc.send_command(new testfunc_cmd("hello"),rc);
171 string ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
173 BOOST_CHECK_EQUAL(string("hello, testfunc() was here"),ret);
178 BOOST_AUTO_TEST_CASE(SimpleException)
180 switch(child_pid=fork())
184 BOOST_FAIL("fork error");
192 socket_server ss("./socket");
193 command_server cs(ss);
196 for (int i=0; i < 10; i++)
200 std::cerr << "exception in child. ignoring\n";
203 // don't call atexit and stuff
210 // wait till server is up
212 socket_client_connection sc("./socket");
213 sc.set_logging(&cerr,debug);
214 command_client cc(&sc);
217 cc.send_command(new testfunc_cmd("throw"),rc);
223 ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
225 catch(t2n_runtime_error &e)
230 BOOST_CHECK_EQUAL(string("throw me around"),ret);
235 BOOST_AUTO_TEST_CASE(BigReturn)
237 switch(child_pid=fork())
241 BOOST_FAIL("fork error");
249 socket_server ss("./socket");
250 command_server cs(ss);
253 for (int i=0; i < 10; i++)
257 std::cerr << "exception in child. ignoring\n";
260 // don't call atexit and stuff
267 // wait till server is up
269 socket_client_connection sc("./socket");
270 command_client cc(&sc);
273 cc.send_command(new testfunc_cmd("big"),rc);
275 string ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
277 BOOST_CHECK_EQUAL(string().insert(0,100*1024,'x'),ret);
282 BOOST_AUTO_TEST_CASE(BigParameter)
284 switch(child_pid=fork())
288 BOOST_FAIL("fork error");
296 socket_server ss("./socket");
297 command_server cs(ss);
299 // max 60 sec - we need atleast 28 handle calls to transfer the buffer
300 for (int i=0; i < 60; i++) {
305 std::cerr << "exception in child. ignoring\n";
308 // don't call atexit and stuff
315 // wait till server is up
317 socket_client_connection sc("./socket");
318 command_client cc(&sc);
321 cc.send_command(new testfunc_cmd(string().insert(0,100*1024,'y')),rc);
323 string ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
325 BOOST_CHECK_EQUAL(string().insert(0,100*1024,'y')+", testfunc() was here",ret);
330 BOOST_AUTO_TEST_SUITE_END()