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 
11 #ifndef P2P_BASE_MOCK_ASYNC_RESOLVER_H_
12 #define P2P_BASE_MOCK_ASYNC_RESOLVER_H_
13 
14 #include "api/async_resolver_factory.h"
15 #include "rtc_base/async_resolver_interface.h"
16 #include "test/gmock.h"
17 
18 namespace rtc {
19 
20 using ::testing::_;
21 using ::testing::InvokeWithoutArgs;
22 
23 class MockAsyncResolver : public AsyncResolverInterface {
24  public:
MockAsyncResolver()25   MockAsyncResolver() {
26     ON_CALL(*this, Start(_)).WillByDefault(InvokeWithoutArgs([this] {
27       SignalDone(this);
28     }));
29   }
30   ~MockAsyncResolver() = default;
31 
32   MOCK_METHOD(void, Start, (const rtc::SocketAddress&), (override));
33   MOCK_METHOD(bool,
34               GetResolvedAddress,
35               (int family, SocketAddress* addr),
36               (const, override));
37   MOCK_METHOD(int, GetError, (), (const, override));
38 
39   // Note that this won't delete the object like AsyncResolverInterface says in
40   // order to avoid sanitizer failures caused by this being a synchronous
41   // implementation. The test code should delete the object instead.
42   MOCK_METHOD(void, Destroy, (bool), (override));
43 };
44 
45 }  // namespace rtc
46 
47 namespace webrtc {
48 
49 class MockAsyncResolverFactory : public AsyncResolverFactory {
50  public:
51   MOCK_METHOD(rtc::AsyncResolverInterface*, Create, (), (override));
52 };
53 
54 }  // namespace webrtc
55 
56 #endif  // P2P_BASE_MOCK_ASYNC_RESOLVER_H_
57