MockAsyncSocket.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #include <folly/io/async/AsyncSocket.h>
  18. #include <folly/io/async/EventBase.h>
  19. #include <folly/portability/GMock.h>
  20. namespace folly {
  21. namespace test {
  22. class MockAsyncSocket : public AsyncSocket {
  23. public:
  24. typedef std::unique_ptr<MockAsyncSocket, Destructor> UniquePtr;
  25. explicit MockAsyncSocket(EventBase* base) : AsyncSocket(base) {}
  26. MOCK_METHOD5(
  27. connect_,
  28. void(
  29. AsyncSocket::ConnectCallback*,
  30. const folly::SocketAddress&,
  31. int,
  32. const OptionMap&,
  33. const folly::SocketAddress&));
  34. void connect(
  35. AsyncSocket::ConnectCallback* callback,
  36. const folly::SocketAddress& address,
  37. int timeout,
  38. const OptionMap& options,
  39. const folly::SocketAddress& bindAddr) noexcept override {
  40. connect_(callback, address, timeout, options, bindAddr);
  41. }
  42. MOCK_CONST_METHOD1(getPeerAddress, void(folly::SocketAddress*));
  43. MOCK_METHOD0(detachFd, int());
  44. MOCK_CONST_METHOD0(getFd, int());
  45. MOCK_METHOD0(closeNow, void());
  46. MOCK_CONST_METHOD0(good, bool());
  47. MOCK_CONST_METHOD0(readable, bool());
  48. MOCK_CONST_METHOD0(hangup, bool());
  49. MOCK_CONST_METHOD1(getLocalAddress, void(SocketAddress*));
  50. MOCK_METHOD1(setReadCB, void(ReadCallback*));
  51. MOCK_METHOD1(_setPreReceivedData, void(std::unique_ptr<IOBuf>&));
  52. MOCK_CONST_METHOD0(getRawBytesWritten, size_t());
  53. MOCK_METHOD4(setSockOptVirtual, int(int, int, void const*, socklen_t));
  54. MOCK_METHOD1(setErrMessageCB, void(AsyncSocket::ErrMessageCallback*));
  55. MOCK_METHOD1(setSendMsgParamCB, void(AsyncSocket::SendMsgParamsCallback*));
  56. void setPreReceivedData(std::unique_ptr<IOBuf> data) override {
  57. return _setPreReceivedData(data);
  58. }
  59. };
  60. } // namespace test
  61. } // namespace folly