blob: 8f18e9b0e1505d1b67e9ebb597318f2725fdcb5f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
/*
* Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef P2P_BASE_MOCK_DNS_RESOLVING_PACKET_SOCKET_FACTORY_H_
#define P2P_BASE_MOCK_DNS_RESOLVING_PACKET_SOCKET_FACTORY_H_
#include <functional>
#include <memory>
#include "api/test/mock_async_dns_resolver.h"
#include "p2p/base/basic_packet_socket_factory.h"
namespace rtc {
// A PacketSocketFactory implementation for tests that uses a mock DnsResolver
// and allows setting expectations on the resolver and results.
class MockDnsResolvingPacketSocketFactory : public BasicPacketSocketFactory {
public:
using Expectations = std::function<void(webrtc::MockAsyncDnsResolver*,
webrtc::MockAsyncDnsResolverResult*)>;
explicit MockDnsResolvingPacketSocketFactory(SocketFactory* socket_factory)
: BasicPacketSocketFactory(socket_factory) {}
std::unique_ptr<webrtc::AsyncDnsResolverInterface> CreateAsyncDnsResolver()
override {
std::unique_ptr<webrtc::MockAsyncDnsResolver> resolver =
std::make_unique<webrtc::MockAsyncDnsResolver>();
if (expectations_) {
expectations_(resolver.get(), &resolver_result_);
}
return resolver;
}
void SetExpectations(Expectations expectations) {
expectations_ = expectations;
}
private:
webrtc::MockAsyncDnsResolverResult resolver_result_;
Expectations expectations_;
};
} // namespace rtc
#endif // P2P_BASE_MOCK_DNS_RESOLVING_PACKET_SOCKET_FACTORY_H_
|