Exemple #1
0
int test_main(int argc, char **argv)
{
    printTestHeader(__FILE__);

    RCF::RcfInitDeinit rcfInitDeinit;

    using namespace Test_General;

    util::CommandLine::getSingleton().parse(argc, argv);

    for (std::size_t i=0; i<RCF::getTransportFactories().size(); ++i)
    {
        RCF::TransportFactoryPtr transportFactoryPtr = RCF::getTransportFactories()[i];
        RCF::TransportPair transports = transportFactoryPtr->createTransports();
        RCF::ServerTransportPtr serverTransportPtr( transports.first );
        RCF::ClientTransportAutoPtr clientTransportAutoPtr( *transports.second );

        std::cout << transportFactoryPtr->desc() << std::endl;

        RCF::RcfServer server(serverTransportPtr);

        unsigned int numberOfTokens = 50;
        unsigned int objectTimeoutS = 60;
        RCF::ObjectFactoryServicePtr objectFactoryServicePtr( new RCF::ObjectFactoryService(numberOfTokens, objectTimeoutS) );
        objectFactoryServicePtr->bind( (A::Calculator*) 0, (A::B::Calculator**) 0);
        objectFactoryServicePtr->bind( (A::X*) 0, (A::B::X**) 0);
        server.addService( RCF::ServicePtr(objectFactoryServicePtr) );

        A::B::Calculator calculator;
        server.bind( (A::Calculator*) 0, calculator);

        A::B::X x;
        server.bind( (A::X*) 0, x);

        A::B::Y y;
        server.bind( (A::Y*) 0, y);

        A::B::Z z;
        server.bind( (A::Z*) 0, z);

        server.start();

        int nReps = 2;

        boost::shared_ptr<RCF::I_ClientTransport> clientTransportPtr(
                clientTransportAutoPtr->clone().release());

        testCalculatorClientReps(clientTransportPtr, nReps);

        server.stop();
    }

    return 0;
}
Exemple #2
0
int test_main(int argc, char **argv)
{

    printTestHeader(__FILE__);

    RCF::RcfInitDeinit rcfInitDeinit;

    using namespace Test_InitDeinit;

    util::CommandLine::getSingleton().parse(argc, argv);

    RCF::deinit();

    for (unsigned int i=0; i<RCF::getTransportFactories().size(); ++i)
    {
        RCF::init();

        {
            RCF::TransportFactoryPtr transportFactoryPtr = RCF::getTransportFactories()[i];
            RCF::TransportPair transports = transportFactoryPtr->createTransports();
            RCF::ServerTransportPtr serverTransportPtr( transports.first );
            RCF::ClientTransportAutoPtr clientTransportAutoPtr( *transports.second );

            std::cout << transportFactoryPtr->desc() << std::endl;

            std::string s0 = "something special";

            Echo echo;
            RCF::RcfServer server( boost::dynamic_pointer_cast<RCF::I_Service>(serverTransportPtr) );
            server.start();
            server.bind( (I_Echo*) 0, echo);

            std::string s = RcfClient<I_Echo>( clientTransportAutoPtr->clone() ).echo(s0);
            RCF_CHECK_EQ(s0 , s);
        }

        RCF::deinit();

    }

    RCF::init();
    RCF::init();

    RCF::deinit();
    RCF::deinit();

    RCF::init();

    return 0;
}
Exemple #3
0
int test_main(int argc, char **argv)
{
    printTestHeader(__FILE__);

    RCF::RcfInitDeinit rcfInitDeinit;

    using namespace Test_ErrorReporting;

    util::CommandLine::getSingleton().parse(argc, argv);

    // Check error translation.
    int rcfError = RCF::RcfError_ClientCancel;
    RCF::Error err(rcfError);
    RCF::Exception e(err);
    std::string eWhat = e.what();
    std::string errorMsg = RCF::getErrorString(rcfError);
    // Assuming here that RcfError_ClientCancel has no replacements...
    RCF_CHECK( eWhat.find(errorMsg) != std::string::npos );

    {
        RCF::Error err(RCF::_RcfError_ClientConnectTimeout(5000, ""));
        std::string s = err.getErrorString();
        RCF_CHECK( s.find("5000") != std::string::npos );
    }

    for (unsigned int i=0; i<RCF::getTransportFactories().size(); ++i)
    {

        
        RCF::TransportFactoryPtr transportFactoryPtr = RCF::getTransportFactories()[i];
        RCF::TransportPair transports = transportFactoryPtr->createTransports();
        RCF::ServerTransportPtr serverTransportPtr( transports.first );
        RCF::ClientTransportAutoPtr clientTransportAutoPtr( *transports.second );

        std::cout << transportFactoryPtr->desc() << std::endl;

        serverTransportPtr->setMaxMessageLength(1000*10);
        clientTransportAutoPtr->setMaxMessageLength(1000*10);

        std::string s0 = "something special";

        Echo echo;
        RCF::RcfServer server( serverTransportPtr );
        server.start();
        server.bind( (I_Echo *) 0, echo);

        //***********************************************
        // message size errors

        // no error
        {
            serverTransportPtr->setMaxMessageLength(1000*10);
            clientTransportAutoPtr->setMaxMessageLength(1000*10);
            RcfClient<I_Echo> client( clientTransportAutoPtr->clone() );
            RCF_CHECK_EQ(client.putString(makeString(50)) , 50);
            std::string s = client.getString(50);
            RCF_CHECK_EQ(s.size() , 50);
        }

        // try to trigger client transport send error
        {
            serverTransportPtr->setMaxMessageLength(1000*10);
            clientTransportAutoPtr->setMaxMessageLength(100);
            RcfClient<I_Echo>( clientTransportAutoPtr->clone() ).putString(makeString(500));
            RCF_CHECK_OK();
        }

        // trigger client transport receive error
        {
            serverTransportPtr->setMaxMessageLength(1000*10);
            clientTransportAutoPtr->setMaxMessageLength(500);
            try
            {
                RcfClient<I_Echo>( clientTransportAutoPtr->clone() ).getString(500);
                RCF_CHECK_FAIL();
            }
            catch(RCF::Exception &e)
            {
                RCF_CHECK_OK();
                RCF_CHECK_EQ(e.getErrorId() , RCF::RcfError_ClientMessageLength );
            }
        }

        // trigger server transport receive error
        {
            serverTransportPtr->setMaxMessageLength(500);
            clientTransportAutoPtr->setMaxMessageLength(1000*10);
            try
            {
                RcfClient<I_Echo>( clientTransportAutoPtr->clone() ).putString(makeString(500));
                RCF_CHECK_FAIL();
            }
            catch(RCF::RemoteException &e)
            {
                RCF_CHECK_OK();
                RCF_CHECK_EQ(e.getErrorId() , RCF::RcfError_ServerMessageLength );
            }
            catch(RCF::Exception &e)
            {
                if (typeid(*serverTransportPtr) == typeid(RCF::Win32NamedPipeServerTransport))
                {
                    // TODO: named pipe server transport currently doesn't report 
                    // message length errors.
                }
                else
                {
                    // server did a hard close, we didn't get any error info
                    RCF_CHECK_FAIL();
                }
            }
        }

        // try to trigger server transport send error
        {
            serverTransportPtr->setMaxMessageLength(500);
            clientTransportAutoPtr->setMaxMessageLength(1000*10);
            RcfClient<I_Echo>( clientTransportAutoPtr->clone() ).getString(500);
            RCF_CHECK_OK();
        }

        //************************************************
        // serialization errors

        serverTransportPtr->setMaxMessageLength(1000*10);
        clientTransportAutoPtr->setMaxMessageLength(1000*10);

        // no errors
        A a;
        RcfClient<I_Echo>( clientTransportAutoPtr->clone() ).putA(a);
        a = RcfClient<I_Echo>( clientTransportAutoPtr->clone() ).getA(0);

        // outbound client serialization error
        try
        {
            RcfClient<I_Echo>( clientTransportAutoPtr->clone() ).putA( A(1) );
            RCF_CHECK_FAIL();
        }
        catch(const RCF::SerializationException &e)
        {
            std::string msg = e.what();
            RCF_CHECK_OK();
            RCF_CHECK_EQ(e.getErrorId() , RCF::RcfError_Serialization);
        }

        // server deserialization error
        try
        {
            RcfClient<I_Echo>( clientTransportAutoPtr->clone() ).putA( A(2) );
            RCF_CHECK_FAIL();
        }
        catch(RCF::RemoteException &e)
        {
            std::string msg = e.what();
            RCF_CHECK_OK();
            RCF_CHECK_EQ(e.getErrorId() , RCF::SfError_DataFormat);
        }

        // server serialization error
        try
        {
            RcfClient<I_Echo>( clientTransportAutoPtr->clone() ).getA(1);
            RCF_CHECK_FAIL();
        }
        catch(RCF::RemoteException &e)
        {
            std::string msg = e.what();
            RCF_CHECK_OK();
            RCF_CHECK_EQ(e.getErrorId() , RCF::RcfError_Serialization);
        }

        // inbound client serialization error
        try
        {
            RcfClient<I_Echo>( clientTransportAutoPtr->clone() ).getA(2);
            RCF_CHECK_FAIL();
        }
        catch(const RCF::Exception &e)
        {
            std::string msg = e.what();
            RCF_CHECK_OK();
            RCF_CHECK_EQ(e.getErrorId() , RCF::SfError_DataFormat);
        }

        //************************************************
        // returning non RCF error codes and strings, through RemoteException

        int myErrorCode = 12345;
        std::string myErrorString = "qwerty";
        try
        {
            RcfClient<I_Echo>( clientTransportAutoPtr->clone() )
                .throwRemoteException(myErrorCode, myErrorString);

            RCF_CHECK_FAIL();
        }
        catch(const RCF::RemoteException &e)
        {
            std::string msg = e.what();
            RCF_CHECK_OK();
            RCF_CHECK_EQ(e.getErrorId() , myErrorCode);
            //RCF_CHECK_EQ(e.what() , myErrorString);
            RCF_CHECK( std::string(e.what()).find(myErrorString) != std::string::npos);
        }

        //************************************************
        // throwing and catching RemoteException-derived exceptions across the wire

        for(int protocol=1; protocol<10; ++protocol)
        {
            RCF::SerializationProtocol sp = RCF::SerializationProtocol(protocol);
            if (RCF::isSerializationProtocolSupported(sp))
            {
                try
                {
                    RcfClient<I_Echo> client( clientTransportAutoPtr->clone() );
                    client.getClientStub().setSerializationProtocol(sp);
                    client.throwMyRemoteException(myErrorCode, myErrorString);
                    RCF_CHECK_FAIL();
                }
                catch(const MyRemoteException &e)
                {
                    std::string msg = e.what();
                    RCF_CHECK_OK();
                    RCF_CHECK_EQ(e.getErrorId() , myErrorCode);
                    RCF_CHECK_EQ(e.what() , myErrorString);
                }
                catch(const RCF::RemoteException &e)
                {
                    std::string msg = e.what();
                    RCF_CHECK_FAIL()(sp);
                    RCF_CHECK_EQ(e.getErrorId() , myErrorCode)(sp);
                    RCF_CHECK_EQ(e.what() , myErrorString)(sp);
                }
            }
        }

        //************************************************
        // catching non RemoteException-derived exception thrown on server

        for(int protocol=1; protocol<10; ++protocol)
        {
            RCF::SerializationProtocol sp = RCF::SerializationProtocol(protocol);
            if (RCF::isSerializationProtocolSupported(sp))
            {
                try
                {
                    RcfClient<I_Echo> client( clientTransportAutoPtr->clone() );
                    client.throwStdException(myErrorString);

                    RCF_CHECK_FAIL();
                }
                catch(const RCF::RemoteException &e)
                {
                    //std::string msg = e.what();
                    //RCF_CHECK_FAIL();
                    //RCF_CHECK_EQ(e.getErrorId() , myErrorCode);
                    //RCF_CHECK_EQ(e.what() , myErrorString);

                    RCF_CHECK_EQ(e.getErrorId() , RCF::RcfError_UserModeException);
                    std::string errorString = e.getErrorString();
                    RCF_CHECK( errorString.find(myErrorString) != errorString.npos );
                }
            }
        }



        //************************************************
        // message header errors (eg corruption)

        // TODO


        //************************************************
        // transport filter errors

        // TODO


        //************************************************
        // payload filter errors

        // TODO


    }


    return 0;
}
int test_main(int argc, char **argv)
{    

    printTestHeader(__FILE__);

    RCF::RcfInitDeinit rcfInitDeinit;

    using namespace Test_Polymorphic;

    util::CommandLine::getSingleton().parse(argc, argv);

    RCF_ASSERT( !RCF::getTransportFactories().empty() );

    RCF::TransportFactoryPtr transportFactoryPtr = RCF::getTransportFactories()[0];
    RCF::TransportPair transports = transportFactoryPtr->createTransports();
    RCF::ServerTransportPtr serverTransportPtr( transports.first );
    RCF::ClientTransportAutoPtr clientTransportAutoPtr( *transports.second );

    std::cout << transportFactoryPtr->desc() << std::endl;

    RCF::RcfServer server(serverTransportPtr);
   
    X x;
    Y y;
    Z z;
    server.bind( (I_X*) 0, x);
    server.bind( (I_Y*) 0, y);
    server.bind( (I_Z*) 0, z);
   
    server.start();

    for (int protocol=1; protocol<=2; ++protocol)
    {
        RCF::SerializationProtocol sp = RCF::SerializationProtocol(protocol);
        if (RCF::isSerializationProtocolSupported(sp))
        {
            std::string protocolName = RCF::getSerializationProtocolName(protocol);
            std::cout << "Testing serialization protocol: " << protocol << ": " << protocolName << std::endl;

            std::string s;

            RcfClient<I_X> xClient(clientTransportAutoPtr->clone());
            RcfClient<I_Y> yClient(clientTransportAutoPtr->clone());
            RcfClient<I_Z> zClient(clientTransportAutoPtr->clone());

            xClient.getClientStub().setSerializationProtocol(sp);
            yClient.getClientStub().setSerializationProtocol(sp);
            zClient.getClientStub().setSerializationProtocol(sp);

            {
                boost::shared_ptr<A> pa(new A);
                boost::shared_ptr<A> pb(new B);
                boost::shared_ptr<A> pc(new C);

                s = xClient.f1(pa.get()); RCF_CHECK_EQ(s , typeid(A).name() );
                s = xClient.f1(pb.get()); RCF_CHECK_EQ(s , typeid(B).name() );
                s = xClient.f1(pc.get()); RCF_CHECK_EQ(s , typeid(C).name() );

                // Top level polymorphic serialization no longer supported as of
                // runtime version 8 (RCF 1.3). But we're still fully backwards 
                // compatible.

                int ver = yClient.getClientStub().getRuntimeVersion();
                yClient.getClientStub().setRuntimeVersion(7);

                s = yClient.f1(*pa); RCF_CHECK_EQ(s , typeid(A).name() );
                s = yClient.f1(*pb); RCF_CHECK_EQ(s , typeid(B).name() );
                s = yClient.f1(*pc); RCF_CHECK_EQ(s , typeid(C).name() );

                yClient.getClientStub().setRuntimeVersion(7);

                s = zClient.f1(pa); RCF_CHECK_EQ(s , typeid(A).name() );
                s = zClient.f1(pb); RCF_CHECK_EQ(s , typeid(B).name() );
                s = zClient.f1(pc); RCF_CHECK_EQ(s , typeid(C).name() );
            }
            {
                boost::shared_ptr<A> spa;
                spa = zClient.f2( typeid(B).name() ); RCF_CHECK( dynamic_cast<B *>(spa.get()) != NULL );
                spa = zClient.f2( typeid(C).name() ); RCF_CHECK( dynamic_cast<C *>(spa.get()) != NULL );
            }
            {
                A *pa = NULL;
                //xClient.f3(typeid(B).name(), pa); RCF_CHECK( dynamic_cast<B *>(pa) != NULL );
                //xClient.f3(typeid(C).name(), pa); RCF_CHECK( dynamic_cast<C *>(pa) != NULL );

                boost::shared_ptr<A> spa;
                zClient.f3(typeid(B).name(), spa); RCF_CHECK( dynamic_cast<B *>(spa.get()) != NULL );
                zClient.f3(typeid(C).name(), spa); RCF_CHECK( dynamic_cast<C *>(spa.get()) != NULL );
            }
        }
    }
           
    return 0;
}
int test_main(int argc, char **argv)
{

    printTestHeader(__FILE__);

    RCF::RcfInitDeinit rcfInitDeinit;

    using namespace Test_ClientInfo;

    util::CommandLine::getSingleton().parse(argc, argv);

    for (std::size_t i=0; i<RCF::getIpTransportFactories().size(); ++i)
    {
        RCF::TransportFactoryPtr transportFactoryPtr = RCF::getIpTransportFactories()[i];
        RCF::TransportPair transports = transportFactoryPtr->createTransports();
        RCF::ServerTransportPtr serverTransportPtr( transports.first );
        RCF::ClientTransportAutoPtr clientTransportAutoPtr( *transports.second );

        std::cout << transportFactoryPtr->desc() << std::endl;

        GetMyAddress getMyAddress;
        RCF::RcfServer server(serverTransportPtr);
        server.bind( (I_GetMyAddress*) 0, getMyAddress);
        server.start();

#if defined(_MSC_VER) && _MSC_VER < 1310
        std::pair<std::string, int> myAddress = RcfClient<I_GetMyAddress>(clientTransportAutoPtr).getMyAddress(RCF::Twoway).get();
#else
        std::pair<std::string, int> myAddress = RcfClient<I_GetMyAddress>(clientTransportAutoPtr).getMyAddress(RCF::Twoway);
#endif

        RCF_CHECK(myAddress.first == "127.0.0.1" || myAddress.first == "::1");
        RCF_CHECK_GT(myAddress.second, 0);
    }

    // Check that we can get native handles for the underlying I/O objects.
    for (std::size_t i=0; i<RCF::getTransportFactories().size(); ++i)
    {
        RCF::TransportFactoryPtr transportFactoryPtr = RCF::getTransportFactories()[i];
        RCF::TransportPair transports = transportFactoryPtr->createTransports();
        RCF::ServerTransportPtr serverTransportPtr( transports.first );
        RCF::ClientTransportAutoPtr clientTransportAutoPtr( *transports.second );

        std::cout << transportFactoryPtr->desc() << std::endl;

        GetMyAddress getMyAddress;
        RCF::RcfServer server(serverTransportPtr);
        server.bind( (I_GetMyAddress*) 0, getMyAddress);
        server.start();


        RcfClient<I_GetMyAddress> client(clientTransportAutoPtr);

        // Check that we can get server side native handles.
        client.checkServerHandle();


        // Check that we can get client side native handles.
        RCF::TcpClientTransport *pTcpClientTransport = 
            dynamic_cast<RCF::TcpClientTransport *>( 
                & client.getClientStub().getTransport() );

        if (pTcpClientTransport)
        {
            int clientHandle = pTcpClientTransport->getNativeHandle();
            RCF_CHECK(clientHandle != 0 && clientHandle != -1);
            continue;
        }

        RCF::UdpClientTransport *pUdpClientTransport = 
            dynamic_cast<RCF::UdpClientTransport *>( 
                & client.getClientStub().getTransport() );

        if (pUdpClientTransport)
        {
            int clientHandle = pUdpClientTransport->getNativeHandle();
            RCF_CHECK(clientHandle != 0 && clientHandle != -1);
            continue;
        }

#ifdef BOOST_WINDOWS

        RCF::Win32NamedPipeClientTransport *pWin32PipeClientTransport = 
            dynamic_cast<RCF::Win32NamedPipeClientTransport *>( 
                & client.getClientStub().getTransport() );

        if (pWin32PipeClientTransport)
        {
            HANDLE clientHandle = pWin32PipeClientTransport->getNativeHandle();
            RCF_CHECK(clientHandle != 0);
            continue;
        }

#endif

#if defined(RCF_USE_BOOST_ASIO) && defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)

        RCF::UnixLocalClientTransport *pUnixLocalClientTransport = 
            dynamic_cast<RCF::UnixLocalClientTransport *>( 
                & client.getClientStub().getTransport() );

        if (pUnixLocalClientTransport)
        {
            int clientHandle = pUnixLocalClientTransport->getNativeHandle();
            RCF_CHECK(clientHandle != 0 && clientHandle != -1);
            continue;
        }


#endif

        RCF_CHECK_EQ(1 , 0);

    }
   
    return 0;
}