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