Skip to content

Commit

Permalink
Make MockAsyncUDPSocket usable with intermediate types
Browse files Browse the repository at this point in the history
Summary: Make it possible to use `MockAsyncUDPSocket` in cases where the type to be mocked inherits from `AsyncUDPSocket` by templating the class and defining a default.

Differential Revision: D48717389

fbshipit-source-id: b0907d18b887ebe6703f8367b243d7f88414a0d5
  • Loading branch information
Brandon Schlinker authored and facebook-github-bot committed Sep 21, 2023
1 parent 62d8697 commit f52e6aa
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions folly/io/async/test/MockAsyncUDPSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
namespace folly {
namespace test {

struct MockAsyncUDPSocket : public AsyncUDPSocket {
explicit MockAsyncUDPSocket(EventBase* evb) : AsyncUDPSocket(evb) {}
~MockAsyncUDPSocket() override {}
template <typename Base = AsyncUDPSocket>
struct MockAsyncUDPSocketT : public Base {
explicit MockAsyncUDPSocketT(EventBase* evb) : Base(evb) {}
~MockAsyncUDPSocketT() override {}

MOCK_METHOD(const SocketAddress&, address, (), (const));
MOCK_METHOD(
Expand All @@ -48,15 +49,18 @@ struct MockAsyncUDPSocket : public AsyncUDPSocket {
folly::AsyncUDPSocket::WriteOptions));
MOCK_METHOD(
ssize_t, writev, (const SocketAddress&, const struct iovec*, size_t));
MOCK_METHOD(void, resumeRead, (ReadCallback*));
MOCK_METHOD(void, resumeRead, (folly::AsyncUDPSocket::ReadCallback*));
MOCK_METHOD(void, pauseRead, ());
MOCK_METHOD(void, close, ());
MOCK_METHOD(void, setDFAndTurnOffPMTU, ());
MOCK_METHOD(NetworkSocket, getNetworkSocket, (), (const));
MOCK_METHOD(void, setReusePort, (bool));
MOCK_METHOD(void, setReuseAddr, (bool));
MOCK_METHOD(void, dontFragment, (bool));
MOCK_METHOD(void, setErrMessageCallback, (ErrMessageCallback*));
MOCK_METHOD(
void,
setErrMessageCallback,
(folly::AsyncUDPSocket::ErrMessageCallback*));
MOCK_METHOD(void, connect, (const SocketAddress&));
MOCK_METHOD(bool, isBound, (), (const));
MOCK_METHOD(int, getGSO, ());
Expand All @@ -78,5 +82,7 @@ struct MockAsyncUDPSocket : public AsyncUDPSocket {
(const SocketNontrivialOptionMap&, SocketOptionKey::ApplyPos));
};

using MockAsyncUDPSocket = MockAsyncUDPSocketT<>;

} // namespace test
} // namespace folly

0 comments on commit f52e6aa

Please sign in to comment.