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 string testfunc(const string& str)
41 throw libt2n::t2n_runtime_error("throw me around");
43 ret.insert(0,100*1024,'x');
45 ret=str+", testfunc() was here";
49 class testfunc_res : public libt2n::result
54 friend class boost::serialization::access;
55 template<class Archive>
56 void serialize(Archive & ar, const unsigned int version)
58 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::result);
59 ar & BOOST_SERIALIZATION_NVP(res);
66 testfunc_res(const string& str)
78 class testfunc_cmd : public libt2n::command
83 friend class boost::serialization::access;
84 template<class Archive>
85 void serialize(Archive & ar, const unsigned int version)
87 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::command);
88 ar & BOOST_SERIALIZATION_NVP(param);
95 testfunc_cmd(const string& str)
100 libt2n::result* operator()()
102 return new testfunc_res(testfunc(param));
106 #include <boost/serialization/export.hpp>
108 BOOST_CLASS_EXPORT(testfunc_cmd)
109 BOOST_CLASS_EXPORT(testfunc_res)
111 using namespace libt2n;
113 class test_simplecmd : public TestFixture
115 CPPUNIT_TEST_SUITE(test_simplecmd);
117 CPPUNIT_TEST(SimpleCmd);
118 CPPUNIT_TEST(SimpleException);
119 CPPUNIT_TEST(BigReturn);
120 CPPUNIT_TEST(BigParameter);
122 CPPUNIT_TEST_SUITE_END();
141 CPPUNIT_FAIL("fork error");
147 socket_server ss("./socket");
148 command_server cs(ss);
151 for (int i=0; i < 10; i++)
154 // don't call atexit and stuff
161 // wait till server is up
163 socket_client_connection sc("./socket");
164 sc.set_logging(&cerr,debug);
165 command_client cc(sc);
168 cc.send_command(new testfunc_cmd("hello"),rc);
170 string ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
172 CPPUNIT_ASSERT_EQUAL(string("hello, testfunc() was here"),ret);
177 void SimpleException()
185 CPPUNIT_FAIL("fork error");
191 socket_server ss("./socket");
192 command_server cs(ss);
195 for (int i=0; i < 10; i++)
198 // don't call atexit and stuff
205 // wait till server is up
207 socket_client_connection sc("./socket");
208 sc.set_logging(&cerr,debug);
209 command_client cc(sc);
212 cc.send_command(new testfunc_cmd("throw"),rc);
218 ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
220 catch(t2n_runtime_error &e)
225 CPPUNIT_ASSERT_EQUAL(string("throw me around"),ret);
238 CPPUNIT_FAIL("fork error");
244 socket_server ss("./socket");
245 command_server cs(ss);
248 for (int i=0; i < 10; i++)
251 // don't call atexit and stuff
258 // wait till server is up
260 socket_client_connection sc("./socket");
261 command_client cc(sc);
264 cc.send_command(new testfunc_cmd("big"),rc);
266 string ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
268 CPPUNIT_ASSERT_EQUAL(string().insert(0,100*1024,'x'),ret);
281 CPPUNIT_FAIL("fork error");
287 socket_server ss("./socket");
288 command_server cs(ss);
291 for (int i=0; i < 10; i++)
294 // don't call atexit and stuff
301 // wait till server is up
303 socket_client_connection sc("./socket");
304 command_client cc(sc);
307 cc.send_command(new testfunc_cmd(string().insert(0,100*1024,'y')),rc);
309 string ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
311 CPPUNIT_ASSERT_EQUAL(string().insert(0,100*1024,'y')+", testfunc() was here",ret);
318 CPPUNIT_TEST_SUITE_REGISTRATION(test_simplecmd);