X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=test%2Fserialize.cpp;fp=test%2Fserialize.cpp;h=02f8a6edbef858bc8d2be5ad0c88387735597ae5;hp=0000000000000000000000000000000000000000;hb=01a464637ed95b0aacd58eb74bdd17df4a7851ab;hpb=b604df5f671b5e7abfd37570d76927a6ebd45f98 diff --git a/test/serialize.cpp b/test/serialize.cpp new file mode 100644 index 0000000..02f8a6e --- /dev/null +++ b/test/serialize.cpp @@ -0,0 +1,180 @@ +/*************************************************************************** + * Copyright (C) 2004 by Intra2net AG * + * info@intra2net.com * + * * + ***************************************************************************/ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +using namespace std; +using namespace CppUnit; + +string testfunc3(const string& str) +{ + if (str=="throw") + throw libt2n::t2n_runtime_error("throw me around"); + string ret(str); + ret+=", testfunc() was here"; + return ret; +} + +class testfunc3_res : public libt2n::result +{ + private: + string res; + + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::result); + ar & BOOST_SERIALIZATION_NVP(res); + } + + public: + testfunc3_res() + { } + + testfunc3_res(const string& str) + { + res=str; + } + + string get_data() + { + return res; + } +}; + + +class testfunc3_cmd : public libt2n::command +{ + private: + string param; + + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int version) + { + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::command); + ar & BOOST_SERIALIZATION_NVP(param); + } + + public: + testfunc3_cmd() + { } + + testfunc3_cmd(const string& str) + { + param=str; + } + + libt2n::result* operator()() + { + return new testfunc3_res(testfunc3(param)); + } +}; + +#include + +using namespace libt2n; + +class test_serialize : public TestFixture +{ + CPPUNIT_TEST_SUITE(test_serialize); + + CPPUNIT_TEST(ClientSerializeErr); + + // TODO: Server Deserialization Error + // TODO: Server Serialization Error + // TODO: Client Deserialization Error + // but those probably need separate client/server binaries + + CPPUNIT_TEST_SUITE_END(); + + public: + + void setUp() + { } + + void tearDown() + { } + + void ClientSerializeErr() + { + pid_t pid; + + switch(pid=fork()) + { + case -1: + { + CPPUNIT_FAIL("fork error"); + break; + } + case 0: + // child + { + socket_server ss("./socket"); + command_server cs(ss); + + // max 10 sec + for (int i=0; i < 10; i++) + cs.handle(1000000); + + // don't call atexit and stuff + _exit(0); + } + + default: + // parent + { + // wait till server is up + sleep(1); + socket_client_connection sc("./socket"); + command_client cc(sc); + + string errormsg; + + result_container rc; + try + { + cc.send_command(new testfunc3_cmd("xyz"),rc); + } + catch(t2n_serialization_error &e) + { errormsg=e.what(); } + catch(...) + { throw; } + + CPPUNIT_ASSERT_EQUAL(string("archive_exception while serializing on client-side, code 2 (unregistered class)"),errormsg); + } + } + } + +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(test_serialize);