#include <iostream>
#include <sstream>
#include <string>
#include <RCF/test/TestMinimal.hpp>
#include <RCF/Idl.hpp>
#include <RCF/RcfServer.hpp>
#include <RCF/test/EndpointFactories.hpp>
#include <RCF/test/TransportFactories.hpp>
#include <RCF/util/CommandLine.hpp>
#include <RCF/util/PortNumbers.hpp>
#include <SF/AdlWorkaround.hpp>
#include <SF/memory.hpp>
#include <SF/ITextStream.hpp>
#include <SF/OTextStream.hpp>
#ifdef RCF_USE_BOOST_SERIALIZATION
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#endif
namespace Test_StubSerialization {
RCF_BEGIN(I_X, "I_X")
RCF_METHOD_V0(void, increment);
RCF_METHOD_R0(int, getCount);
RCF_END(I_X);
class X
{
public:
X() : count(RCF_DEFAULT_INIT)
{}
void increment()
{
count++;
}
int getCount()
{
return count;
}
private:
int count;
};
} // namespace Test_StubSerialization
RCF_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(Test_StubSerialization::I_X::RcfClient)
// TODO: following belong in RCF headers
RCF_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(RCF::ClientStub)
RCF_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(RCF::RemoteCallSemantics)
//RCF_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(RCF::I_Endpoint)
RCF_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(RCF::EndpointPtr)
//SF_ADL_WORKAROUND(RCF, I_Endpoint)
SF_ADL_WORKAROUND(RCF, ByteBuffer)
int RCF_TEST_MAIN(int argc, char **argv)
{
printTestHeader(__FILE__);
using namespace Test_StubSerialization;
util::CommandLine::getSingleton().parse(argc, argv);
for (unsigned int i=0; i<RCF::getEndpointPairFactories().size(); ++i)
{
RCF::EndpointPair endpointPair = RCF::getEndpointPairFactories()[i]->createEndpointPair();
const RCF::I_Endpoint &serverEndpoint = *endpointPair.first;
const RCF::I_Endpoint &clientEndpoint = *endpointPair.second;
X x;
RCF::RcfServer server(serverEndpoint);
server.bind( (I_X*) 0, x);
server.start();
RcfClient<I_X> client(clientEndpoint);
client.increment();
std::ostringstream os1;
SF::OTextStream(os1) << client;
std::string s1 = os1.str();
RCF_TRACE("")(s1);
{
RcfClient<I_X> client2;
std::istringstream is(s1);
SF::ITextStream(is) >> client2;
client2.increment();
}
{
RcfClient<I_X> client3;
std::istringstream is(s1);
SF::ITextStream(is) >> client3;
client3.increment();
}
// Polymorphic serialization in B.Ser. is seriously broken on gcc.
// On gcc 3.4, this test passes in debug, and crashes on release.
// On gcc 3.2, it asserts.
#if defined(RCF_USE_BOOST_SERIALIZATION) && !defined(__GNUC__)
{
std::ostringstream os;
boost::archive::text_oarchive(os) & client;
std::string s = os.str();
RCF_TRACE("")(s);
RcfClient<I_X> client4;
std::istringstream is(s);
boost::archive::text_iarchive(is) & client4;
client4.increment();
}
int count = client.getCount();
BOOST_CHECK(count == 4);
#else
int count = client.getCount();
BOOST_CHECK(count == 3);
#endif
}
return boost::exit_success;
}