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>
23 #include <boost/archive/binary_oarchive.hpp>
24 #include <boost/archive/binary_iarchive.hpp>
25 #include <boost/serialization/serialization.hpp>
27 #include <container.hxx>
28 #include <socket_client.hxx>
29 #include <socket_server.hxx>
30 #include <command_client.hxx>
31 #include <command_server.hxx>
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)
73 class testfunc_cmd : public libt2n::command
78 friend class boost::serialization::access;
79 template<class Archive>
80 void serialize(Archive & ar, const unsigned int version)
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));
101 #include <boost/serialization/export.hpp>
103 BOOST_CLASS_EXPORT(testfunc_cmd)
104 BOOST_CLASS_EXPORT(testfunc_res)
106 class test_simplecmd : public TestFixture
108 CPPUNIT_TEST_SUITE(test_simplecmd);
110 CPPUNIT_TEST(SimpleCmd);
112 CPPUNIT_TEST_SUITE_END();
131 CPPUNIT_FAIL("fork error");
137 socket_server ss("./socket");
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 sc.set_logging(&cerr,debug);
155 command_client cc(sc);
158 cc.send_command(new testfunc_cmd("hello"),rc);
160 string ret=dynamic_cast<testfunc_res*>(rc.get_result())->get_data();
162 CPPUNIT_ASSERT_EQUAL(string("hello, testfunc() was here"),ret);
170 CPPUNIT_TEST_SUITE_REGISTRATION(test_simplecmd);