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)
40 throw libt2n::t2n_runtime_error("throw me around");
42 ret+=", testfunc() was here";
46 class testfunc_res : public libt2n::result
51 friend class boost::serialization::access;
52 template<class Archive>
53 void serialize(Archive & ar, const unsigned int version)
55 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::result);
56 ar & BOOST_SERIALIZATION_NVP(res);
63 testfunc_res(const string& str)
75 class testfunc_cmd : public libt2n::command
80 friend class boost::serialization::access;
81 template<class Archive>
82 void serialize(Archive & ar, const unsigned int version)
84 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::command);
85 ar & BOOST_SERIALIZATION_NVP(param);
92 testfunc_cmd(const string& str)
97 libt2n::result* operator()()
99 return new testfunc_res(testfunc(param));
103 #include <boost/serialization/export.hpp>
105 BOOST_CLASS_EXPORT(testfunc_cmd)
106 BOOST_CLASS_EXPORT(testfunc_res)
108 using namespace libt2n;
110 class test_simplecmd : public TestFixture
112 CPPUNIT_TEST_SUITE(test_simplecmd);
114 CPPUNIT_TEST(SimpleCmd);
115 CPPUNIT_TEST(SimpleException);
117 CPPUNIT_TEST_SUITE_END();
136 CPPUNIT_FAIL("fork error");
142 socket_server ss("./socket");
143 command_server cs(ss);
146 for (int i=0; i < 10; i++)
149 // don't call atexit and stuff
156 // wait till server is up
158 socket_client_connection sc("./socket");
159 sc.set_logging(&cerr,debug);
160 command_client cc(sc);
163 cc.send_command(new testfunc_cmd("hello"),rc);
165 string ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
167 CPPUNIT_ASSERT_EQUAL(string("hello, testfunc() was here"),ret);
172 void SimpleException()
180 CPPUNIT_FAIL("fork error");
186 socket_server ss("./socket");
187 command_server cs(ss);
190 for (int i=0; i < 10; i++)
193 // don't call atexit and stuff
200 // wait till server is up
202 socket_client_connection sc("./socket");
203 sc.set_logging(&cerr,debug);
204 command_client cc(sc);
207 cc.send_command(new testfunc_cmd("throw"),rc);
213 ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
215 catch(t2n_runtime_error &e)
220 CPPUNIT_ASSERT_EQUAL(string("throw me around"),ret);
227 CPPUNIT_TEST_SUITE_REGISTRATION(test_simplecmd);