//////////////////////////////////////////////////////////// // 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)); }
void testMessageheaderParserSize() { tnt::Messageheader mh; tnt::Messageheader::Parser parser(mh); for (unsigned c = 0; c < tnt::Messageheader::MAXHEADERSIZE - 1; ++c) parser.parse('A'); CXXTOOLS_UNIT_ASSERT_THROW(parser.parse('B'), tnt::HttpError); }
//////////////////////////////////////////////////////////// // UnknownMethod // void UnknownMethod() { cxxtools::bin::RpcClient client(_loop, "", _port); cxxtools::RemoteProcedure<bool> unknownMethod(client, "unknownMethod"); unknownMethod.begin(); CXXTOOLS_UNIT_ASSERT_THROW(unknownMethod.end(2000), cxxtools::RemoteException); }
//////////////////////////////////////////////////////////// // WrongDomain // void WrongDomain() { cxxtools::ServiceRegistry registry; registry.registerMethod("multiply", *this, &BinRpcTest::multiplyInt); _server->addService("myDomain", registry); cxxtools::bin::RpcClient client(_loop, "", _port, "unknownDomain"); cxxtools::RemoteProcedure<int, int, int> multiply(client, "multiply"); multiply.begin(2, 3); CXXTOOLS_UNIT_ASSERT_THROW(multiply.end(2000), cxxtools::RemoteException); }
//////////////////////////////////////////////////////////// // CallbackException // void CallbackException() { _server->registerMethod("multiply", *this, &BinRpcTest::multiplyNothing); cxxtools::bin::RpcClient client(_loop, "", _port); cxxtools::RemoteProcedure<bool> multiply(client, "multiply"); connect( multiply.finished, *this, &BinRpcTest::onExceptionCallback ); multiply.begin(); _count = 0; CXXTOOLS_UNIT_ASSERT_THROW(_loop.run(), std::runtime_error); CXXTOOLS_UNIT_ASSERT_EQUALS(_count, 1); }
void onConnectErrorCallback(cxxtools::RemoteResult<bool>& r) { log_debug("onConnectErrorCallback"); _loop.exit(); CXXTOOLS_UNIT_ASSERT_THROW(r.get(), std::exception); }