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 testfunc3(const string& str)
40 throw libt2n::t2n_runtime_error("throw me around");
42 ret+=", testfunc() was here";
46 class testfunc3_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 testfunc3_res(const string& str)
75 class testfunc3_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 testfunc3_cmd(const string& str)
97 libt2n::result* operator()()
99 return new testfunc3_res(testfunc3(param));
103 #include <boost/serialization/export.hpp>
105 using namespace libt2n;
107 class test_serialize : public TestFixture
109 CPPUNIT_TEST_SUITE(test_serialize);
111 CPPUNIT_TEST(ClientSerializeErr);
113 // TODO: Server Deserialization Error
114 // TODO: Server Serialization Error
115 // TODO: Client Deserialization Error
116 // but those probably need separate client/server binaries
118 CPPUNIT_TEST_SUITE_END();
129 // make sure the server-child is dead before the next test runs
130 kill(child_pid,SIGKILL);
134 void ClientSerializeErr()
136 switch(child_pid=fork())
140 CPPUNIT_FAIL("fork error");
146 socket_server ss("./socket");
147 command_server cs(ss);
150 for (int i=0; i < 10; i++)
153 // don't call atexit and stuff
160 // wait till server is up
162 socket_client_connection sc("./socket");
163 command_client cc(&sc);
170 cc.send_command(new testfunc3_cmd("xyz"),rc);
172 catch(t2n_serialization_error &e)
173 { errormsg=e.what(); }
177 CPPUNIT_ASSERT_EQUAL(string("archive_exception while serializing on client-side, code 2 (unregistered class)"),errormsg);
184 CPPUNIT_TEST_SUITE_REGISTRATION(test_serialize);