/* * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ #pragma once #include #include namespace quic { class MockQuicSocket : public QuicSocket { public: using SharedBuf = std::shared_ptr; MockQuicSocket(folly::EventBase* /*eventBase*/, ConnectionCallback& cb) : cb_(&cb) {} MOCK_CONST_METHOD0(good, bool()); MOCK_CONST_METHOD0(replaySafe, bool()); MOCK_CONST_METHOD0(error, bool()); MOCK_METHOD1( close, void(folly::Optional>)); MOCK_METHOD0(closeGracefully, void()); MOCK_METHOD1( closeNow, void(folly::Optional>)); MOCK_CONST_METHOD0( getClientConnectionId, folly::Optional()); MOCK_CONST_METHOD0(getTransportSettings, const TransportSettings&()); MOCK_CONST_METHOD0( getServerConnectionId, folly::Optional()); MOCK_CONST_METHOD0( getClientChosenDestConnectionId, folly::Optional()); MOCK_CONST_METHOD0(getPeerAddress, const folly::SocketAddress&()); MOCK_CONST_METHOD0(getOriginalPeerAddress, const folly::SocketAddress&()); MOCK_CONST_METHOD0(getLocalAddress, const folly::SocketAddress&()); MOCK_CONST_METHOD0(getEventBase, folly::EventBase*()); MOCK_CONST_METHOD1( getStreamReadOffset, folly::Expected(StreamId)); MOCK_CONST_METHOD1( getStreamWriteOffset, folly::Expected(StreamId)); MOCK_CONST_METHOD1( getStreamWriteBufferedBytes, folly::Expected(StreamId)); MOCK_CONST_METHOD0(getTransportInfo, QuicSocket::TransportInfo()); MOCK_CONST_METHOD1( getStreamTransportInfo, folly::Expected( StreamId)); MOCK_CONST_METHOD0(getAppProtocol, folly::Optional()); MOCK_METHOD2(setReceiveWindow, void(StreamId, size_t)); MOCK_METHOD3(setSendBuffer, void(StreamId, size_t, size_t)); MOCK_CONST_METHOD0(getConnectionBufferAvailable, uint64_t()); MOCK_CONST_METHOD0( getConnectionFlowControl, folly::Expected()); MOCK_CONST_METHOD1( getStreamFlowControl, folly::Expected(StreamId)); MOCK_METHOD0(unsetAllReadCallbacks, void()); MOCK_METHOD0(unsetAllPeekCallbacks, void()); MOCK_METHOD0(unsetAllDeliveryCallbacks, void()); MOCK_METHOD1(cancelDeliveryCallbacksForStream, void(StreamId)); MOCK_METHOD2( cancelDeliveryCallbacksForStream, void(StreamId, uint64_t offset)); MOCK_METHOD1( setConnectionFlowControlWindow, folly::Expected(uint64_t)); MOCK_METHOD2( setStreamFlowControlWindow, folly::Expected(StreamId, uint64_t)); MOCK_METHOD1(setTransportSettings, void(TransportSettings)); MOCK_CONST_METHOD0(isPartiallyReliableTransport, bool()); MOCK_METHOD2( setReadCallback, folly::Expected(StreamId, ReadCallback*)); MOCK_METHOD1(setConnectionCallback, void(ConnectionCallback*)); void setEarlyDataAppParamsFunctions( folly::Function&, const Buf&) const> validator, folly::Function getter) override { earlyDataAppParamsValidator_ = std::move(validator); earlyDataAppParamsGetter_ = std::move(getter); } MOCK_METHOD1( pauseRead, folly::Expected(StreamId)); MOCK_METHOD1( resumeRead, folly::Expected(StreamId)); MOCK_METHOD2( stopSending, folly::Expected( StreamId, ApplicationErrorCode)); folly::Expected, LocalErrorCode> read( StreamId id, size_t maxRead) override { auto res = readNaked(id, maxRead); if (res.hasError()) { return folly::makeUnexpected(res.error()); } else { return std::pair(Buf(res.value().first), res.value().second); } } using ReadResult = folly::Expected, LocalErrorCode>; MOCK_METHOD2(readNaked, ReadResult(StreamId, size_t)); MOCK_METHOD1( createBidirectionalStream, folly::Expected(bool)); MOCK_METHOD1( createUnidirectionalStream, folly::Expected(bool)); MOCK_CONST_METHOD0(getNumOpenableBidirectionalStreams, uint64_t()); MOCK_CONST_METHOD0(getNumOpenableUnidirectionalStreams, uint64_t()); GMOCK_METHOD1_(, noexcept, , isClientStream, bool(StreamId)); GMOCK_METHOD1_(, noexcept, , isServerStream, bool(StreamId)); GMOCK_METHOD1_(, noexcept, , isBidirectionalStream, bool(StreamId)); GMOCK_METHOD1_(, noexcept, , isUnidirectionalStream, bool(StreamId)); MOCK_METHOD1( notifyPendingWriteOnConnection, folly::Expected(WriteCallback*)); MOCK_METHOD2( notifyPendingWriteOnStream, folly::Expected(StreamId, WriteCallback*)); MOCK_METHOD1( unregisterStreamWriteCallback, folly::Expected(StreamId)); folly::Expected writeChain( StreamId id, Buf data, bool eof, bool cork, DeliveryCallback* cb) override { SharedBuf sharedData(data.release()); auto res = writeChain(id, sharedData, eof, cork, cb); if (res.hasError()) { return folly::makeUnexpected(res.error()); } else { return Buf(res.value()); } } using WriteResult = folly::Expected; MOCK_METHOD5( writeChain, WriteResult(StreamId, SharedBuf, bool, bool, DeliveryCallback*)); MOCK_METHOD3( registerDeliveryCallback, folly::Expected( StreamId, uint64_t, DeliveryCallback*)); MOCK_METHOD1(shutdownWrite, folly::Optional(StreamId)); MOCK_METHOD2( resetStream, folly::Expected( StreamId, ApplicationErrorCode)); MOCK_METHOD2( maybeResetStreamFromReadError, folly::Expected(StreamId, QuicErrorCode)); MOCK_METHOD2(sendPing, void(PingCallback*, std::chrono::milliseconds)); MOCK_CONST_METHOD0(getState, const QuicConnectionStateBase*()); MOCK_METHOD0(isDetachable, bool()); MOCK_METHOD1(attachEventBase, void(folly::EventBase*)); MOCK_METHOD0(detachEventBase, void()); MOCK_METHOD1(setControlStream, folly::Optional(StreamId)); MOCK_METHOD2( setPeekCallback, folly::Expected(StreamId, PeekCallback*)); MOCK_METHOD1( pausePeek, folly::Expected(StreamId)); MOCK_METHOD1( resumePeek, folly::Expected(StreamId)); MOCK_METHOD2( peek, folly::Expected( StreamId, const folly::Function< void(StreamId, const folly::Range&) const>&)); MOCK_METHOD3( consume, folly::Expected< folly::Unit, std::pair>>( StreamId, uint64_t, size_t)); MOCK_METHOD2( consume, folly::Expected(StreamId, size_t)); MOCK_METHOD2( setDataExpiredCallback, folly::Expected( StreamId, DataExpiredCallback*)); MOCK_METHOD2( sendDataExpired, folly::Expected, LocalErrorCode>( StreamId, uint64_t offset)); MOCK_METHOD2( setDataRejectedCallback, folly::Expected( StreamId, DataRejectedCallback*)); MOCK_METHOD2( sendDataRejected, folly::Expected, LocalErrorCode>( StreamId, uint64_t offset)); MOCK_METHOD1(setCongestionControl, void(CongestionControlType)); ConnectionCallback* cb_; folly::Function&, const Buf&)> earlyDataAppParamsValidator_; folly::Function earlyDataAppParamsGetter_; }; } // namespace quic