proxygen
MockAsyncSocket.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
21 
22 namespace folly {
23 
24 namespace test {
25 
26 class MockAsyncSocket : public AsyncSocket {
27  public:
28  typedef std::unique_ptr<MockAsyncSocket, Destructor> UniquePtr;
29 
30  explicit MockAsyncSocket(EventBase* base) : AsyncSocket(base) {}
31 
33  connect_,
34  void(
36  const folly::SocketAddress&,
37  int,
38  const OptionMap&,
39  const folly::SocketAddress&));
40  void connect(
42  const folly::SocketAddress& address,
43  int timeout,
44  const OptionMap& options,
45  const folly::SocketAddress& bindAddr) noexcept override {
46  connect_(callback, address, timeout, options, bindAddr);
47  }
48 
50  MOCK_METHOD0(detachFd, int());
51  MOCK_CONST_METHOD0(getFd, int());
52  MOCK_METHOD0(closeNow, void());
53  MOCK_CONST_METHOD0(good, bool());
55  MOCK_CONST_METHOD0(hangup, bool());
58  MOCK_METHOD1(_setPreReceivedData, void(std::unique_ptr<IOBuf>&));
60  MOCK_METHOD4(setSockOptVirtual, int(int, int, void const*, socklen_t));
63  void setPreReceivedData(std::unique_ptr<IOBuf> data) override {
64  return _setPreReceivedData(data);
65  }
66 };
67 
68 } // namespace test
69 } // namespace folly
MOCK_METHOD0(detachFd, int())
virtual int detachFd()
MOCK_CONST_METHOD0(getFd, int())
virtual bool hangup() const
void connect(AsyncSocket::ConnectCallback *callback, const folly::SocketAddress &address, int timeout, const OptionMap &options, const folly::SocketAddress &bindAddr) noexceptoverride
size_t getRawBytesWritten() const override
Definition: AsyncSocket.h:587
virtual void setErrMessageCB(ErrMessageCallback *callback)
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
requires E e noexcept(noexcept(s.error(std::move(e))))
void closeNow() override
virtual void setSendMsgParamCB(SendMsgParamsCallback *callback)
std::map< OptionKey, int > OptionMap
Definition: AsyncSocket.h:376
SocketAddress getPeerAddress() const
MOCK_METHOD5(connect_, void(AsyncSocket::ConnectCallback *, const folly::SocketAddress &, int, const OptionMap &, const folly::SocketAddress &))
constexpr auto data(C &c) -> decltype(c.data())
Definition: Access.h:71
MockAsyncSocket(EventBase *base)
bool good() const override
MOCK_METHOD1(setReadCB, void(ReadCallback *))
MOCK_METHOD4(setSockOptVirtual, int(int, int, void const *, socklen_t))
virtual int getFd() const
Definition: AsyncSocket.h:335
MOCK_CONST_METHOD1(getPeerAddress, void(folly::SocketAddress *))
SocketAddress getLocalAddress() const
void setReadCB(ReadCallback *callback) override
void setPreReceivedData(std::unique_ptr< IOBuf > data) override
std::unique_ptr< MockAsyncSocket, Destructor > UniquePtr
bool readable() const override
virtual int setSockOptVirtual(int level, int optname, void const *optval, socklen_t optlen)
Definition: AsyncSocket.h:758