2 Copyright (C) 2004 by Intra2net AG
4 The software in this package is distributed under the GNU General
5 Public License version 2 (with a special exception described below).
7 A copy of GNU General Public License (GPL) is included in this distribution,
8 in the file COPYING.GPL.
10 As a special exception, if other files instantiate templates or use macros
11 or inline functions from this file, or you compile this file and link it
12 with other works to produce a work based on this file, this file
13 does not by itself cause the resulting work to be covered
14 by the GNU General Public License.
16 However the source code for this file must still be made available
17 in accordance with section (3) of the GNU General Public License.
19 This exception does not invalidate any other reasons why a work based
20 on this file might be covered by the GNU General Public License.
22 #include <sys/types.h>
33 #include <cppunit/extensions/TestFactoryRegistry.h>
34 #include <cppunit/ui/text/TestRunner.h>
35 #include <cppunit/extensions/HelperMacros.h>
37 #include <boost/archive/binary_oarchive.hpp>
38 #include <boost/archive/binary_iarchive.hpp>
39 #include <boost/archive/xml_oarchive.hpp>
40 #include <boost/archive/xml_iarchive.hpp>
41 #include <boost/serialization/serialization.hpp>
43 #include <container.hxx>
44 #include <socket_client.hxx>
45 #include <socket_server.hxx>
46 #include <command_client.hxx>
47 #include <command_server.hxx>
50 using namespace CppUnit;
52 string testfunc3(const string& str)
55 throw libt2n::t2n_runtime_error("throw me around");
57 ret+=", testfunc() was here";
61 class testfunc3_res : public libt2n::result
66 friend class boost::serialization::access;
67 template<class Archive>
68 void serialize(Archive & ar, const unsigned int version)
70 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::result);
71 ar & BOOST_SERIALIZATION_NVP(res);
78 testfunc3_res(const string& str)
90 class testfunc3_cmd : public libt2n::command
95 friend class boost::serialization::access;
96 template<class Archive>
97 void serialize(Archive & ar, const unsigned int version)
99 ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::command);
100 ar & BOOST_SERIALIZATION_NVP(param);
107 testfunc3_cmd(const string& str)
112 libt2n::result* operator()()
114 return new testfunc3_res(testfunc3(param));
118 #include <boost/serialization/export.hpp>
120 using namespace libt2n;
122 class test_serialize : public TestFixture
124 CPPUNIT_TEST_SUITE(test_serialize);
126 CPPUNIT_TEST(ClientSerializeErr);
128 // TODO: Server Deserialization Error
129 // TODO: Server Serialization Error
130 // TODO: Client Deserialization Error
131 // but those probably need separate client/server binaries
133 CPPUNIT_TEST_SUITE_END();
145 // make sure the server-child is dead before the next test runs
146 kill(child_pid,SIGKILL);
150 void ClientSerializeErr()
152 switch(child_pid=fork())
156 CPPUNIT_FAIL("fork error");
164 socket_server ss("./socket");
165 command_server cs(ss);
168 for (int i=0; i < 10; i++)
172 std::cerr << "exception in child. ignoring\n";
175 // don't call atexit and stuff
182 // wait till server is up
184 socket_client_connection sc("./socket");
185 command_client cc(&sc);
192 cc.send_command(new testfunc3_cmd("xyz"),rc);
194 catch(t2n_serialization_error &e)
195 { errormsg=e.what(); }
199 CPPUNIT_ASSERT_EQUAL(string("archive_exception while serializing on client-side, code 2 (unregistered class)"),errormsg);
206 CPPUNIT_TEST_SUITE_REGISTRATION(test_serialize);