Ejemplo n.º 1
0
    MockStreamDescriptor(boost::asio::io_service& ioService):
            ioService(ioService) {}

    MOCK_METHOD(cancel, 1, void(boost::system::error_code&));
    METHOD_WITH_ERROR(cancel)

    MOCK_METHOD(close, 1, void(boost::system::error_code&));
    METHOD_WITH_ERROR(close)

    using AsyncReadResult = std::pair<boost::system::error_code, std::size_t>;
    MOCK_METHOD(doAsyncRead, 0, AsyncReadResult());
    template <typename Buffer, typename Callback>
    void async_read_some(const Buffer&, const Callback& callback)
    {
        auto result = doAsyncRead();
        ioService.post(std::bind(callback, result.first, result.second));
    }

    MOCK_METHOD(native_handle, 0, native_handle_type());
    MOCK_METHOD(is_open, 0, bool());

    boost::asio::io_service& ioService;
};

}

#undef METHOD_WITH_ERROR

#endif /* UNITTEST_MOCKSTREAMDESCRIPTOR_HPP */
Ejemplo n.º 2
0
 // Get the native socket representation.
 native_handle_type native_handle(implementation_type& impl)
 {
   if (impl.have_remote_endpoint_)
     return native_handle_type(impl.socket_, impl.remote_endpoint_);
   return native_handle_type(impl.socket_);
 }