Example #1
0
        ////////////////////////////////////////////////////////////
        // PrepareConnect
        //
        void PrepareConnect()
        {
            log_trace("PrepareConnect");

            _server->registerMethod("boolean", *this, &BinRpcTest::boolean);

            // test connect using cxxtools::net::AddrInfo
            {
                cxxtools::bin::RpcClient client(_loop);
                cxxtools::RemoteProcedure<bool, bool, bool> boolean(client, "boolean");

                client.prepareConnect(cxxtools::net::AddrInfo("", _port));
                boolean.begin(true, true);
                CXXTOOLS_UNIT_ASSERT_EQUALS(boolean.end(2000), true);
            }

            // test connect using host and port
            {
                cxxtools::bin::RpcClient client(_loop);
                cxxtools::RemoteProcedure<bool, bool, bool> boolean(client, "boolean");

                client.prepareConnect("", _port);
                boolean.begin(true, true);
                CXXTOOLS_UNIT_ASSERT_EQUALS(boolean.end(2000), true);
            }

            // test connect using uri
            {
                cxxtools::bin::RpcClient client(_loop);
                cxxtools::RemoteProcedure<bool, bool, bool> boolean(client, "boolean");

                std::ostringstream uri;
                uri << "http://localhost:" << _port << '/';
                client.prepareConnect(cxxtools::net::Uri(uri.str()));
                boolean.begin(true, true);
                CXXTOOLS_UNIT_ASSERT_EQUALS(boolean.end(2000), true);
            }

            // test failing connect in connect
            {
                cxxtools::bin::RpcClient client(_loop);
                cxxtools::RemoteProcedure<bool, bool, bool> boolean(client, "boolean");

                CXXTOOLS_UNIT_ASSERT_NOTHROW(client.prepareConnect("", _port + 1));
                CXXTOOLS_UNIT_ASSERT_THROW(client.connect(), cxxtools::IOError);
            }

            // test failing connect when calling function
            {
                cxxtools::bin::RpcClient client(_loop);
                cxxtools::RemoteProcedure<bool, bool, bool> boolean(client, "boolean");
                CXXTOOLS_UNIT_ASSERT_NOTHROW(client.prepareConnect("", _port + 1));

                boolean.begin(true, true);
                CXXTOOLS_UNIT_ASSERT_THROW(boolean.end(2000), cxxtools::IOError);
            }

        }
        void testRangeCheck()
        {
            cxxtools::SerializationInfo si;
            si.setValue(-1);
            CXXTOOLS_UNIT_ASSERT_THROW(siValue<unsigned short>(si), std::range_error);
            CXXTOOLS_UNIT_ASSERT_THROW(siValue<unsigned>(si), std::range_error);
            CXXTOOLS_UNIT_ASSERT_THROW(siValue<unsigned long>(si), std::range_error);

            si.setValue(static_cast<long>(std::numeric_limits<short>::max()) + 1);
            CXXTOOLS_UNIT_ASSERT_THROW(siValue<short>(si), std::range_error);
            CXXTOOLS_UNIT_ASSERT_NOTHROW(siValue<long>(si));
        }