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>
27 #include <boost/serialization/export.hpp>
29 #include <container.hxx>
30 #include <socket_client.hxx>
31 #include <socket_server.hxx>
32 #include <command_client.hxx>
33 #include <command_server.hxx>
36 using namespace CppUnit;
37 using namespace libt2n;
39 string testfunc4(const string& str)
42 throw libt2n::t2n_runtime_error("throw me around");
44 ret+=", testfunc() was here";
48 class testfunc4_res : public libt2n::result
53 friend class boost::serialization::access;
54 template<class Archive>
55 void serialize(Archive & ar, const unsigned int version)
57 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::result);
58 ar & BOOST_SERIALIZATION_NVP(res);
65 testfunc4_res(const string& str)
76 class cmd_group_a : public command
79 friend class boost::serialization::access;
80 template<class Archive>
81 void serialize(Archive & ar, const unsigned int version)
83 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::command);
87 class cmd_group_b : public command
90 friend class boost::serialization::access;
91 template<class Archive>
92 void serialize(Archive & ar, const unsigned int version)
94 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::command);
98 class testfunc4a_cmd : public cmd_group_a
103 friend class boost::serialization::access;
104 template<class Archive>
105 void serialize(Archive & ar, const unsigned int version)
107 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(cmd_group_a);
108 ar & BOOST_SERIALIZATION_NVP(param);
115 testfunc4a_cmd(const string& str)
120 libt2n::result* operator()()
122 return new testfunc4_res(testfunc4(param));
126 class testfunc4b_cmd : public cmd_group_b
131 friend class boost::serialization::access;
132 template<class Archive>
133 void serialize(Archive & ar, const unsigned int version)
135 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(cmd_group_b);
136 ar & BOOST_SERIALIZATION_NVP(param);
143 testfunc4b_cmd(const string& str)
148 libt2n::result* operator()()
150 return new testfunc4_res(testfunc4(param));
155 BOOST_CLASS_EXPORT(testfunc4_res)
156 BOOST_CLASS_EXPORT(cmd_group_a)
157 BOOST_CLASS_EXPORT(cmd_group_b)
158 BOOST_CLASS_EXPORT(testfunc4a_cmd)
159 BOOST_CLASS_EXPORT(testfunc4b_cmd)
161 class test_cmdgroup : public TestFixture
163 CPPUNIT_TEST_SUITE(test_cmdgroup);
165 CPPUNIT_TEST(GroupOk);
166 CPPUNIT_TEST(WrongGroup);
168 CPPUNIT_TEST_SUITE_END();
186 CPPUNIT_FAIL("fork error");
192 socket_server ss("./socket");
193 group_command_server<cmd_group_a> cs(ss);
196 for (int i=0; i < 10; i++)
199 // don't call atexit and stuff
206 // wait till server is up
208 socket_client_connection sc("./socket");
209 command_client cc(sc);
212 cc.send_command(new testfunc4a_cmd("hello"),rc);
214 string ret=dynamic_cast<testfunc4_res*>(rc.get_result())->get_data();
216 CPPUNIT_ASSERT_EQUAL(string("hello, testfunc() was here"),ret);
229 CPPUNIT_FAIL("fork error");
235 socket_server ss("./socket");
236 group_command_server<cmd_group_b> cs(ss);
239 for (int i=0; i < 10; i++)
242 // don't call atexit and stuff
249 // wait till server is up
251 socket_client_connection sc("./socket");
252 command_client cc(sc);
255 cc.send_command(new testfunc4a_cmd("hello"),rc);
261 ret=dynamic_cast<testfunc4_res*>(rc.get_result())->get_data();
263 catch(t2n_command_error &e)
268 string expected_what="illegal command of type ";
270 CPPUNIT_ASSERT_EQUAL(expected_what,ret.substr(0,expected_what.size()));
277 CPPUNIT_TEST_SUITE_REGISTRATION(test_cmdgroup);