mock_async_resolver.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright 2018 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef P2P_BASE_MOCK_ASYNC_RESOLVER_H_
  11. #define P2P_BASE_MOCK_ASYNC_RESOLVER_H_
  12. #include "api/async_resolver_factory.h"
  13. #include "rtc_base/async_resolver_interface.h"
  14. #include "test/gmock.h"
  15. namespace rtc {
  16. using ::testing::_;
  17. using ::testing::InvokeWithoutArgs;
  18. class MockAsyncResolver : public AsyncResolverInterface {
  19. public:
  20. MockAsyncResolver() {
  21. ON_CALL(*this, Start(_)).WillByDefault(InvokeWithoutArgs([this] {
  22. SignalDone(this);
  23. }));
  24. }
  25. ~MockAsyncResolver() = default;
  26. MOCK_METHOD(void, Start, (const rtc::SocketAddress&), (override));
  27. MOCK_METHOD(bool,
  28. GetResolvedAddress,
  29. (int family, SocketAddress* addr),
  30. (const, override));
  31. MOCK_METHOD(int, GetError, (), (const, override));
  32. // Note that this won't delete the object like AsyncResolverInterface says in
  33. // order to avoid sanitizer failures caused by this being a synchronous
  34. // implementation. The test code should delete the object instead.
  35. MOCK_METHOD(void, Destroy, (bool), (override));
  36. };
  37. } // namespace rtc
  38. namespace webrtc {
  39. class MockAsyncResolverFactory : public AsyncResolverFactory {
  40. public:
  41. MOCK_METHOD(rtc::AsyncResolverInterface*, Create, (), (override));
  42. };
  43. } // namespace webrtc
  44. #endif // P2P_BASE_MOCK_ASYNC_RESOLVER_H_