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 <container.hxx>
23 #include <socket_client.hxx>
24 #include <socket_server.hxx>
25 #include <command_client.hxx>
26 #include <command_server.hxx>
28 #include <boost/serialization/serialization.hpp>
29 #include <boost/serialization/level.hpp>
30 #include <boost/serialization/tracking.hpp>
31 #include <boost/serialization/export.hpp>
34 using namespace libt2n;
35 using namespace CppUnit;
37 string testfunc(const string& str)
40 ret+=", testfunc() was here";
44 class testfunc_res : public result
49 friend class boost::serialization::access;
50 template<class Archive>
51 void serialize(Archive & ar, const unsigned int version)
53 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(result);
54 ar & BOOST_SERIALIZATION_NVP(res);
61 testfunc_res(const string& str)
72 class testfunc_cmd : public libt2n::command
77 friend class boost::serialization::access;
78 template<class Archive>
79 void serialize(Archive & ar, const unsigned int version)
81 cerr << "ser: testfunc_cmd" << endl;
82 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::command);
83 ar & BOOST_SERIALIZATION_NVP(param);
90 testfunc_cmd(const string& str)
97 return new testfunc_res(testfunc(param));
102 BOOST_CLASS_EXPORT(testfunc_cmd)
103 BOOST_CLASS_EXPORT(testfunc_res)
105 class test_simplecmd : public TestFixture
107 CPPUNIT_TEST_SUITE(test_simplecmd);
109 CPPUNIT_TEST(SimpleCmd);
111 CPPUNIT_TEST_SUITE_END();
130 CPPUNIT_FAIL("fork error");
136 socket_server ss("./socket");
137 ss.set_logging(&cerr,debug);
138 command_server cs(ss);
141 for (int i=0; i < 10; i++)
144 // don't call atexit and stuff
151 // wait till server is up
153 socket_client_connection sc("./socket");
154 command_client cc(sc);
157 cc.send_command(new testfunc_cmd("hello"),rc);
159 string ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
161 CPPUNIT_ASSERT_EQUAL(string("hello, testfunc() was here"),ret);
169 CPPUNIT_TEST_SUITE_REGISTRATION(test_simplecmd);