Coverage Report

Created: 2023-11-12 09:30

/proc/self/cwd/test/common/network/listener_impl_test_base.h
Line
Count
Source (jump to first uncovered line)
1
#pragma once
2
3
#include "source/common/event/dispatcher_impl.h"
4
#include "source/common/network/address_impl.h"
5
#include "source/common/network/utility.h"
6
7
#include "test/test_common/network_utility.h"
8
#include "test/test_common/simulated_time_system.h"
9
#include "test/test_common/test_time.h"
10
#include "test/test_common/utility.h"
11
12
#include "gtest/gtest.h"
13
14
namespace Envoy {
15
namespace Network {
16
17
// Captures common infrastructure needed by both ListenerImplTest and UdpListenerImplTest.
18
class ListenerImplTestBase : public testing::TestWithParam<Address::IpVersion> {
19
protected:
20
  ListenerImplTestBase()
21
      : version_(GetParam()),
22
        alt_address_(Network::Test::findOrCheckFreePort(
23
            Network::Test::getCanonicalLoopbackAddress(version_), Socket::Type::Stream)),
24
0
        api_(Api::createApiForTest()), dispatcher_(api_->allocateDispatcher("test_thread")) {}
25
26
0
  Event::DispatcherImpl& dispatcherImpl() {
27
0
    // We need access to the concrete impl type in order to instantiate a
28
0
    // Test[Udp]Listener, which instantiates a [Udp]ListenerImpl, which requires
29
0
    // a DispatcherImpl to access DispatcherImpl::base_, which is not part of
30
0
    // the Dispatcher API.
31
0
    Event::DispatcherImpl* impl = dynamic_cast<Event::DispatcherImpl*>(dispatcher_.get());
32
0
    RELEASE_ASSERT(impl, "dispatcher dynamic-cast to DispatcherImpl failed");
33
0
    return *impl;
34
0
  }
35
36
  const Address::IpVersion version_;
37
  const Address::InstanceConstSharedPtr alt_address_;
38
  Event::SimulatedTimeSystem time_system_;
39
  Api::ApiPtr api_;
40
  Event::DispatcherPtr dispatcher_;
41
};
42
43
} // namespace Network
44
} // namespace Envoy