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 "test_fixtures.hxx"
35 #define BOOST_TEST_DYN_LINK
36 #include <boost/test/unit_test.hpp>
38 #include <boost/archive/binary_oarchive.hpp>
39 #include <boost/archive/binary_iarchive.hpp>
40 #include <boost/archive/xml_oarchive.hpp>
41 #include <boost/archive/xml_iarchive.hpp>
42 #include <boost/serialization/serialization.hpp>
44 #include <container.hxx>
45 #include <socket_client.hxx>
46 #include <socket_server.hxx>
47 #include <command_client.hxx>
48 #include <command_server.hxx>
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 BOOST_FIXTURE_TEST_SUITE(test_serialize, KillChildOnShutdownFixture)
123 // TODO: Server Deserialization Error
124 // TODO: Server Serialization Error
125 // TODO: Client Deserialization Error
126 // but those probably need separate client/server binaries
128 BOOST_AUTO_TEST_CASE(ClientSerializeErr)
130 switch(child_pid=fork())
134 BOOST_FAIL("fork error");
142 socket_server ss("./socket");
143 command_server cs(ss);
146 for (int i=0; i < 10; i++)
150 std::cerr << "exception in child. ignoring\n";
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(); }
175 BOOST_CHECK_EQUAL(string("archive_exception while serializing on client-side, code 2 (unregistered class - derived class not registered or exported)"),errormsg);
180 BOOST_AUTO_TEST_SUITE_END()