Bug Summary

File:usr/src/googletest/googletest/include/gtest/gtest.h
Warning:line 1472, column 1
An undefined value may be read from 'errno'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-redhat-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name iface_mgr_unittest.cc -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/home/fedora/workspace/kea-dev/clang-static-analyzer/build/meson-private/tmpz0p224zs -fcoverage-compilation-dir=/home/fedora/workspace/kea-dev/clang-static-analyzer/build/meson-private/tmpz0p224zs -resource-dir /usr/bin/../lib/clang/22 -I src/lib/dhcp/tests/kea-dhcp-tests.p -I src/lib/dhcp/tests -I ../../../src/lib/dhcp/tests -I . -I ../../.. -I src -I ../../../src -I src/bin -I ../../../src/bin -I src/lib -I ../../../src/lib -I /usr/src/googletest/googletest -I /usr/src/googletest/googletest/include -I /usr/include -D _GLIBCXX_ASSERTIONS=1 -D _FILE_OFFSET_BITS=64 -D BOOST_ALL_NO_LIB -D TEST_DATA_BUILDDIR="/home/fedora/workspace/kea-dev/clang-static-analyzer/build/meson-private/tmpz0p224zs/src/lib/dhcp/tests" -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16/backward -internal-isystem /usr/bin/../lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wwrite-strings -Wno-missing-field-initializers -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -fdwarf2-cfi-asm -o /home/fedora/workspace/kea-dev/clang-static-analyzer/build/meson-logs/scanbuild/2026-06-18-163926-5114-1 -x c++ ../../../src/lib/dhcp/tests/iface_mgr_unittest.cc

../../../src/lib/dhcp/tests/iface_mgr_unittest.cc

1// Copyright (C) 2011-2026 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
9#include <asiolink/io_address.h>
10#include <dhcp/dhcp4.h>
11#include <dhcp/iface_mgr.h>
12#include <dhcp/option.h>
13#include <dhcp/pkt6.h>
14#include <dhcp/pkt_filter.h>
15#include <dhcp/pkt_filter_inet.h>
16#include <dhcp/pkt_filter_inet6.h>
17#include <dhcp/testutils/iface_mgr_test_config.h>
18#include <dhcp/tests/pkt_filter_iface_test_utils.h>
19#include <dhcp/tests/pkt_filter_test_utils.h>
20#include <dhcp/tests/pkt_filter6_test_utils.h>
21#include <dhcp/tests/packet_queue_testutils.h>
22#include <testutils/env_var_wrapper.h>
23#include <testutils/gtest_utils.h>
24#include <testutils/log_utils.h>
25#include <util/watch_socket.h>
26#include <boost/scoped_ptr.hpp>
27#include <gtest/gtest.h>
28
29#include <fcntl.h>
30#include <fstream>
31#include <functional>
32#include <iostream>
33#include <sstream>
34#include <thread>
35#include <unordered_map>
36
37#include <arpa/inet.h>
38#include <sys/resource.h>
39#include <sys/types.h>
40#include <unistd.h>
41
42using namespace std;
43using namespace isc;
44using namespace isc::asiolink;
45using namespace isc::dhcp;
46using namespace isc::dhcp::test;
47using namespace isc::test;
48using namespace isc::util;
49using boost::scoped_ptr;
50namespace ph = std::placeholders;
51
52namespace {
53
54typedef boost::hash<Pkt4Ptr> hash_pkt4;
55
56typedef boost::hash<Pkt6Ptr> hash_pkt6;
57
58// Note this is for the *real* loopback interface, *not* the fake one.
59// So in tests using it you have LOOPBACK_NAME, LOOPBACK_INDEX and
60// no "eth0" nor "eth1". In tests not using it you can have "lo", LO_INDEX,
61// "eth0" or "eth1".
62// Name of loopback interface detection.
63const size_t BUF_SIZE = 32;
64// Can be overwritten to "lo0" for instance on BSD systems.
65char LOOPBACK_NAME[BUF_SIZE] = "lo";
66// In fact is never 0, 1 is by far the most likely.
67uint32_t LOOPBACK_INDEX = 0;
68
69// Ports used during testing
70const uint16_t PORT1 = 10547; // V6 socket
71const uint16_t PORT2 = 10548; // V4 socket
72
73// On some systems measured duration of receive6() and receive4() appears to be
74// shorter than select() timeout. This may be the case if different time
75// resolutions are used by these functions. For such cases we set the
76// tolerance to 0.01s.
77const uint32_t TIMEOUT_TOLERANCE = 10000;
78
79// Macro for making select wait time arguments for receive functions
80#define RECEIVE_WAIT_MS(m)0,(m*1000) 0,(m*1000)
81
82bool callback_ok = false;
83bool callback2_ok = false;
84
85void my_callback(int /* fd */) {
86 callback_ok = true;
87}
88
89void my_callback2(int /* fd */) {
90 callback2_ok = true;
91}
92
93/// This test verifies that the socket read buffer can be used to
94/// receive the data and that the data can be read from it.
95TEST(IfaceTest, readBuffer)static_assert(sizeof("IfaceTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("readBuffer") > 1, "test_name must not be empty"
); class IfaceTest_readBuffer_Test : public ::testing::Test {
public: IfaceTest_readBuffer_Test() = default; ~IfaceTest_readBuffer_Test
() override = default; IfaceTest_readBuffer_Test (const IfaceTest_readBuffer_Test
&) = delete; IfaceTest_readBuffer_Test & operator=( const
IfaceTest_readBuffer_Test &) = delete; IfaceTest_readBuffer_Test
(IfaceTest_readBuffer_Test &&) noexcept = delete; IfaceTest_readBuffer_Test
& operator=( IfaceTest_readBuffer_Test &&) noexcept
= delete; private: void TestBody() override; [[maybe_unused]
] static ::testing::TestInfo* const test_info_; }; ::testing::
TestInfo* const IfaceTest_readBuffer_Test::test_info_ = ::testing
::internal::MakeAndRegisterTestInfo( "IfaceTest", "readBuffer"
, nullptr, nullptr, ::testing::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 95), (::testing::internal::GetTestTypeId()), ::testing::internal
::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 95), ::
testing::internal::SuiteApiResolver< ::testing::Test>::
GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 95), new ::testing::internal::TestFactoryImpl<IfaceTest_readBuffer_Test
>); void IfaceTest_readBuffer_Test::TestBody()
{
96 // Create fake interface object.
97 Iface iface("em0", 0);
98 // The size of read buffer should initially be 0 and the returned
99 // pointer should be NULL.
100 ASSERT_EQ(0U, iface.getReadBufferSize())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "iface.getReadBufferSize()"
, 0U, iface.getReadBufferSize()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 100, gtest_ar.failure_message()) = ::testing::Message()
;
101 EXPECT_EQ(0, iface.getReadBuffer())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "iface.getReadBuffer()"
, 0, iface.getReadBuffer()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 101, gtest_ar.failure_message()) = ::testing::Message()
;
102
103 // Let's resize the buffer.
104 iface.resizeReadBuffer(256);
105 // Check that the buffer has expected size.
106 ASSERT_EQ(256U, iface.getReadBufferSize())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("256U", "iface.getReadBufferSize()"
, 256U, iface.getReadBufferSize()))) ; else return ::testing::
internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 106, gtest_ar
.failure_message()) = ::testing::Message()
;
107 // The returned pointer should now be non-NULL.
108 uint8_t* buf_ptr = iface.getReadBuffer();
109 ASSERT_TRUE(buf_ptr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(buf_ptr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 109, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "buf_ptr", "false", "true") .c_str()) = ::testing::Message(
)
;
110
111 // Use the pointer to set some data.
112 for (size_t i = 0; i < iface.getReadBufferSize(); ++i) {
113 buf_ptr[i] = i;
114 }
115
116 // Get the pointer again and validate the data.
117 buf_ptr = iface.getReadBuffer();
118 ASSERT_EQ(256U, iface.getReadBufferSize())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("256U", "iface.getReadBufferSize()"
, 256U, iface.getReadBufferSize()))) ; else return ::testing::
internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 118, gtest_ar
.failure_message()) = ::testing::Message()
;
119 for (size_t i = 0; i < iface.getReadBufferSize(); ++i) {
120 // Use assert so as it fails on the first failure, no need
121 // to continue further checks.
122 ASSERT_EQ(i, buf_ptr[i])switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("i", "buf_ptr[i]"
, i, buf_ptr[i]))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 122, gtest_ar.failure_message()) = ::testing::Message()
;
123 }
124}
125
126// Check that counting the number of active addresses on the interface
127// works as expected.
128TEST(IfaceTest, countActive4)static_assert(sizeof("IfaceTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("countActive4") > 1, "test_name must not be empty"
); class IfaceTest_countActive4_Test : public ::testing::Test
{ public: IfaceTest_countActive4_Test() = default; ~IfaceTest_countActive4_Test
() override = default; IfaceTest_countActive4_Test (const IfaceTest_countActive4_Test
&) = delete; IfaceTest_countActive4_Test & operator=
( const IfaceTest_countActive4_Test &) = delete; IfaceTest_countActive4_Test
(IfaceTest_countActive4_Test &&) noexcept = delete; IfaceTest_countActive4_Test
& operator=( IfaceTest_countActive4_Test &&) noexcept
= delete; private: void TestBody() override; [[maybe_unused]
] static ::testing::TestInfo* const test_info_; }; ::testing::
TestInfo* const IfaceTest_countActive4_Test::test_info_ = ::testing
::internal::MakeAndRegisterTestInfo( "IfaceTest", "countActive4"
, nullptr, nullptr, ::testing::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 128), (::testing::internal::GetTestTypeId()), ::testing::internal
::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 128), ::
testing::internal::SuiteApiResolver< ::testing::Test>::
GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 128), new ::testing::internal::TestFactoryImpl<IfaceTest_countActive4_Test
>); void IfaceTest_countActive4_Test::TestBody()
{
129 Iface iface("eth0", 0);
130 ASSERT_EQ(0U, iface.countActive4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "iface.countActive4()"
, 0U, iface.countActive4()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 130, gtest_ar.failure_message()) = ::testing::Message()
;
131
132 iface.addAddress(IOAddress("192.168.0.2"));
133 ASSERT_EQ(1U, iface.countActive4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "iface.countActive4()"
, 1U, iface.countActive4()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 133, gtest_ar.failure_message()) = ::testing::Message()
;
134
135 iface.addAddress(IOAddress("2001:db8:1::1"));
136 ASSERT_EQ(1U, iface.countActive4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "iface.countActive4()"
, 1U, iface.countActive4()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 136, gtest_ar.failure_message()) = ::testing::Message()
;
137
138 iface.addAddress(IOAddress("192.168.0.3"));
139 ASSERT_EQ(2U, iface.countActive4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("2U", "iface.countActive4()"
, 2U, iface.countActive4()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 139, gtest_ar.failure_message()) = ::testing::Message()
;
140
141 ASSERT_NO_THROW(iface.setActive(IOAddress("192.168.0.2"), false))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface.setActive(IOAddress("192.168.0.2"), false); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_141; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_141; } } else gtest_label_testnothrow_141
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 141, ("Expected: " "iface.setActive(IOAddress(\"192.168.0.2\"), false)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
142 ASSERT_EQ(1U, iface.countActive4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "iface.countActive4()"
, 1U, iface.countActive4()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 142, gtest_ar.failure_message()) = ::testing::Message()
;
143
144 ASSERT_NO_THROW(iface.setActive(IOAddress("192.168.0.3"), false))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface.setActive(IOAddress("192.168.0.3"), false); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_144; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_144; } } else gtest_label_testnothrow_144
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 144, ("Expected: " "iface.setActive(IOAddress(\"192.168.0.3\"), false)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
145 ASSERT_EQ(0U, iface.countActive4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "iface.countActive4()"
, 0U, iface.countActive4()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 145, gtest_ar.failure_message()) = ::testing::Message()
;
146}
147
148/// Mock object implementing PktFilter class. It is used by
149/// IfaceMgrTest::setPacketFilter to verify that IfaceMgr::setPacketFilter
150/// sets this object as a handler for opening sockets. This dummy
151/// class simply records that openSocket function was called by
152/// the IfaceMgr as expected.
153///
154/// @todo This class currently doesn't verify that send/receive functions
155/// were called. In order to test it, there is a need to supply dummy
156/// function performing select() on certain sockets. The system select()
157/// call will fail when dummy socket descriptor is provided and thus
158/// TestPktFilter::receive will never be called. The appropriate extension
159/// to IfaceMgr is planned along with implementation of other "Packet
160/// Filters" such as these supporting Linux Packet Filtering and
161/// Berkeley Packet Filtering.
162class TestPktFilter : public PktFilter {
163public:
164
165 /// Constructor
166 TestPktFilter()
167 : open_socket_called_(false) {
168 }
169
170 virtual bool isDirectResponseSupported() const {
171 return (false);
172 }
173
174 virtual bool isSocketReceivedTimeSupported() const {
175 return (false);
176 }
177
178 /// @brief Pretend to open a socket.
179 ///
180 /// This function doesn't open a real socket. It always returns the
181 /// same fake socket descriptor. It also records the fact that it has
182 /// been called in the public open_socket_called_ member.
183 /// As in the case of opening a real socket, this function will check
184 /// if there is another fake socket "bound" to the same address and port.
185 /// If there is, it will throw an exception. This allows to simulate the
186 /// conditions when one of the sockets can't be open because there is
187 /// a socket already open and test how IfaceMgr will handle it.
188 ///
189 /// @param iface An interface on which the socket is to be opened.
190 /// @param addr An address to which the socket is to be bound.
191 /// @param port A port to which the socket is to be bound.
192 virtual SocketInfo openSocket(Iface& iface,
193 const isc::asiolink::IOAddress& addr,
194 const uint16_t port,
195 const bool join_multicast,
196 const bool) {
197 // Check if there is any other socket bound to the specified address
198 // and port on this interface.
199 const Iface::SocketCollection& sockets = iface.getSockets();
200 for (auto const& socket : sockets) {
201 if (((socket.addr_ == addr) ||
202 ((socket.addr_ == IOAddress("::")) && join_multicast)) &&
203 socket.port_ == port) {
204 isc_throw(SocketConfigError, "test socket bind error")do { std::ostringstream oss__; oss__ << "test socket bind error"
; throw SocketConfigError("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 204, oss__.str().c_str()); } while (1)
;
205 }
206 }
207 open_socket_called_ = true;
208 return (SocketInfo(addr, port, 255));
209 }
210
211 /// Does nothing
212 virtual Pkt4Ptr receive(Iface&, const SocketInfo&) {
213 return (Pkt4Ptr());
214 }
215
216 /// Does nothing
217 virtual int send(const Iface&, uint16_t, const Pkt4Ptr&) {
218 return (0);
219 }
220
221 /// Holds the information whether openSocket was called on this
222 /// object after its creation.
223 bool open_socket_called_;
224};
225
226class NakedIfaceMgr: public IfaceMgr {
227 // "Naked" Interface Manager, exposes internal fields
228public:
229
230 /// @brief Constructor.
231 NakedIfaceMgr() {
232 loDetect();
233 }
234
235 /// @brief detects name of the loopback interface
236 ///
237 /// This method detects name of the loopback interface.
238 static void loDetect() {
239 // Poor man's interface detection. It will go away as soon as proper
240 // interface detection is implemented
241 if (if_nametoindex("lo") > 0) {
242 snprintf(LOOPBACK_NAME, BUF_SIZE - 1, "lo");
243 } else if (if_nametoindex("lo0") > 0) {
244 snprintf(LOOPBACK_NAME, BUF_SIZE - 1, "lo0");
245 } else {
246 cout << "Failed to detect loopback interface. Neither "
247 << "lo nor lo0 worked. I give up." << endl;
248 FAIL()return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 248, "Failed") = ::testing::Message()
;
249 }
250 LOOPBACK_INDEX = if_nametoindex(LOOPBACK_NAME);
251 }
252
253 /// @brief This function creates fictitious interfaces with fictitious
254 /// addresses.
255 ///
256 /// These interfaces can be used in tests that don't actually try
257 /// to open the sockets on these interfaces. Some tests use mock
258 /// objects to mimic sockets being open. These interfaces are
259 /// suitable for such tests.
260 void createIfaces() {
261
262 ifaces_.clear();
263
264 // local loopback
265 IfacePtr lo = createIface("lo", LO_INDEX);
266 lo->addAddress(IOAddress("127.0.0.1"));
267 lo->addAddress(IOAddress("::1"));
268 ifaces_.push_back(lo);
269 // eth0
270 IfacePtr eth0 = createIface("eth0", ETH0_INDEX);
271 eth0->addAddress(IOAddress("10.0.0.1"));
272 eth0->addAddress(IOAddress("fe80::3a60:77ff:fed5:cdef"));
273 eth0->addAddress(IOAddress("2001:db8:1::1"));
274 ifaces_.push_back(eth0);
275 // eth1
276 IfacePtr eth1 = createIface("eth1", ETH1_INDEX);
277 eth1->addAddress(IOAddress("192.0.2.3"));
278 eth1->addAddress(IOAddress("fe80::3a60:77ff:fed5:abcd"));
279 ifaces_.push_back(eth1);
280 }
281
282 /// @brief Create an object representing interface.
283 ///
284 /// Apart from creating an interface, this function also sets the
285 /// interface flags:
286 /// - loopback flag if interface name is "lo"
287 /// - up always true
288 /// - running always true
289 /// - inactive always to false
290 /// - multicast always to true
291 /// - broadcast always to false
292 ///
293 /// If one needs to modify the default flag settings, the setIfaceFlags
294 /// function should be used.
295 ///
296 /// @param name A name of the interface to be created.
297 /// @param ifindex An index of the interface to be created.
298 ///
299 /// @return An object representing interface.
300 static IfacePtr createIface(const std::string& name, const unsigned int ifindex) {
301 IfacePtr iface(new Iface(name, ifindex));
302 if (name == "lo") {
303 iface->flag_loopback_ = true;
304 // Don't open sockets on loopback interface.
305 iface->inactive4_ = true;
306 iface->inactive6_ = true;
307 } else {
308 iface->inactive4_ = false;
309 iface->inactive6_ = false;
310 }
311 iface->flag_multicast_ = true;
312 // On BSD systems, the SO_BINDTODEVICE option is not supported.
313 // Therefore the IfaceMgr will throw an exception on attempt to
314 // open sockets on more than one broadcast-capable interface at
315 // the same time. In order to prevent this error, we mark all
316 // interfaces broadcast-incapable for unit testing.
317 iface->flag_broadcast_ = false;
318 iface->flag_up_ = true;
319 iface->flag_running_ = true;
320 return (iface);
321 }
322
323 /// @brief Checks if the specified interface has a socket bound to a
324 /// specified address.
325 ///
326 /// @param iface_name A name of the interface.
327 /// @param addr An address to be checked for binding.
328 ///
329 /// @return true if there is a socket bound to the specified address.
330 bool isBound(const std::string& iface_name, const std::string& addr) {
331 IfacePtr iface = getIface(iface_name);
332 if (!iface) {
333 ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 333, "Failed") = ::testing::Message()
<< "the interface " << iface_name << " doesn't exist";
334 return (false);
335 }
336 const Iface::SocketCollection& sockets = iface->getSockets();
337 for (auto const& sock : sockets) {
338 if (sock.addr_ == IOAddress(addr)) {
339 return (true);
340
341 } else if ((sock.addr_ == IOAddress("::")) &&
342 (IOAddress(addr).isV6LinkLocal())) {
343 for (auto const& a : iface->getAddresses()) {
344 if (a.get() == IOAddress(addr)) {
345 return (true);
346 }
347 }
348 }
349 }
350 return (false);
351 }
352
353 /// @brief Modify flags on the interface.
354 ///
355 /// @param name A name of the interface.
356 /// @param loopback A new value of the loopback flag.
357 /// @param up A new value of the up flag.
358 /// @param running A new value of the running flag.
359 /// @param inactive A new value of the inactive flag.
360 void setIfaceFlags(const std::string& name, const bool loopback,
361 const bool up, const bool running,
362 const bool inactive4,
363 const bool inactive6) {
364 for (auto const& iface : getIfaces()) {
365 if (iface->getName() == name) {
366 iface->flag_loopback_ = loopback;
367 iface->flag_up_ = up;
368 iface->flag_running_ = running;
369 iface->inactive4_ = inactive4;
370 iface->inactive6_ = inactive6;
371 }
372 }
373 }
374};
375
376/// @brief A test fixture class for IfaceMgr.
377///
378/// @todo Sockets being opened by IfaceMgr tests should be managed by
379/// the test fixture. In particular, the class should close sockets after
380/// each test. Current approach where test cases are responsible for
381/// closing sockets is resource leak prone, especially in case of the
382/// test failure path.
383class IfaceMgrTest : public ::testing::Test {
384public:
385
386 /// @brief Structure used to store and restore the system limit of open files.
387 struct rlimit limit_;
388
389 /// @brief Constructor.
390 IfaceMgrTest()
391 : errors_count_(0), kea_event_handler_type_("KEA_EVENT_HANDLER_TYPE") {
392 IfaceMgr::instance().setFamily(AF_INET2);
393 struct rlimit limit;
394 getrlimit(RLIMIT_NOFILERLIMIT_NOFILE, &limit_);
395 limit.rlim_cur = 16 * FD_SETSIZE1024;
396 limit.rlim_max = 16 * FD_SETSIZE1024;
397 setrlimit(RLIMIT_NOFILERLIMIT_NOFILE, &limit);
398 }
399
400 ~IfaceMgrTest() {
401 setrlimit(RLIMIT_NOFILERLIMIT_NOFILE, &limit_);
402 IfaceMgr::instance().stopDHCPReceiver();
403 IfaceMgr::instance().clearIfaces();
404 IfaceMgr::instance().deleteAllExternalSockets();
405 IfaceMgr::instance().detectIfaces();
406 IfaceMgr::instance().setPacketFilter(PktFilterPtr(new PktFilterInet()));
407 IfaceMgr::instance().setPacketFilter(PktFilter6Ptr(new PktFilterInet6()));
408 IfaceMgr::instance().configureDHCPPacketQueue(AF_INET2, data::ConstElementPtr());
409 IfaceMgr::instance().configureDHCPPacketQueue(AF_INET610, data::ConstElementPtr());
410 IfaceMgr::instance().setFamily(AF_INET2);
411 }
412
413 /// @brief Tests the number of IPv6 sockets on interface
414 ///
415 /// This function checks the expected number of open IPv6 sockets on the
416 /// specified interface. On non-Linux systems, sockets are bound to a
417 /// link-local address and the number of unicast addresses specified.
418 /// On Linux systems, there is two more sockets bound to ff02::1:2
419 /// and ff05::1:3 multicast addresses.
420 ///
421 /// @param iface An interface on which sockets are open.
422 /// @param unicast_num A number of unicast addresses bound.
423 /// @param link_local_num A number of link local addresses bound.
424 void checkSocketsCount6(const Iface& iface,
425 const int unicast_num,
426 const int link_local_num = 1) {
427 // On local-loopback interface, there should be no sockets.
428 if (iface.flag_loopback_) {
429 ASSERT_TRUE(iface.getSockets().empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface.getSockets().empty
())) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 429, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface.getSockets().empty()", "false", "true") .c_str()) = ::
testing::Message()
430 << "expected empty socket set on loopback interface "
431 << iface.getName();
432 return;
433 }
434#if defined OS_LINUX
435 // On Linux, for each link-local address there may be two
436 // additional sockets opened and bound to multicast. These sockets
437 // are only opened if the interface is multicast-capable.
438 ASSERT_EQ(unicast_numswitch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("unicast_num + (iface.flag_multicast_ ? 2 * link_local_num : 0) + link_local_num"
, "static_cast<int>(iface.getSockets().size())", unicast_num
+ (iface.flag_multicast_ ? 2 * link_local_num : 0) + link_local_num
, static_cast<int>(iface.getSockets().size())))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 441, gtest_ar.failure_message()) = ::testing::Message()
439 + (iface.flag_multicast_ ? 2 * link_local_num : 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("unicast_num + (iface.flag_multicast_ ? 2 * link_local_num : 0) + link_local_num"
, "static_cast<int>(iface.getSockets().size())", unicast_num
+ (iface.flag_multicast_ ? 2 * link_local_num : 0) + link_local_num
, static_cast<int>(iface.getSockets().size())))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 441, gtest_ar.failure_message()) = ::testing::Message()
440 + link_local_num,switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("unicast_num + (iface.flag_multicast_ ? 2 * link_local_num : 0) + link_local_num"
, "static_cast<int>(iface.getSockets().size())", unicast_num
+ (iface.flag_multicast_ ? 2 * link_local_num : 0) + link_local_num
, static_cast<int>(iface.getSockets().size())))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 441, gtest_ar.failure_message()) = ::testing::Message()
441 static_cast<int>(iface.getSockets().size()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("unicast_num + (iface.flag_multicast_ ? 2 * link_local_num : 0) + link_local_num"
, "static_cast<int>(iface.getSockets().size())", unicast_num
+ (iface.flag_multicast_ ? 2 * link_local_num : 0) + link_local_num
, static_cast<int>(iface.getSockets().size())))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 441, gtest_ar.failure_message()) = ::testing::Message()
442 << "invalid number of sockets on interface "
443 << iface.getName();
444#else
445 // On non-Linux, there is no additional socket.
446 ASSERT_EQ(unicast_num + link_local_num,switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("unicast_num + link_local_num"
, "static_cast<int>(iface.getSockets().size())", unicast_num
+ link_local_num, static_cast<int>(iface.getSockets().
size())))) ; else return ::testing::internal::AssertHelper(::
testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 447, gtest_ar.failure_message()) = ::testing::Message()
447 static_cast<int>(iface.getSockets().size()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("unicast_num + link_local_num"
, "static_cast<int>(iface.getSockets().size())", unicast_num
+ link_local_num, static_cast<int>(iface.getSockets().
size())))) ; else return ::testing::internal::AssertHelper(::
testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 447, gtest_ar.failure_message()) = ::testing::Message()
448 << "invalid number of sockets on interface "
449 << iface.getName();
450
451#endif
452 }
453
454 // Get the number of IPv4 or IPv6 sockets on the loopback interface
455 int getOpenSocketsCount(const Iface& iface, uint16_t family) const {
456 // Get all sockets.
457 Iface::SocketCollection sockets = iface.getSockets();
458
459 // Loop through sockets and try to find the ones which match the
460 // specified type.
461 int sockets_count = 0;
462 for (auto const& sock : sockets) {
463 // Match found, increase the counter.
464 if (sock.family_ == family) {
465 ++sockets_count;
466 }
467 }
468 return (sockets_count);
469 }
470
471 /// @brief returns socket bound to a specific address (or NULL)
472 ///
473 /// A helper function, used to pick a socketinfo that is bound to a given
474 /// address.
475 ///
476 /// @param sockets sockets collection
477 /// @param addr address the socket is bound to
478 ///
479 /// @return socket info structure (or NULL)
480 const isc::dhcp::SocketInfo*
481 getSocketByAddr(const isc::dhcp::Iface::SocketCollection& sockets,
482 const IOAddress& addr) {
483 for (auto const& s : sockets) {
484 if (s.addr_ == addr) {
485 return (&s);
486 }
487 }
488 return (NULL__null);
489 }
490
491 /// @brief Implements an IfaceMgr error handler.
492 ///
493 /// This function can be installed as an error handler for the
494 /// IfaceMgr::openSockets4 function. The error handler is invoked
495 /// when an attempt to open a particular socket fails for any reason.
496 /// Typically, the error handler will log a warning. When the error
497 /// handler returns, the openSockets4 function should continue opening
498 /// sockets on other interfaces.
499 ///
500 /// @param errmsg An error string indicating the reason for failure.
501 void ifaceMgrErrorHandler(const std::string&) {
502 // Increase the counter of invocations to this function. By checking
503 // this number, a test may check if the expected number of errors
504 // has occurred.
505 ++errors_count_;
506 }
507
508 /// @brief Tests the ability to send and receive DHCPv6 packets
509 ///
510 /// This test calls @r IfaceMgr::configureDHCPPacketQueue, passing in the
511 /// given queue configuration. It then calls IfaceMgr::startDHCPReceiver
512 /// and verifies whether or not the receive thread has been started as
513 /// expected. Next it creates a generic DHCPv6 packet and sends it over
514 /// the loop back interface. It invokes IfaceMgr::receive6 to receive the
515 /// packet sent, and compares to the packets for equality.
516 ///
517 /// @param dhcp_queue_control dhcp-queue-control contents to use for the test
518 /// @param exp_queue_enabled flag that indicates if packet queuing is expected
519 /// to be enabled.
520 void sendReceive6Test(data::ConstElementPtr dhcp_queue_control, bool exp_queue_enabled) {
521 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
522
523 // Testing socket operation in a portable way is tricky
524 // without interface detection implemented
525 // let's assume that every supported OS have lo interface
526 IOAddress lo_addr("::1");
527 int socket1 = 0, socket2 = 0;
528 EXPECT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547
); socket2 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10546
);; } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_531; } catch (...
) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_531
; } } else gtest_label_testnothrow_531 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 531, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547); socket2 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10546);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
529 socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547
); socket2 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10546
);; } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_531; } catch (...
) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_531
; } } else gtest_label_testnothrow_531 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 531, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547); socket2 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10546);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
530 socket2 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10546);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547
); socket2 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10546
);; } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_531; } catch (...
) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_531
; } } else gtest_label_testnothrow_531 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 531, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547); socket2 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10546);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
531 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547
); socket2 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10546
);; } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_531; } catch (...
) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_531
; } } else gtest_label_testnothrow_531 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 531, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547); socket2 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10546);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
532
533 EXPECT_GE(socket1, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket1", "0",
socket1, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 533, gtest_ar.failure_message()) = ::testing::Message()
;
534 EXPECT_GE(socket2, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket2", "0",
socket2, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 534, gtest_ar.failure_message()) = ::testing::Message()
;
535
536 // Configure packet queueing as desired.
537 bool queue_enabled = false;
538 ASSERT_NO_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET6, dhcp_queue_control))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
queue_enabled = ifacemgr->configureDHCPPacketQueue(10, dhcp_queue_control
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_538; } catch (...
) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_538
; } } else gtest_label_testnothrow_538 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 538, ("Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(10, dhcp_queue_control)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
539
540 // Verify that we have a queue only if we expected one.
541 ASSERT_EQ(exp_queue_enabled, queue_enabled)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("exp_queue_enabled"
, "queue_enabled", exp_queue_enabled, queue_enabled))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 541, gtest_ar.failure_message()) = ::testing::Message()
;
542
543 // Thread should only start when there is a packet queue.
544 ASSERT_NO_THROW(ifacemgr->startDHCPReceiver(AF_INET6))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->startDHCPReceiver(10); } else static_assert(true
, ""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_544
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_544
; } } else gtest_label_testnothrow_544 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 544, ("Expected: " "ifacemgr->startDHCPReceiver(10)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
545 ASSERT_TRUE(queue_enabled == ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(queue_enabled == ifacemgr
->isDHCPReceiverRunning())) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 545, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "queue_enabled == ifacemgr->isDHCPReceiverRunning()", "false"
, "true") .c_str()) = ::testing::Message()
;
546
547 // If the thread is already running, trying to start it again should fail.
548 if (queue_enabled) {
549 ASSERT_THROW(ifacemgr->startDHCPReceiver(AF_INET6), InvalidOperation)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->startDHCPReceiver
(10); } else static_assert(true, ""); } catch (InvalidOperation
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< InvalidOperation>::
type>::type, std::exception>::value, const ::testing::internal
::NeverThrown&, const std::exception&>::type e) { gtest_msg
.value = "Expected: " "ifacemgr->startDHCPReceiver(10)" " throws an exception of type "
"InvalidOperation" ".\n Actual: it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_549; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->startDHCPReceiver(10)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_549; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->startDHCPReceiver(10)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_549; } } else gtest_label_testthrow_549
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 549, gtest_msg.value.c_str()) = ::testing::Message()
;
550 // Should still have one running.
551 ASSERT_TRUE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->isDHCPReceiverRunning
())) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 551, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "false", "true") .c_str
()) = ::testing::Message()
;
552 }
553
554 // Let's build our DHCPv6 packet.
555 // prepare dummy payload
556 uint8_t data[128];
557 for (uint8_t i = 0; i < 128; i++) {
558 data[i] = i;
559 }
560
561 Pkt6Ptr sendPkt = Pkt6Ptr(new Pkt6(data, 128));
562 sendPkt->repack();
563 sendPkt->setRemotePort(10547);
564 sendPkt->setRemoteAddr(IOAddress("::1"));
565 sendPkt->setIndex(LOOPBACK_INDEX);
566 sendPkt->setIface(LOOPBACK_NAME);
567
568 // Send the packet.
569 EXPECT_TRUE(ifacemgr->send(sendPkt))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->send(sendPkt
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 569, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->send(sendPkt)", "false", "true") .c_str()) = ::
testing::Message()
;
570
571 // Now, let's try and receive it.
572 Pkt6Ptr rcvPkt;
573 rcvPkt = ifacemgr->receive6(10);
574 ASSERT_TRUE(rcvPkt)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(rcvPkt)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 574, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "rcvPkt", "false", "true") .c_str()) = ::testing::Message()
; // received our own packet
575
576 // let's check that we received what was sent
577 ASSERT_EQ(sendPkt->data_.size(), rcvPkt->data_.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("sendPkt->data_.size()"
, "rcvPkt->data_.size()", sendPkt->data_.size(), rcvPkt
->data_.size()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 577, gtest_ar.failure_message()) = ::testing::Message()
;
578 EXPECT_EQ(0, memcmp(&sendPkt->data_[0], &rcvPkt->data_[0],switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "memcmp(&sendPkt->data_[0], &rcvPkt->data_[0], rcvPkt->data_.size())"
, 0, memcmp(&sendPkt->data_[0], &rcvPkt->data_[
0], rcvPkt->data_.size())))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 579, gtest_ar.failure_message()) = ::testing::Message()
579 rcvPkt->data_.size()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "memcmp(&sendPkt->data_[0], &rcvPkt->data_[0], rcvPkt->data_.size())"
, 0, memcmp(&sendPkt->data_[0], &rcvPkt->data_[
0], rcvPkt->data_.size())))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 579, gtest_ar.failure_message()) = ::testing::Message()
;
580
581 EXPECT_EQ(sendPkt->getRemoteAddr(), rcvPkt->getRemoteAddr())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("sendPkt->getRemoteAddr()"
, "rcvPkt->getRemoteAddr()", sendPkt->getRemoteAddr(), rcvPkt
->getRemoteAddr()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 581, gtest_ar.failure_message()) = ::testing::Message()
;
582
583 // since we opened 2 sockets on the same interface and none of them is multicast,
584 // none is preferred over the other for sending data, so we really should not
585 // assume the one or the other will always be chosen for sending data. Therefore
586 // we should accept both values as source ports.
587 EXPECT_TRUE((rcvPkt->getRemotePort() == 10546) || (rcvPkt->getRemotePort() == 10547))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult((rcvPkt->getRemotePort
() == 10546) || (rcvPkt->getRemotePort() == 10547))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 587, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "(rcvPkt->getRemotePort() == 10546) || (rcvPkt->getRemotePort() == 10547)"
, "false", "true") .c_str()) = ::testing::Message()
;
588
589 // Close the socket. Further we will test if errors are reported
590 // properly on attempt to use closed socket.
591 close(socket2);
592
593 // @todo Closing the socket does NOT cause a read error out of the
594 // receiveDHCP<X>Packets() select. Apparently this is because the
595 // thread is already inside the select when the socket is closed,
596 // and (at least under Centos 7.5), this does not interrupt the
597 // select. For now, we'll only test this for direct receive.
598 if (!queue_enabled) {
599 EXPECT_THROW(ifacemgr->receive6(10), SocketFDError)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->receive6(10
); } else static_assert(true, ""); } catch (SocketFDError const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< SocketFDError>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->receive6(10)" " throws an exception of type "
"SocketFDError" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_599; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->receive6(10)"
" throws an exception of type " "SocketFDError" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_599; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->receive6(10)"
" throws an exception of type " "SocketFDError" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_599; } } else gtest_label_testthrow_599
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 599, gtest_msg.value.c_str()) = ::testing::Message()
;
600 }
601
602 // Verify write fails.
603 EXPECT_THROW(ifacemgr->send(sendPkt), SocketWriteError)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->send(sendPkt
); } else static_assert(true, ""); } catch (SocketWriteError const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< SocketWriteError>::type>::type
, std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->send(sendPkt)" " throws an exception of type "
"SocketWriteError" ".\n Actual: it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_603; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->send(sendPkt)"
" throws an exception of type " "SocketWriteError" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_603; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->send(sendPkt)"
" throws an exception of type " "SocketWriteError" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_603; } } else gtest_label_testthrow_603
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 603, gtest_msg.value.c_str()) = ::testing::Message()
;
604
605 // Stop the thread. This should be no harm/no foul if we're not
606 // queueuing. Either way, we should not have a thread afterwards.
607 ASSERT_NO_THROW(ifacemgr->stopDHCPReceiver())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->stopDHCPReceiver(); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_607
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_607
; } } else gtest_label_testnothrow_607 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 607, ("Expected: " "ifacemgr->stopDHCPReceiver()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
608 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 608, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
609 }
610
611 /// @brief Tests the ability to send and receive DHCPv4 packets
612 ///
613 /// This test calls @r IfaceMgr::configureDHCPPacketQueue, passing in the
614 /// given queue configuration. It then calls IfaceMgr::startDHCPReceiver
615 /// and verifies whether or not the receive thread has been started as
616 /// expected. Next it creates a DISCOVER packet and sends it over
617 /// the loop back interface. It invokes IfaceMgr::receive4 to receive the
618 /// packet sent, and compares to the packets for equality.
619 ///
620 /// @param dhcp_queue_control dhcp-queue-control contents to use for the test
621 /// @param exp_queue_enabled flag that indicates if packet queuing is expected
622 /// to be enabled.
623 void sendReceive4Test(data::ConstElementPtr dhcp_queue_control, bool exp_queue_enabled) {
624 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
625
626 // Testing socket operation in a portable way is tricky
627 // without interface detection implemented.
628 // Let's assume that every supported OS has lo interface
629 IOAddress lo_addr("127.0.0.1");
630 int socket1 = 0;
631 EXPECT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT
+ 10000);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_634; } catch (...
) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_634
; } } else gtest_label_testnothrow_634 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 634, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
632 socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr,switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT
+ 10000);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_634; } catch (...
) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_634
; } } else gtest_label_testnothrow_634 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 634, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
633 DHCP4_SERVER_PORT + 10000);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT
+ 10000);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_634; } catch (...
) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_634
; } } else gtest_label_testnothrow_634 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 634, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
634 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT
+ 10000);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_634; } catch (...
) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_634
; } } else gtest_label_testnothrow_634 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 634, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
635
636 EXPECT_GE(socket1, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket1", "0",
socket1, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 636, gtest_ar.failure_message()) = ::testing::Message()
;
637
638 // Configure packet queueing as desired.
639 bool queue_enabled = false;
640 ASSERT_NO_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET, dhcp_queue_control))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
queue_enabled = ifacemgr->configureDHCPPacketQueue(2, dhcp_queue_control
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_640; } catch (...
) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_640
; } } else gtest_label_testnothrow_640 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 640, ("Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(2, dhcp_queue_control)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
641
642 // Verify that we have a queue only if we expected one.
643 ASSERT_EQ(exp_queue_enabled, queue_enabled)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("exp_queue_enabled"
, "queue_enabled", exp_queue_enabled, queue_enabled))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 643, gtest_ar.failure_message()) = ::testing::Message()
;
644
645 // Thread should only start when there is a packet queue.
646 ASSERT_NO_THROW(ifacemgr->startDHCPReceiver(AF_INET))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->startDHCPReceiver(2); } else static_assert(true
, ""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_646
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_646
; } } else gtest_label_testnothrow_646 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 646, ("Expected: " "ifacemgr->startDHCPReceiver(2)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
647 ASSERT_TRUE(queue_enabled == ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(queue_enabled == ifacemgr
->isDHCPReceiverRunning())) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 647, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "queue_enabled == ifacemgr->isDHCPReceiverRunning()", "false"
, "true") .c_str()) = ::testing::Message()
;
648
649 // If the thread is already running, trying to start it again should fail.
650 if (queue_enabled) {
651 ASSERT_THROW(ifacemgr->startDHCPReceiver(AF_INET), InvalidOperation)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->startDHCPReceiver
(2); } else static_assert(true, ""); } catch (InvalidOperation
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< InvalidOperation>::
type>::type, std::exception>::value, const ::testing::internal
::NeverThrown&, const std::exception&>::type e) { gtest_msg
.value = "Expected: " "ifacemgr->startDHCPReceiver(2)" " throws an exception of type "
"InvalidOperation" ".\n Actual: it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_651; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->startDHCPReceiver(2)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_651; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->startDHCPReceiver(2)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_651; } } else gtest_label_testthrow_651
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 651, gtest_msg.value.c_str()) = ::testing::Message()
;
652 // Should still have one running.
653 ASSERT_TRUE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->isDHCPReceiverRunning
())) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 653, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "false", "true") .c_str
()) = ::testing::Message()
;
654 }
655
656 // Let's construct the packet to send.
657 boost::shared_ptr<Pkt4> sendPkt(new Pkt4(DHCPDISCOVER, 1234) );
658 sendPkt->setLocalAddr(IOAddress("127.0.0.1"));
659 sendPkt->setLocalPort(DHCP4_SERVER_PORT + 10000 + 1);
660 sendPkt->setRemotePort(DHCP4_SERVER_PORT + 10000);
661 sendPkt->setRemoteAddr(IOAddress("127.0.0.1"));
662 sendPkt->setIndex(LOOPBACK_INDEX);
663 sendPkt->setIface(string(LOOPBACK_NAME));
664 sendPkt->setHops(6);
665 sendPkt->setSecs(42);
666 sendPkt->setCiaddr(IOAddress("192.0.2.1"));
667 sendPkt->setSiaddr(IOAddress("192.0.2.2"));
668 sendPkt->setYiaddr(IOAddress("192.0.2.3"));
669 sendPkt->setGiaddr(IOAddress("192.0.2.4"));
670
671 // Unpack() now checks if mandatory DHCP_MESSAGE_TYPE is present.
672 // Workarounds (creating DHCP Message Type Option by hand) are no longer
673 // needed as setDhcpType() is called in constructor.
674
675 uint8_t sname[] = "That's just a string that will act as SNAME";
676 sendPkt->setSname(sname, strlen((const char*)sname));
677 uint8_t file[] = "/another/string/that/acts/as/a/file_name.txt";
678 sendPkt->setFile(file, strlen((const char*)file));
679
680 ASSERT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
sendPkt->pack();; } else static_assert(true, ""); } catch
(std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_682
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_682
; } } else gtest_label_testnothrow_682 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 682, ("Expected: " "sendPkt->pack();" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
681 sendPkt->pack();switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
sendPkt->pack();; } else static_assert(true, ""); } catch
(std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_682
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_682
; } } else gtest_label_testnothrow_682 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 682, ("Expected: " "sendPkt->pack();" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
682 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
sendPkt->pack();; } else static_assert(true, ""); } catch
(std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_682
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_682
; } } else gtest_label_testnothrow_682 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 682, ("Expected: " "sendPkt->pack();" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
683
684 // OK, Send the PACKET!
685 bool result = false;
686 EXPECT_NO_THROW(result = ifacemgr->send(sendPkt))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
result = ifacemgr->send(sendPkt); } else static_assert(true
, ""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_686
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_686
; } } else gtest_label_testnothrow_686 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 686, ("Expected: " "result = ifacemgr->send(sendPkt)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
687 EXPECT_TRUE(result)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(result)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 687, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"result", "false", "true") .c_str()) = ::testing::Message()
;
688
689 // Now let's try and receive it.
690 boost::shared_ptr<Pkt4> rcvPkt;
691 ASSERT_NO_THROW(rcvPkt = ifacemgr->receive4(10))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
rcvPkt = ifacemgr->receive4(10); } else static_assert(true
, ""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_691
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_691
; } } else gtest_label_testnothrow_691 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 691, ("Expected: " "rcvPkt = ifacemgr->receive4(10)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
692 ASSERT_TRUE(rcvPkt)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(rcvPkt)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 692, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "rcvPkt", "false", "true") .c_str()) = ::testing::Message()
; // received our own packet
693 ASSERT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
rcvPkt->unpack();; } else static_assert(true, ""); } catch
(std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_695
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_695
; } } else gtest_label_testnothrow_695 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 695, ("Expected: " "rcvPkt->unpack();" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
694 rcvPkt->unpack();switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
rcvPkt->unpack();; } else static_assert(true, ""); } catch
(std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_695
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_695
; } } else gtest_label_testnothrow_695 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 695, ("Expected: " "rcvPkt->unpack();" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
695 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
rcvPkt->unpack();; } else static_assert(true, ""); } catch
(std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_695
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_695
; } } else gtest_label_testnothrow_695 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 695, ("Expected: " "rcvPkt->unpack();" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
696
697 // let's check that we received what was sent
698 EXPECT_EQ(sendPkt->len(), rcvPkt->len())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("sendPkt->len()"
, "rcvPkt->len()", sendPkt->len(), rcvPkt->len()))) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 698, gtest_ar.failure_message()) = ::testing::Message()
;
699 EXPECT_EQ("127.0.0.1", rcvPkt->getRemoteAddr().toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"127.0.0.1\""
, "rcvPkt->getRemoteAddr().toText()", "127.0.0.1", rcvPkt->
getRemoteAddr().toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 699, gtest_ar.failure_message()) = ::testing::Message()
;
700 EXPECT_EQ(sendPkt->getRemotePort(), rcvPkt->getLocalPort())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("sendPkt->getRemotePort()"
, "rcvPkt->getLocalPort()", sendPkt->getRemotePort(), rcvPkt
->getLocalPort()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 700, gtest_ar.failure_message()) = ::testing::Message()
;
701 EXPECT_EQ(sendPkt->getHops(), rcvPkt->getHops())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("sendPkt->getHops()"
, "rcvPkt->getHops()", sendPkt->getHops(), rcvPkt->getHops
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 701, gtest_ar.failure_message()) = ::testing::Message()
;
702 EXPECT_EQ(sendPkt->getOp(), rcvPkt->getOp())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("sendPkt->getOp()"
, "rcvPkt->getOp()", sendPkt->getOp(), rcvPkt->getOp
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 702, gtest_ar.failure_message()) = ::testing::Message()
;
703 EXPECT_EQ(sendPkt->getSecs(), rcvPkt->getSecs())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("sendPkt->getSecs()"
, "rcvPkt->getSecs()", sendPkt->getSecs(), rcvPkt->getSecs
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 703, gtest_ar.failure_message()) = ::testing::Message()
;
704 EXPECT_EQ(sendPkt->getFlags(), rcvPkt->getFlags())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("sendPkt->getFlags()"
, "rcvPkt->getFlags()", sendPkt->getFlags(), rcvPkt->
getFlags()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 704, gtest_ar.failure_message()) = ::testing::Message()
;
705 EXPECT_EQ(sendPkt->getCiaddr(), rcvPkt->getCiaddr())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("sendPkt->getCiaddr()"
, "rcvPkt->getCiaddr()", sendPkt->getCiaddr(), rcvPkt->
getCiaddr()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 705, gtest_ar.failure_message()) = ::testing::Message()
;
706 EXPECT_EQ(sendPkt->getSiaddr(), rcvPkt->getSiaddr())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("sendPkt->getSiaddr()"
, "rcvPkt->getSiaddr()", sendPkt->getSiaddr(), rcvPkt->
getSiaddr()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 706, gtest_ar.failure_message()) = ::testing::Message()
;
707 EXPECT_EQ(sendPkt->getYiaddr(), rcvPkt->getYiaddr())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("sendPkt->getYiaddr()"
, "rcvPkt->getYiaddr()", sendPkt->getYiaddr(), rcvPkt->
getYiaddr()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 707, gtest_ar.failure_message()) = ::testing::Message()
;
708 EXPECT_EQ(sendPkt->getGiaddr(), rcvPkt->getGiaddr())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("sendPkt->getGiaddr()"
, "rcvPkt->getGiaddr()", sendPkt->getGiaddr(), rcvPkt->
getGiaddr()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 708, gtest_ar.failure_message()) = ::testing::Message()
;
709 EXPECT_EQ(sendPkt->getTransid(), rcvPkt->getTransid())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("sendPkt->getTransid()"
, "rcvPkt->getTransid()", sendPkt->getTransid(), rcvPkt
->getTransid()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 709, gtest_ar.failure_message()) = ::testing::Message()
;
710 EXPECT_TRUE(sendPkt->getSname() == rcvPkt->getSname())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(sendPkt->getSname(
) == rcvPkt->getSname())) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 710, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "sendPkt->getSname() == rcvPkt->getSname()", "false",
"true") .c_str()) = ::testing::Message()
;
711 EXPECT_TRUE(sendPkt->getFile() == rcvPkt->getFile())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(sendPkt->getFile()
== rcvPkt->getFile())) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 711, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "sendPkt->getFile() == rcvPkt->getFile()", "false", "true"
) .c_str()) = ::testing::Message()
;
712 EXPECT_EQ(sendPkt->getHtype(), rcvPkt->getHtype())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("sendPkt->getHtype()"
, "rcvPkt->getHtype()", sendPkt->getHtype(), rcvPkt->
getHtype()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 712, gtest_ar.failure_message()) = ::testing::Message()
;
713 EXPECT_EQ(sendPkt->getHlen(), rcvPkt->getHlen())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("sendPkt->getHlen()"
, "rcvPkt->getHlen()", sendPkt->getHlen(), rcvPkt->getHlen
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 713, gtest_ar.failure_message()) = ::testing::Message()
;
714
715 // since we opened 2 sockets on the same interface and none of them is multicast,
716 // none is preferred over the other for sending data, so we really should not
717 // assume the one or the other will always be chosen for sending data. We should
718 // skip checking source port of sent address.
719
720 // Close the socket. Further we will test if errors are reported
721 // properly on attempt to use closed socket.
722 close(socket1);
723
724 // @todo Closing the socket does NOT cause a read error out of the
725 // receiveDHCP<X>Packets() select. Apparently this is because the
726 // thread is already inside the select when the socket is closed,
727 // and (at least under Centos 7.5), this does not interrupt the
728 // select. For now, we'll only test this for direct receive.
729 if (!queue_enabled) {
730 EXPECT_THROW(ifacemgr->receive4(10), SocketFDError)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->receive4(10
); } else static_assert(true, ""); } catch (SocketFDError const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< SocketFDError>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->receive4(10)" " throws an exception of type "
"SocketFDError" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_730; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->receive4(10)"
" throws an exception of type " "SocketFDError" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_730; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->receive4(10)"
" throws an exception of type " "SocketFDError" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_730; } } else gtest_label_testthrow_730
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 730, gtest_msg.value.c_str()) = ::testing::Message()
;
731 }
732
733 // Verify write fails.
734 EXPECT_THROW(ifacemgr->send(sendPkt), SocketWriteError)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->send(sendPkt
); } else static_assert(true, ""); } catch (SocketWriteError const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< SocketWriteError>::type>::type
, std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->send(sendPkt)" " throws an exception of type "
"SocketWriteError" ".\n Actual: it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_734; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->send(sendPkt)"
" throws an exception of type " "SocketWriteError" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_734; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->send(sendPkt)"
" throws an exception of type " "SocketWriteError" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_734; } } else gtest_label_testthrow_734
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 734, gtest_msg.value.c_str()) = ::testing::Message()
;
735
736 // Stop the thread. This should be no harm/no foul if we're not
737 // queueuing. Either way, we should not have a thread afterwards.
738 ASSERT_NO_THROW(ifacemgr->stopDHCPReceiver())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->stopDHCPReceiver(); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_738
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_738
; } } else gtest_label_testnothrow_738 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 738, ("Expected: " "ifacemgr->stopDHCPReceiver()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
739 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 739, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
740 }
741
742 /// @brief Verifies that IfaceMgr DHCPv4 receive calls detect and
743 /// ignore external sockets that have gone bad without affecting
744 /// affecting normal operations. It can be run with or without
745 /// packet queuing.
746 ///
747 /// @param use_queue determines if packet queuing is used or not.
748 void unusableExternalSockets4Test(bool use_queue = false) {
749 callback_ok = false;
750 callback2_ok = false;
751
752 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
753
754 if (use_queue) {
755 bool queue_enabled = false;
756 data::ConstElementPtr config = makeQueueConfig(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4, 500);
757 ASSERT_NO_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET, config))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
queue_enabled = ifacemgr->configureDHCPPacketQueue(2, config
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_757; } catch (...
) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_757
; } } else gtest_label_testnothrow_757 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 757, ("Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(2, config)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
758 ASSERT_TRUE(queue_enabled)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(queue_enabled)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 758, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "queue_enabled", "false", "true") .c_str()) = ::testing::Message
()
;
759
760 // Thread should only start when there is a packet queue.
761 ASSERT_NO_THROW(ifacemgr->startDHCPReceiver(AF_INET))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->startDHCPReceiver(2); } else static_assert(true
, ""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_761
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_761
; } } else gtest_label_testnothrow_761 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 761, ("Expected: " "ifacemgr->startDHCPReceiver(2)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
762 ASSERT_TRUE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->isDHCPReceiverRunning
())) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 762, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "false", "true") .c_str
()) = ::testing::Message()
;
763 }
764
765 // Create first pipe and register it as extra socket
766 int pipefd[2];
767 EXPECT_TRUE(pipe(pipefd) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(pipefd) == 0)) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 767, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(pipefd) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
768 ASSERT_FALSE(ifacemgr->isExternalSocket(pipefd[0]))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isExternalSocket
(pipefd[0])))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 768, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isExternalSocket(pipefd[0])", "true", "false"
) .c_str()) = ::testing::Message()
;
769 EXPECT_NO_THROW(ifacemgr->addExternalSocket(pipefd[0],switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(pipefd[0], [&pipefd](int fd
) { callback_ok = (pipefd[0] == fd); }); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_772; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_772; } } else gtest_label_testnothrow_772
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 772, ("Expected: " "ifacemgr->addExternalSocket(pipefd[0], [&pipefd](int fd) { callback_ok = (pipefd[0] == fd); })"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
770 [&pipefd](int fd) {switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(pipefd[0], [&pipefd](int fd
) { callback_ok = (pipefd[0] == fd); }); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_772; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_772; } } else gtest_label_testnothrow_772
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 772, ("Expected: " "ifacemgr->addExternalSocket(pipefd[0], [&pipefd](int fd) { callback_ok = (pipefd[0] == fd); })"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
771 callback_ok = (pipefd[0] == fd);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(pipefd[0], [&pipefd](int fd
) { callback_ok = (pipefd[0] == fd); }); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_772; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_772; } } else gtest_label_testnothrow_772
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 772, ("Expected: " "ifacemgr->addExternalSocket(pipefd[0], [&pipefd](int fd) { callback_ok = (pipefd[0] == fd); })"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
772 }))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(pipefd[0], [&pipefd](int fd
) { callback_ok = (pipefd[0] == fd); }); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_772; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_772; } } else gtest_label_testnothrow_772
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 772, ("Expected: " "ifacemgr->addExternalSocket(pipefd[0], [&pipefd](int fd) { callback_ok = (pipefd[0] == fd); })"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
773 ASSERT_TRUE(ifacemgr->isExternalSocket(pipefd[0]))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->isExternalSocket
(pipefd[0]))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 773, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isExternalSocket(pipefd[0])", "false", "true"
) .c_str()) = ::testing::Message()
;
774 ASSERT_FALSE(ifacemgr->isExternalSocketUnusable(pipefd[0]))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isExternalSocketUnusable
(pipefd[0])))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 774, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isExternalSocketUnusable(pipefd[0])", "true",
"false") .c_str()) = ::testing::Message()
;
775
776 // Let's create a second pipe and register it as well
777 int secondpipe[2];
778 EXPECT_TRUE(pipe(secondpipe) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(secondpipe) == 0
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 778, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(secondpipe) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
779 ASSERT_FALSE(ifacemgr->isExternalSocket(secondpipe[0]))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isExternalSocket
(secondpipe[0])))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 779, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isExternalSocket(secondpipe[0])", "true", "false"
) .c_str()) = ::testing::Message()
;
780 EXPECT_NO_THROW(ifacemgr->addExternalSocket(secondpipe[0],switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(secondpipe[0], [&secondpipe
](int fd) { callback2_ok = (secondpipe[0] == fd); }); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_783; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_783; } } else gtest_label_testnothrow_783
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 783, ("Expected: " "ifacemgr->addExternalSocket(secondpipe[0], [&secondpipe](int fd) { callback2_ok = (secondpipe[0] == fd); })"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
781 [&secondpipe](int fd) {switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(secondpipe[0], [&secondpipe
](int fd) { callback2_ok = (secondpipe[0] == fd); }); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_783; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_783; } } else gtest_label_testnothrow_783
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 783, ("Expected: " "ifacemgr->addExternalSocket(secondpipe[0], [&secondpipe](int fd) { callback2_ok = (secondpipe[0] == fd); })"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
782 callback2_ok = (secondpipe[0] == fd);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(secondpipe[0], [&secondpipe
](int fd) { callback2_ok = (secondpipe[0] == fd); }); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_783; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_783; } } else gtest_label_testnothrow_783
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 783, ("Expected: " "ifacemgr->addExternalSocket(secondpipe[0], [&secondpipe](int fd) { callback2_ok = (secondpipe[0] == fd); })"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
783 }))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(secondpipe[0], [&secondpipe
](int fd) { callback2_ok = (secondpipe[0] == fd); }); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_783; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_783; } } else gtest_label_testnothrow_783
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 783, ("Expected: " "ifacemgr->addExternalSocket(secondpipe[0], [&secondpipe](int fd) { callback2_ok = (secondpipe[0] == fd); })"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
784 ASSERT_TRUE(ifacemgr->isExternalSocket(secondpipe[0]))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->isExternalSocket
(secondpipe[0]))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 784, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isExternalSocket(secondpipe[0])", "false", "true"
) .c_str()) = ::testing::Message()
;
785 ASSERT_FALSE(ifacemgr->isExternalSocketUnusable(secondpipe[0]))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isExternalSocketUnusable
(secondpipe[0])))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 785, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isExternalSocketUnusable(secondpipe[0])", "true"
, "false") .c_str()) = ::testing::Message()
;
786
787 // Verify a call with no data and normal external sockets works ok.
788 Pkt4Ptr pkt4;
789 ASSERT_NO_THROW(pkt4 = ifacemgr->receive4(RECEIVE_WAIT_MS(10)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt4 = ifacemgr->receive4(0,(10*1000)); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_789; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_789; } } else gtest_label_testnothrow_789
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 789, ("Expected: " "pkt4 = ifacemgr->receive4(0,(10*1000))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
790
791 // No callback invocations and no DHCPv4 pkt.
792 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 792, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
793 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 793, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
794 EXPECT_FALSE(pkt4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 794, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt4", "true", "false") .c_str()) = ::testing::Message()
;
795
796 // Now close the first pipe. This should make it's external socket invalid.
797 close(pipefd[1]);
798 close(pipefd[0]);
799
800 // We call receive4() which should detect and remove the invalid socket.
801 try {
802 pkt4 = ifacemgr->receive4(RECEIVE_WAIT_MS(10)0,(10*1000));
803 } catch (const SocketFDError& ex) {
804 std::ostringstream err_msg;
805 err_msg << "unexpected state (closed) for fd: " << pipefd[0];
806 EXPECT_EQ(err_msg.str(), ex.what())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("err_msg.str()"
, "ex.what()", err_msg.str(), ex.what()))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 806, gtest_ar
.failure_message()) = ::testing::Message()
;
807 } catch (const std::exception& ex) {
808 ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 808, "Failed") = ::testing::Message()
<< "wrong exception thrown: " << ex.what();
809 }
810 EXPECT_TRUE(ifacemgr->isExternalSocketUnusable(pipefd[0]))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->isExternalSocketUnusable
(pipefd[0]))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 810, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isExternalSocketUnusable(pipefd[0])", "false"
, "true") .c_str()) = ::testing::Message()
;
811 EXPECT_FALSE(ifacemgr->isExternalSocketUnusable(secondpipe[0]))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isExternalSocketUnusable
(secondpipe[0])))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 811, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isExternalSocketUnusable(secondpipe[0])", "true"
, "false") .c_str()) = ::testing::Message()
;
812
813 // No callback invocations and no DHCPv4 pkt.
814 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 814, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
815 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 815, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
816 EXPECT_FALSE(pkt4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 816, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt4", "true", "false") .c_str()) = ::testing::Message()
;
817
818 // Now check whether the second callback is still functional
819 EXPECT_EQ(38, write(secondpipe[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(secondpipe[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(secondpipe[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 819, gtest_ar.failure_message()) = ::testing::Message()
;
820
821 // Call receive4 again, this should work.
822 ASSERT_NO_THROW(pkt4 = ifacemgr->receive4(RECEIVE_WAIT_MS(10)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt4 = ifacemgr->receive4(0,(10*1000)); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_822; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_822; } } else gtest_label_testnothrow_822
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 822, ("Expected: " "pkt4 = ifacemgr->receive4(0,(10*1000))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
823
824 // Should have callback2 data only.
825 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 825, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
826 EXPECT_TRUE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback2_ok)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 826, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "false", "true") .c_str()) = ::testing::Message
()
;
827 EXPECT_FALSE(pkt4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 827, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt4", "true", "false") .c_str()) = ::testing::Message()
;
828
829 // Stop the thread. This should be no harm/no foul if we're not
830 // queueuing. Either way, we should not have a thread afterwards.
831 ASSERT_NO_THROW(ifacemgr->stopDHCPReceiver())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->stopDHCPReceiver(); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_831
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_831
; } } else gtest_label_testnothrow_831 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 831, ("Expected: " "ifacemgr->stopDHCPReceiver()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
832 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 832, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
833 }
834
835 /// @brief Verifies that IfaceMgr DHCPv6 receive calls detect and
836 /// ignore external sockets that have gone bad without affecting
837 /// affecting normal operations. It can be run with or without
838 /// packet queuing.
839 ///
840 /// @param use_queue determines if packet queuing is used or not.
841 void unusableExternalSockets6Test(bool use_queue = false) {
842 callback_ok = false;
843 callback2_ok = false;
844
845 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
846
847 if (use_queue) {
848 bool queue_enabled = false;
849 data::ConstElementPtr config = makeQueueConfig(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6, 500);
850 ASSERT_NO_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET6, config))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
queue_enabled = ifacemgr->configureDHCPPacketQueue(10, config
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_850; } catch (...
) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_850
; } } else gtest_label_testnothrow_850 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 850, ("Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(10, config)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
851 ASSERT_TRUE(queue_enabled)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(queue_enabled)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 851, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "queue_enabled", "false", "true") .c_str()) = ::testing::Message
()
;
852
853 // Thread should only start when there is a packet queue.
854 ASSERT_NO_THROW(ifacemgr->startDHCPReceiver(AF_INET6))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->startDHCPReceiver(10); } else static_assert(true
, ""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_854
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_854
; } } else gtest_label_testnothrow_854 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 854, ("Expected: " "ifacemgr->startDHCPReceiver(10)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
855 ASSERT_TRUE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->isDHCPReceiverRunning
())) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 855, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "false", "true") .c_str
()) = ::testing::Message()
;
856 }
857
858 // Create first pipe and register it as extra socket
859 int pipefd[2];
860 EXPECT_TRUE(pipe(pipefd) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(pipefd) == 0)) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 860, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(pipefd) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
861 ASSERT_FALSE(ifacemgr->isExternalSocket(pipefd[0]))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isExternalSocket
(pipefd[0])))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 861, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isExternalSocket(pipefd[0])", "true", "false"
) .c_str()) = ::testing::Message()
;
862 EXPECT_NO_THROW(ifacemgr->addExternalSocket(pipefd[0],switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(pipefd[0], [&pipefd](int fd
) { callback_ok = (pipefd[0] == fd); }); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_865; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_865; } } else gtest_label_testnothrow_865
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 865, ("Expected: " "ifacemgr->addExternalSocket(pipefd[0], [&pipefd](int fd) { callback_ok = (pipefd[0] == fd); })"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
863 [&pipefd](int fd) {switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(pipefd[0], [&pipefd](int fd
) { callback_ok = (pipefd[0] == fd); }); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_865; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_865; } } else gtest_label_testnothrow_865
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 865, ("Expected: " "ifacemgr->addExternalSocket(pipefd[0], [&pipefd](int fd) { callback_ok = (pipefd[0] == fd); })"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
864 callback_ok = (pipefd[0] == fd);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(pipefd[0], [&pipefd](int fd
) { callback_ok = (pipefd[0] == fd); }); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_865; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_865; } } else gtest_label_testnothrow_865
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 865, ("Expected: " "ifacemgr->addExternalSocket(pipefd[0], [&pipefd](int fd) { callback_ok = (pipefd[0] == fd); })"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
865 }))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(pipefd[0], [&pipefd](int fd
) { callback_ok = (pipefd[0] == fd); }); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_865; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_865; } } else gtest_label_testnothrow_865
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 865, ("Expected: " "ifacemgr->addExternalSocket(pipefd[0], [&pipefd](int fd) { callback_ok = (pipefd[0] == fd); })"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
866 ASSERT_TRUE(ifacemgr->isExternalSocket(pipefd[0]))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->isExternalSocket
(pipefd[0]))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 866, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isExternalSocket(pipefd[0])", "false", "true"
) .c_str()) = ::testing::Message()
;
867 ASSERT_FALSE(ifacemgr->isExternalSocketUnusable(pipefd[0]))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isExternalSocketUnusable
(pipefd[0])))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 867, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isExternalSocketUnusable(pipefd[0])", "true",
"false") .c_str()) = ::testing::Message()
;
868
869 // Let's create a second pipe and register it as well
870 int secondpipe[2];
871 EXPECT_TRUE(pipe(secondpipe) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(secondpipe) == 0
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 871, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(secondpipe) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
872 ASSERT_FALSE(ifacemgr->isExternalSocket(secondpipe[0]))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isExternalSocket
(secondpipe[0])))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 872, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isExternalSocket(secondpipe[0])", "true", "false"
) .c_str()) = ::testing::Message()
;
873 EXPECT_NO_THROW(ifacemgr->addExternalSocket(secondpipe[0],switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(secondpipe[0], [&secondpipe
](int fd) { callback2_ok = (secondpipe[0] == fd); }); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_876; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_876; } } else gtest_label_testnothrow_876
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 876, ("Expected: " "ifacemgr->addExternalSocket(secondpipe[0], [&secondpipe](int fd) { callback2_ok = (secondpipe[0] == fd); })"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
874 [&secondpipe](int fd) {switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(secondpipe[0], [&secondpipe
](int fd) { callback2_ok = (secondpipe[0] == fd); }); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_876; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_876; } } else gtest_label_testnothrow_876
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 876, ("Expected: " "ifacemgr->addExternalSocket(secondpipe[0], [&secondpipe](int fd) { callback2_ok = (secondpipe[0] == fd); })"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
875 callback2_ok = (secondpipe[0] == fd);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(secondpipe[0], [&secondpipe
](int fd) { callback2_ok = (secondpipe[0] == fd); }); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_876; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_876; } } else gtest_label_testnothrow_876
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 876, ("Expected: " "ifacemgr->addExternalSocket(secondpipe[0], [&secondpipe](int fd) { callback2_ok = (secondpipe[0] == fd); })"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
876 }))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(secondpipe[0], [&secondpipe
](int fd) { callback2_ok = (secondpipe[0] == fd); }); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_876; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_876; } } else gtest_label_testnothrow_876
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 876, ("Expected: " "ifacemgr->addExternalSocket(secondpipe[0], [&secondpipe](int fd) { callback2_ok = (secondpipe[0] == fd); })"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
877 ASSERT_TRUE(ifacemgr->isExternalSocket(secondpipe[0]))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->isExternalSocket
(secondpipe[0]))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 877, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isExternalSocket(secondpipe[0])", "false", "true"
) .c_str()) = ::testing::Message()
;
878 ASSERT_FALSE(ifacemgr->isExternalSocketUnusable(secondpipe[0]))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isExternalSocketUnusable
(secondpipe[0])))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 878, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isExternalSocketUnusable(secondpipe[0])", "true"
, "false") .c_str()) = ::testing::Message()
;
879
880 // Verify a call with no data and normal external sockets works ok.
881 Pkt6Ptr pkt6;
882 ASSERT_NO_THROW(pkt6 = ifacemgr->receive6(RECEIVE_WAIT_MS(10)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt6 = ifacemgr->receive6(0,(10*1000)); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_882; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_882; } } else gtest_label_testnothrow_882
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 882, ("Expected: " "pkt6 = ifacemgr->receive6(0,(10*1000))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
883
884 // No callback invocations and no DHCPv6 pkt.
885 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 885, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
886 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 886, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
887 EXPECT_FALSE(pkt6)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 887, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt6", "true", "false") .c_str()) = ::testing::Message()
;
888
889 // Now close the first pipe. This should make it's external socket invalid.
890 close(pipefd[1]);
891 close(pipefd[0]);
892
893 // We call receive6() which should detect and remove the invalid socket.
894 try {
895 pkt6 = ifacemgr->receive6(RECEIVE_WAIT_MS(10)0,(10*1000));
896 } catch (const SocketFDError& ex) {
897 std::ostringstream err_msg;
898 err_msg << "unexpected state (closed) for fd: " << pipefd[0];
899 EXPECT_EQ(err_msg.str(), ex.what())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("err_msg.str()"
, "ex.what()", err_msg.str(), ex.what()))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 899, gtest_ar
.failure_message()) = ::testing::Message()
;
900 } catch (const std::exception& ex) {
901 ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 901, "Failed") = ::testing::Message()
<< "wrong exception thrown: " << ex.what();
902 }
903 EXPECT_TRUE(ifacemgr->isExternalSocketUnusable(pipefd[0]))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->isExternalSocketUnusable
(pipefd[0]))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 903, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isExternalSocketUnusable(pipefd[0])", "false"
, "true") .c_str()) = ::testing::Message()
;
904 EXPECT_FALSE(ifacemgr->isExternalSocketUnusable(secondpipe[0]))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isExternalSocketUnusable
(secondpipe[0])))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 904, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isExternalSocketUnusable(secondpipe[0])", "true"
, "false") .c_str()) = ::testing::Message()
;
905
906 // No callback invocations and no DHCPv6 pkt.
907 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 907, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
908 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 908, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
909 EXPECT_FALSE(pkt6)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 909, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt6", "true", "false") .c_str()) = ::testing::Message()
;
910
911 // Now check whether the second callback is still functional
912 EXPECT_EQ(38, write(secondpipe[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(secondpipe[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(secondpipe[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 912, gtest_ar.failure_message()) = ::testing::Message()
;
913
914 // Call receive6 again, this should work.
915 ASSERT_NO_THROW(pkt6 = ifacemgr->receive6(RECEIVE_WAIT_MS(10)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt6 = ifacemgr->receive6(0,(10*1000)); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_915; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_915; } } else gtest_label_testnothrow_915
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 915, ("Expected: " "pkt6 = ifacemgr->receive6(0,(10*1000))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
916
917 // Should have callback2 data only.
918 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 918, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
919 EXPECT_TRUE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback2_ok)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 919, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "false", "true") .c_str()) = ::testing::Message
()
;
920 EXPECT_FALSE(pkt6)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 920, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt6", "true", "false") .c_str()) = ::testing::Message()
;
921
922 // Stop the thread. This should be no harm/no foul if we're not
923 // queueuing. Either way, we should not have a thread afterwards.
924 ASSERT_NO_THROW(ifacemgr->stopDHCPReceiver())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->stopDHCPReceiver(); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_924
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_924
; } } else gtest_label_testnothrow_924 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 924, ("Expected: " "ifacemgr->stopDHCPReceiver()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
925 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 925, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
926 }
927
928 /// @brief test receive timeout (v6).
929 void testReceiveTimeout6();
930
931 /// @brief test receive timeout (v4).
932 void testReceiveTimeout4();
933
934 /// @brief Tests single external socket (v4).
935 void testSingleExternalSocket4();
936
937 /// @brief Tests multiple external sockets (v4);
938 void testMultipleExternalSockets4();
939
940 /// @brief Tests if existing external socket can be deleted (v4).
941 void testDeleteExternalSockets4();
942
943 /// @brief Tests single external socket (v6).
944 void testSingleExternalSocket6();
945
946 /// @brief Tests multiple external sockets (v6);
947 void testMultipleExternalSockets6();
948
949 /// @brief Tests if existing external socket can be deleted (v6).
950 void testDeleteExternalSockets6();
951
952 /// @brief Verifies that IfaceMgr DHCPv4 receive calls follow
953 /// a LRU order.
954 void lruExternalSockets4Test() {
955 callback_ok = false;
956 callback2_ok = false;
957
958 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
959
960 // Create 3 watch sockets.
961 WatchSocket ws0;
962 WatchSocket ws1;
963 WatchSocket ws2;
964
965 // Register them. the first with no handle.
966 EXPECT_NO_THROW(ifacemgr->addExternalSocket(ws0.getSelectFd(), 0))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(ws0.getSelectFd(), 0); } else
static_assert(true, ""); } catch (std::exception const& e
) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_966; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_966; } } else gtest_label_testnothrow_966
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 966, ("Expected: " "ifacemgr->addExternalSocket(ws0.getSelectFd(), 0)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
967 auto handler1 = [&ws1](int) {
968 callback_ok = true;
969 EXPECT_NO_THROW(ws1.clearReady())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ws1.clearReady(); } else static_assert(true, ""); } catch (std
::exception const& e) { gtest_msg.value = "it throws "; gtest_msg
.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg
.value += " with description \""; gtest_msg.value += e.what()
; gtest_msg.value += "\"."; goto gtest_label_testnothrow_969;
} catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_969
; } } else gtest_label_testnothrow_969 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 969, ("Expected: " "ws1.clearReady()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
970 };
971 EXPECT_NO_THROW(ifacemgr->addExternalSocket(ws1.getSelectFd(), handler1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(ws1.getSelectFd(), handler1);
} else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_971; } catch (...
) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_971
; } } else gtest_label_testnothrow_971 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 971, ("Expected: " "ifacemgr->addExternalSocket(ws1.getSelectFd(), handler1)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
972 auto handler2 = [&ws2](int) {
973 callback2_ok = true;
974 EXPECT_NO_THROW(ws2.clearReady())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ws2.clearReady(); } else static_assert(true, ""); } catch (std
::exception const& e) { gtest_msg.value = "it throws "; gtest_msg
.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg
.value += " with description \""; gtest_msg.value += e.what()
; gtest_msg.value += "\"."; goto gtest_label_testnothrow_974;
} catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_974
; } } else gtest_label_testnothrow_974 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 974, ("Expected: " "ws2.clearReady()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
975 };
976 EXPECT_NO_THROW(ifacemgr->addExternalSocket(ws2.getSelectFd(), handler2))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(ws2.getSelectFd(), handler2);
} else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_976; } catch (...
) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_976
; } } else gtest_label_testnothrow_976 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 976, ("Expected: " "ifacemgr->addExternalSocket(ws2.getSelectFd(), handler2)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
977
978 // Mark all watch sockets as ready.
979 ws0.markReady();
980 ws1.markReady();
981 ws2.markReady();
982 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 982, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
983 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 983, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
984
985 /// Check the order before the first call to receive4.
986 std::list<int> expected;
987 expected.push_back(ws0.getSelectFd());
988 expected.push_back(ws1.getSelectFd());
989 expected.push_back(ws2.getSelectFd());
990 EXPECT_EQ(expected, ifacemgr->getAllExternalSockets())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("expected"
, "ifacemgr->getAllExternalSockets()", expected, ifacemgr->
getAllExternalSockets()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 990, gtest_ar.failure_message()) = ::testing::Message()
;
991
992 // First call to receive4: ws0 and ws1 are scanned and moved.
993 Pkt4Ptr pkt4;
994 ASSERT_NO_THROW(pkt4 = ifacemgr->receive4(RECEIVE_WAIT_MS(10)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt4 = ifacemgr->receive4(0,(10*1000)); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_994; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_994; } } else gtest_label_testnothrow_994
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 994, ("Expected: " "pkt4 = ifacemgr->receive4(0,(10*1000))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
995 EXPECT_TRUE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback_ok)) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 995, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"callback_ok", "false", "true") .c_str()) = ::testing::Message
()
;
996 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 996, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
997 EXPECT_FALSE(pkt4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 997, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt4", "true", "false") .c_str()) = ::testing::Message()
;
998 expected.clear();
999 expected.push_back(ws2.getSelectFd());
1000 expected.push_back(ws0.getSelectFd());
1001 expected.push_back(ws1.getSelectFd());
1002 EXPECT_EQ(expected, ifacemgr->getAllExternalSockets())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("expected"
, "ifacemgr->getAllExternalSockets()", expected, ifacemgr->
getAllExternalSockets()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1002, gtest_ar.failure_message()) = ::testing::Message()
;
1003
1004 // Second call to receive4: ws2 is scanned and moved.
1005 callback_ok = false;
1006 ASSERT_NO_THROW(pkt4 = ifacemgr->receive4(RECEIVE_WAIT_MS(10)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt4 = ifacemgr->receive4(0,(10*1000)); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1006; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1006; } } else gtest_label_testnothrow_1006
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1006, ("Expected: " "pkt4 = ifacemgr->receive4(0,(10*1000))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1007 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1007, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1008 EXPECT_TRUE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback2_ok)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1008, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "false", "true") .c_str()) = ::testing::Message
()
;
1009 EXPECT_FALSE(pkt4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1009, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt4", "true", "false") .c_str()) = ::testing::Message()
;
1010 expected.clear();
1011 expected.push_back(ws0.getSelectFd());
1012 expected.push_back(ws1.getSelectFd());
1013 expected.push_back(ws2.getSelectFd());
1014 EXPECT_EQ(expected, ifacemgr->getAllExternalSockets())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("expected"
, "ifacemgr->getAllExternalSockets()", expected, ifacemgr->
getAllExternalSockets()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1014, gtest_ar.failure_message()) = ::testing::Message()
;
1015
1016 // Third call to receive4: ws0 is scanned and moved.
1017 callback_ok = false;
1018 callback2_ok = false;
1019 ASSERT_NO_THROW(pkt4 = ifacemgr->receive4(RECEIVE_WAIT_MS(10)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt4 = ifacemgr->receive4(0,(10*1000)); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1019; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1019; } } else gtest_label_testnothrow_1019
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1019, ("Expected: " "pkt4 = ifacemgr->receive4(0,(10*1000))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1020 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1020, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1021 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1021, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1022 EXPECT_FALSE(pkt4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1022, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt4", "true", "false") .c_str()) = ::testing::Message()
;
1023 expected.clear();
1024 expected.push_back(ws1.getSelectFd());
1025 expected.push_back(ws2.getSelectFd());
1026 expected.push_back(ws0.getSelectFd());
1027 EXPECT_EQ(expected, ifacemgr->getAllExternalSockets())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("expected"
, "ifacemgr->getAllExternalSockets()", expected, ifacemgr->
getAllExternalSockets()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1027, gtest_ar.failure_message()) = ::testing::Message()
;
1028
1029 EXPECT_NO_THROW(ws0.clearReady())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ws0.clearReady(); } else static_assert(true, ""); } catch (std
::exception const& e) { gtest_msg.value = "it throws "; gtest_msg
.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg
.value += " with description \""; gtest_msg.value += e.what()
; gtest_msg.value += "\"."; goto gtest_label_testnothrow_1029
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1029
; } } else gtest_label_testnothrow_1029 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1029, ("Expected: " "ws0.clearReady()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
1030 std::string err;
1031 EXPECT_NO_THROW(ws0.closeSocket(err))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ws0.closeSocket(err); } else static_assert(true, ""); } catch
(std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1031
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1031
; } } else gtest_label_testnothrow_1031 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1031, ("Expected: " "ws0.closeSocket(err)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
1032 EXPECT_EQ("", err)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"\"", "err"
, "", err))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1032, gtest_ar.failure_message()) = ::testing::Message()
;
1033 EXPECT_NO_THROW(ws1.closeSocket(err))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ws1.closeSocket(err); } else static_assert(true, ""); } catch
(std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1033
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1033
; } } else gtest_label_testnothrow_1033 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1033, ("Expected: " "ws1.closeSocket(err)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
1034 EXPECT_EQ("", err)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"\"", "err"
, "", err))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1034, gtest_ar.failure_message()) = ::testing::Message()
;
1035 EXPECT_NO_THROW(ws2.closeSocket(err))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ws2.closeSocket(err); } else static_assert(true, ""); } catch
(std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1035
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1035
; } } else gtest_label_testnothrow_1035 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1035, ("Expected: " "ws2.closeSocket(err)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
1036 EXPECT_EQ("", err)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"\"", "err"
, "", err))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1036, gtest_ar.failure_message()) = ::testing::Message()
;
1037 }
1038
1039 /// @brief Verifies that IfaceMgr DHCPv6 receive calls follow
1040 /// a LRU order.
1041 void lruExternalSockets6Test() {
1042 callback_ok = false;
1043 callback2_ok = false;
1044
1045 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
1046
1047 // Create 3 watch sockets.
1048 WatchSocket ws0;
1049 WatchSocket ws1;
1050 WatchSocket ws2;
1051
1052 // Register them. the first with no handle.
1053 EXPECT_NO_THROW(ifacemgr->addExternalSocket(ws0.getSelectFd(), 0))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(ws0.getSelectFd(), 0); } else
static_assert(true, ""); } catch (std::exception const& e
) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1053; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1053; } } else gtest_label_testnothrow_1053
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1053, ("Expected: " "ifacemgr->addExternalSocket(ws0.getSelectFd(), 0)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1054 auto handler1 = [&ws1](int) {
1055 callback_ok = true;
1056 EXPECT_NO_THROW(ws1.clearReady())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ws1.clearReady(); } else static_assert(true, ""); } catch (std
::exception const& e) { gtest_msg.value = "it throws "; gtest_msg
.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg
.value += " with description \""; gtest_msg.value += e.what()
; gtest_msg.value += "\"."; goto gtest_label_testnothrow_1056
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1056
; } } else gtest_label_testnothrow_1056 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1056, ("Expected: " "ws1.clearReady()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
1057 };
1058 EXPECT_NO_THROW(ifacemgr->addExternalSocket(ws1.getSelectFd(), handler1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(ws1.getSelectFd(), handler1);
} else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_1058; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1058
; } } else gtest_label_testnothrow_1058 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1058, ("Expected: " "ifacemgr->addExternalSocket(ws1.getSelectFd(), handler1)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1059 auto handler2 = [&ws2](int) {
1060 callback2_ok = true;
1061 EXPECT_NO_THROW(ws2.clearReady())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ws2.clearReady(); } else static_assert(true, ""); } catch (std
::exception const& e) { gtest_msg.value = "it throws "; gtest_msg
.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg
.value += " with description \""; gtest_msg.value += e.what()
; gtest_msg.value += "\"."; goto gtest_label_testnothrow_1061
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1061
; } } else gtest_label_testnothrow_1061 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1061, ("Expected: " "ws2.clearReady()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
1062 };
1063 EXPECT_NO_THROW(ifacemgr->addExternalSocket(ws2.getSelectFd(), handler2))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(ws2.getSelectFd(), handler2);
} else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_1063; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1063
; } } else gtest_label_testnothrow_1063 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1063, ("Expected: " "ifacemgr->addExternalSocket(ws2.getSelectFd(), handler2)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1064
1065 // Mark all watch sockets as ready.
1066 ws0.markReady();
1067 ws1.markReady();
1068 ws2.markReady();
1069 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1069, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1070 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1070, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1071
1072 /// Check the order before the first call to receive6.
1073 std::list<int> expected;
1074 expected.push_back(ws0.getSelectFd());
1075 expected.push_back(ws1.getSelectFd());
1076 expected.push_back(ws2.getSelectFd());
1077 EXPECT_EQ(expected, ifacemgr->getAllExternalSockets())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("expected"
, "ifacemgr->getAllExternalSockets()", expected, ifacemgr->
getAllExternalSockets()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1077, gtest_ar.failure_message()) = ::testing::Message()
;
1078
1079 // First call to receive6: ws0 and ws1 are scanned and moved.
1080 Pkt6Ptr pkt6;
1081 ASSERT_NO_THROW(pkt6 = ifacemgr->receive6(RECEIVE_WAIT_MS(10)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt6 = ifacemgr->receive6(0,(10*1000)); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1081; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1081; } } else gtest_label_testnothrow_1081
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1081, ("Expected: " "pkt6 = ifacemgr->receive6(0,(10*1000))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1082 EXPECT_TRUE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback_ok)) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1082, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"callback_ok", "false", "true") .c_str()) = ::testing::Message
()
;
1083 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1083, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1084 EXPECT_FALSE(pkt6)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1084, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt6", "true", "false") .c_str()) = ::testing::Message()
;
1085 expected.clear();
1086 expected.push_back(ws2.getSelectFd());
1087 expected.push_back(ws0.getSelectFd());
1088 expected.push_back(ws1.getSelectFd());
1089 EXPECT_EQ(expected, ifacemgr->getAllExternalSockets())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("expected"
, "ifacemgr->getAllExternalSockets()", expected, ifacemgr->
getAllExternalSockets()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1089, gtest_ar.failure_message()) = ::testing::Message()
;
1090
1091 // Second call to receive6: ws2 is scanned and moved.
1092 callback_ok = false;
1093 ASSERT_NO_THROW(pkt6 = ifacemgr->receive6(RECEIVE_WAIT_MS(10)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt6 = ifacemgr->receive6(0,(10*1000)); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1093; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1093; } } else gtest_label_testnothrow_1093
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1093, ("Expected: " "pkt6 = ifacemgr->receive6(0,(10*1000))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1094 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1094, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1095 EXPECT_TRUE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback2_ok)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1095, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "false", "true") .c_str()) = ::testing::Message
()
;
1096 EXPECT_FALSE(pkt6)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1096, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt6", "true", "false") .c_str()) = ::testing::Message()
;
1097 expected.clear();
1098 expected.push_back(ws0.getSelectFd());
1099 expected.push_back(ws1.getSelectFd());
1100 expected.push_back(ws2.getSelectFd());
1101 EXPECT_EQ(expected, ifacemgr->getAllExternalSockets())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("expected"
, "ifacemgr->getAllExternalSockets()", expected, ifacemgr->
getAllExternalSockets()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1101, gtest_ar.failure_message()) = ::testing::Message()
;
1102
1103 // Third call to receive6: ws0 is scanned and moved.
1104 callback_ok = false;
1105 callback2_ok = false;
1106 ASSERT_NO_THROW(pkt6 = ifacemgr->receive6(RECEIVE_WAIT_MS(10)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt6 = ifacemgr->receive6(0,(10*1000)); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1106; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1106; } } else gtest_label_testnothrow_1106
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1106, ("Expected: " "pkt6 = ifacemgr->receive6(0,(10*1000))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1107 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1107, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1108 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1108, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1109 EXPECT_FALSE(pkt6)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1109, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt6", "true", "false") .c_str()) = ::testing::Message()
;
1110 expected.clear();
1111 expected.push_back(ws1.getSelectFd());
1112 expected.push_back(ws2.getSelectFd());
1113 expected.push_back(ws0.getSelectFd());
1114 EXPECT_EQ(expected, ifacemgr->getAllExternalSockets())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("expected"
, "ifacemgr->getAllExternalSockets()", expected, ifacemgr->
getAllExternalSockets()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1114, gtest_ar.failure_message()) = ::testing::Message()
;
1115
1116 EXPECT_NO_THROW(ws0.clearReady())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ws0.clearReady(); } else static_assert(true, ""); } catch (std
::exception const& e) { gtest_msg.value = "it throws "; gtest_msg
.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg
.value += " with description \""; gtest_msg.value += e.what()
; gtest_msg.value += "\"."; goto gtest_label_testnothrow_1116
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1116
; } } else gtest_label_testnothrow_1116 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1116, ("Expected: " "ws0.clearReady()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
1117 std::string err;
1118 EXPECT_NO_THROW(ws0.closeSocket(err))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ws0.closeSocket(err); } else static_assert(true, ""); } catch
(std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1118
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1118
; } } else gtest_label_testnothrow_1118 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1118, ("Expected: " "ws0.closeSocket(err)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
1119 EXPECT_EQ("", err)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"\"", "err"
, "", err))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1119, gtest_ar.failure_message()) = ::testing::Message()
;
1120 EXPECT_NO_THROW(ws1.closeSocket(err))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ws1.closeSocket(err); } else static_assert(true, ""); } catch
(std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1120
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1120
; } } else gtest_label_testnothrow_1120 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1120, ("Expected: " "ws1.closeSocket(err)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
1121 EXPECT_EQ("", err)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"\"", "err"
, "", err))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1121, gtest_ar.failure_message()) = ::testing::Message()
;
1122 EXPECT_NO_THROW(ws2.closeSocket(err))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ws2.closeSocket(err); } else static_assert(true, ""); } catch
(std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1122
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1122
; } } else gtest_label_testnothrow_1122 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1122, ("Expected: " "ws2.closeSocket(err)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
1123 EXPECT_EQ("", err)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"\"", "err"
, "", err))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1123, gtest_ar.failure_message()) = ::testing::Message()
;
1124 }
1125
1126 /// @brief Test that all sockets are rotated when they are under load.
1127 ///
1128 /// @param direct Flag which indicates if direct or indirect receive should
1129 /// be used.
1130 void testReceive4RotateAll(bool direct = true) {
1131 const size_t loop_count = 1024;
1132 IfaceMgr::instance().clearIfaces();
1133 IfaceMgr::instance().deleteAllExternalSockets();
1134 callback_ok = false;
1135 callback2_ok = false;
1136 size_t callback_count = 0;
1137 size_t callback2_count = 0;
1138 PktFilterPtr filter(new PktFilter4IfaceSocketTest(true, false));
1139 IfaceMgr::instance().setPacketFilter(filter);
1140 IfacePtr iface0(new Iface("eth0", 0));
1141 iface0->flag_up_ = true;
1142 iface0->flag_running_ = true;
1143 iface0->addAddress(IOAddress("192.168.0.1"));
1144 IfaceMgr::instance().addInterface(iface0);
1145 IfacePtr iface1(new Iface("eth1", 1));
1146 iface1->flag_up_ = true;
1147 iface1->flag_running_ = true;
1148 iface1->addAddress(IOAddress("192.168.0.2"));
1149 IfaceMgr::instance().addInterface(iface1);
1150 IfacePtr iface2(new Iface("eth2", 2));
1151 iface2->flag_up_ = true;
1152 iface2->flag_running_ = true;
1153 iface2->addAddress(IOAddress("192.168.0.3"));
1154 IfaceMgr::instance().addInterface(iface2);
1155 for (size_t i = 3; i < 250; ++i) {
1156 string name = "eth";
1157 name += std::to_string(i);
1158 IfacePtr iface_n(new Iface(name, i));
1159 iface_n->flag_up_ = true;
1160 iface_n->flag_running_ = true;
1161 iface_n->addAddress(IOAddress(string("192.168.0.") + std::to_string(i)));
1162 IfaceMgr::instance().addInterface(iface_n);
1163 }
1164 if (!direct) {
1165 auto queue_control = makeQueueConfig(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4, 50000, true);
1166 IfaceMgr::instance().configureDHCPPacketQueue(AF_INET2, queue_control);
1167 } else {
1168 IfaceMgr::instance().configureDHCPPacketQueue(AF_INET2, data::ConstElementPtr());
1169 }
1170 IfaceMgr::instance().openSockets4(9999, true, IfaceMgrErrorMsgCallback(), false);
1171 EXPECT_EQ((boost::dynamic_pointer_cast<PktFilter4IfaceSocketTest>(filter))->socket_fds_.size(), 250U)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("(boost::dynamic_pointer_cast<PktFilter4IfaceSocketTest>(filter))->socket_fds_.size()"
, "250U", (boost::dynamic_pointer_cast<PktFilter4IfaceSocketTest
>(filter))->socket_fds_.size(), 250U))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1171, gtest_ar
.failure_message()) = ::testing::Message()
;
1172
1173 // Create first pipe and register it as extra socket
1174 int pipefd[2];
1175 EXPECT_TRUE(pipe(pipefd) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(pipefd) == 0)) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1175, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(pipefd) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
1176 EXPECT_NO_THROW(IfaceMgr::instance().addExternalSocket(pipefd[0], my_callback))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().addExternalSocket(pipefd[0], my_callback
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_1176; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1176
; } } else gtest_label_testnothrow_1176 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1176, ("Expected: " "IfaceMgr::instance().addExternalSocket(pipefd[0], my_callback)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1177
1178 // Let's create a second pipe and register it as well
1179 int secondpipe[2];
1180 EXPECT_TRUE(pipe(secondpipe) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(secondpipe) == 0
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1180, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(secondpipe) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
1181 EXPECT_NO_THROW(IfaceMgr::instance().addExternalSocket(secondpipe[0], my_callback2))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().addExternalSocket(secondpipe[0], my_callback2
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_1181; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1181
; } } else gtest_label_testnothrow_1181 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1181, ("Expected: " "IfaceMgr::instance().addExternalSocket(secondpipe[0], my_callback2)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1182
1183 Pkt4Ptr pkt4;
1184 ASSERT_NO_THROW(pkt4 = IfaceMgr::instance().receive4(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt4 = IfaceMgr::instance().receive4(1); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1184; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1184; } } else gtest_label_testnothrow_1184
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1184, ("Expected: " "pkt4 = IfaceMgr::instance().receive4(1)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1185
1186 // Our callbacks should not be called this time (there was no data)
1187 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1187, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1188 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1188, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1189
1190 // IfaceMgr should not process control socket data as incoming packets
1191 EXPECT_FALSE(pkt4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1191, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt4", "true", "false") .c_str()) = ::testing::Message()
;
1192
1193 // Now, send some data over the first pipe (38 bytes)
1194 EXPECT_EQ(38, write(pipefd[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(pipefd[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(pipefd[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1194, gtest_ar.failure_message()) = ::testing::Message()
;
1195
1196 // And try again, using the second pipe
1197 EXPECT_EQ(38, write(secondpipe[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(secondpipe[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(secondpipe[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1197, gtest_ar.failure_message()) = ::testing::Message()
;
1198
1199 Pkt4Ptr pkt0(new Pkt4(DHCPDISCOVER, 1234));
1200 pkt0->setIface("eth0");
1201 pkt0->setIndex(0);
1202 Pkt4Ptr pkt1(new Pkt4(DHCPDISCOVER, 2345));
1203 pkt1->setIface("eth1");
1204 pkt1->setIndex(1);
1205 Pkt4Ptr pkt2(new Pkt4(DHCPDISCOVER, 3456));
1206 pkt2->setIface("eth2");
1207 pkt2->setIndex(2);
1208 IfaceMgr::instance().send(pkt0);
1209 IfaceMgr::instance().send(pkt1);
1210 IfaceMgr::instance().send(pkt2);
1211 std::unordered_map<Pkt4Ptr, size_t, hash_pkt4> expected;
1212 expected[pkt0] = 0;
1213 expected[pkt1] = 0;
1214 expected[pkt2] = 0;
1215 bool first = true;
1216 size_t j = 0;
1217 for (size_t i = 0; i < 3 * loop_count && j < 20 * loop_count;) {
1218 Pkt4Ptr new_pkt = IfaceMgr::instance().receive4(1, 0);
1219 if (first) {
1220 first = false;
1221 EXPECT_TRUE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback_ok)) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1221, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"callback_ok", "false", "true") .c_str()) = ::testing::Message
()
;
1222 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1222, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1223 callback_count++;
1224 } else {
1225 first = true;
1226 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1226, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1227 EXPECT_TRUE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback2_ok)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1227, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "false", "true") .c_str()) = ::testing::Message
()
;
1228 callback2_count++;
1229 }
1230 callback_ok = false;
1231 callback2_ok = false;
1232 if (new_pkt) {
1233 expected[new_pkt]++;
1234 if (i % 3 == 0) {
1235 EXPECT_EQ(new_pkt.get(), pkt0.get())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("new_pkt.get()"
, "pkt0.get()", new_pkt.get(), pkt0.get()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1235, gtest_ar
.failure_message()) = ::testing::Message()
;
1236 } else if (i % 3 == 1) {
1237 EXPECT_EQ(new_pkt.get(), pkt1.get())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("new_pkt.get()"
, "pkt1.get()", new_pkt.get(), pkt1.get()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1237, gtest_ar
.failure_message()) = ::testing::Message()
;
1238 } else {
1239 EXPECT_EQ(new_pkt.get(), pkt2.get())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("new_pkt.get()"
, "pkt2.get()", new_pkt.get(), pkt2.get()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1239, gtest_ar
.failure_message()) = ::testing::Message()
;
1240 }
1241 i++;
1242 } else {
1243 j++;
1244 }
1245 }
1246
1247 for (auto i = expected.begin(); i!= expected.end(); ++i) {
1248 EXPECT_EQ(loop_count, i->second)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("loop_count"
, "i->second", loop_count, i->second))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1248, gtest_ar
.failure_message()) = ::testing::Message()
;
1249 }
1250
1251 EXPECT_EQ((3 * loop_count + j) / 2 + j % 2, callback_count)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("(3 * loop_count + j) / 2 + j % 2"
, "callback_count", (3 * loop_count + j) / 2 + j % 2, callback_count
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1251, gtest_ar.failure_message()) = ::testing::Message()
;
1252 EXPECT_EQ((3 * loop_count + j) / 2, callback2_count)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("(3 * loop_count + j) / 2"
, "callback2_count", (3 * loop_count + j) / 2, callback2_count
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1252, gtest_ar.failure_message()) = ::testing::Message()
;
1253
1254 // close both pipe ends
1255 close(pipefd[1]);
1256 close(pipefd[0]);
1257
1258 close(secondpipe[1]);
1259 close(secondpipe[0]);
1260
1261 ASSERT_NO_THROW(IfaceMgr::instance().stopDHCPReceiver())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().stopDHCPReceiver(); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1261; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1261; } } else gtest_label_testnothrow_1261
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1261, ("Expected: " "IfaceMgr::instance().stopDHCPReceiver()"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1262 }
1263
1264 /// @brief Test that all sockets are rotated when they are under load.
1265 ///
1266 /// @param direct Flag which indicates if direct or indirect receive should
1267 /// be used.
1268 void testReceive6RotateAll(bool direct = true) {
1269 const size_t loop_count = 1024;
1270 IfaceMgr::instance().clearIfaces();
1271 IfaceMgr::instance().deleteAllExternalSockets();
1272 callback_ok = false;
1273 callback2_ok = false;
1274 size_t callback_count = 0;
1275 size_t callback2_count = 0;
1276 PktFilter6Ptr filter(new PktFilter6IfaceSocketTest(true, false));
1277 IfaceMgr::instance().setPacketFilter(filter);
1278 IfacePtr iface0(new Iface("eth0", 0));
1279 iface0->flag_up_ = true;
1280 iface0->flag_running_ = true;
1281 iface0->addAddress(IOAddress("2003:db8::1"));
1282 iface0->addAddress(IOAddress("fe80::3a60:77ff:fed5:abcd"));
1283 IfaceMgr::instance().addInterface(iface0);
1284 IfacePtr iface1(new Iface("eth1", 1));
1285 iface1->flag_up_ = true;
1286 iface1->flag_running_ = true;
1287 iface1->addAddress(IOAddress("2003:db8::2"));
1288 iface1->addAddress(IOAddress("fe80::3a60:77ff:fed5:bcde"));
1289 IfaceMgr::instance().addInterface(iface1);
1290 IfacePtr iface2(new Iface("eth2", 2));
1291 iface2->flag_up_ = true;
1292 iface2->flag_running_ = true;
1293 iface2->addAddress(IOAddress("2003:db8::3"));
1294 iface2->addAddress(IOAddress("fe80::3a60:77ff:fed5:cdef"));
1295 IfaceMgr::instance().addInterface(iface2);
1296 for (size_t i = 3; i < 250; ++i) {
1297 string name = "eth";
1298 name += std::to_string(i);
1299 IfacePtr iface_n(new Iface(name, i));
1300 iface_n->flag_up_ = true;
1301 iface_n->flag_running_ = true;
1302 iface_n->addAddress(IOAddress(string("2003:db8::") + std::to_string(i)));
1303 iface_n->addAddress(IOAddress(string("fe80::3a60:77ff:fed5:") + std::to_string(i)));
1304 IfaceMgr::instance().addInterface(iface_n);
1305 }
1306 if (!direct) {
1307 auto queue_control = makeQueueConfig(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6, 50000, true);
1308 IfaceMgr::instance().configureDHCPPacketQueue(AF_INET610, queue_control);
1309 } else {
1310 IfaceMgr::instance().configureDHCPPacketQueue(AF_INET610, data::ConstElementPtr());
1311 }
1312 IfaceMgr::instance().openSockets6(9999, IfaceMgrErrorMsgCallback(), false);
1313 EXPECT_EQ((boost::dynamic_pointer_cast<PktFilter6IfaceSocketTest>(filter))->socket_fds_.size(), 250U)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("(boost::dynamic_pointer_cast<PktFilter6IfaceSocketTest>(filter))->socket_fds_.size()"
, "250U", (boost::dynamic_pointer_cast<PktFilter6IfaceSocketTest
>(filter))->socket_fds_.size(), 250U))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1313, gtest_ar
.failure_message()) = ::testing::Message()
;
1314
1315 // Create first pipe and register it as extra socket
1316 int pipefd[2];
1317 EXPECT_TRUE(pipe(pipefd) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(pipefd) == 0)) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1317, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(pipefd) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
1318 EXPECT_NO_THROW(IfaceMgr::instance().addExternalSocket(pipefd[0], my_callback))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().addExternalSocket(pipefd[0], my_callback
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_1318; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1318
; } } else gtest_label_testnothrow_1318 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1318, ("Expected: " "IfaceMgr::instance().addExternalSocket(pipefd[0], my_callback)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1319
1320 // Let's create a second pipe and register it as well
1321 int secondpipe[2];
1322 EXPECT_TRUE(pipe(secondpipe) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(secondpipe) == 0
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1322, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(secondpipe) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
1323 EXPECT_NO_THROW(IfaceMgr::instance().addExternalSocket(secondpipe[0], my_callback2))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().addExternalSocket(secondpipe[0], my_callback2
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_1323; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1323
; } } else gtest_label_testnothrow_1323 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1323, ("Expected: " "IfaceMgr::instance().addExternalSocket(secondpipe[0], my_callback2)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1324
1325 Pkt6Ptr pkt6;
1326 ASSERT_NO_THROW(pkt6 = IfaceMgr::instance().receive6(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt6 = IfaceMgr::instance().receive6(1); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1326; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1326; } } else gtest_label_testnothrow_1326
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1326, ("Expected: " "pkt6 = IfaceMgr::instance().receive6(1)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1327
1328 // Our callbacks should not be called this time (there was no data)
1329 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1329, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1330 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1330, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1331
1332 // IfaceMgr should not process control socket data as incoming packets
1333 EXPECT_FALSE(pkt6)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1333, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt6", "true", "false") .c_str()) = ::testing::Message()
;
1334
1335 // Now, send some data over the first pipe (38 bytes)
1336 EXPECT_EQ(38, write(pipefd[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(pipefd[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(pipefd[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1336, gtest_ar.failure_message()) = ::testing::Message()
;
1337
1338 // And try again, using the second pipe
1339 EXPECT_EQ(38, write(secondpipe[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(secondpipe[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(secondpipe[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1339, gtest_ar.failure_message()) = ::testing::Message()
;
1340
1341 Pkt6Ptr pkt0(new Pkt6(DHCPV6_SOLICIT, 1234));
1342 pkt0->setIface("eth0");
1343 pkt0->setIndex(0);
1344 Pkt6Ptr pkt1(new Pkt6(DHCPV6_SOLICIT, 2345));
1345 pkt1->setIface("eth1");
1346 pkt1->setIndex(1);
1347 Pkt6Ptr pkt2(new Pkt6(DHCPV6_SOLICIT, 3456));
1348 pkt2->setIface("eth2");
1349 pkt2->setIndex(2);
1350 IfaceMgr::instance().send(pkt0);
1351 IfaceMgr::instance().send(pkt1);
1352 IfaceMgr::instance().send(pkt2);
1353 std::unordered_map<Pkt6Ptr, size_t, hash_pkt6> expected;
1354 expected[pkt0] = 0;
1355 expected[pkt1] = 0;
1356 expected[pkt2] = 0;
1357 bool first = true;
1358 size_t j = 0;
1359 for (size_t i = 0; i < 3 * loop_count && j < 20 * loop_count;) {
1360 Pkt6Ptr new_pkt = IfaceMgr::instance().receive6(1, 0);
1361 if (first) {
1362 first = false;
1363 EXPECT_TRUE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback_ok)) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1363, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"callback_ok", "false", "true") .c_str()) = ::testing::Message
()
;
1364 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1364, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1365 callback_count++;
1366 } else {
1367 first = true;
1368 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1368, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1369 EXPECT_TRUE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback2_ok)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1369, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "false", "true") .c_str()) = ::testing::Message
()
;
1370 callback2_count++;
1371 }
1372 callback_ok = false;
1373 callback2_ok = false;
1374 if (new_pkt) {
1375 expected[new_pkt]++;
1376 if (i % 3 == 0) {
1377 EXPECT_EQ(new_pkt.get(), pkt0.get())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("new_pkt.get()"
, "pkt0.get()", new_pkt.get(), pkt0.get()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1377, gtest_ar
.failure_message()) = ::testing::Message()
;
1378 } else if (i % 3 == 1) {
1379 EXPECT_EQ(new_pkt.get(), pkt1.get())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("new_pkt.get()"
, "pkt1.get()", new_pkt.get(), pkt1.get()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1379, gtest_ar
.failure_message()) = ::testing::Message()
;
1380 } else {
1381 EXPECT_EQ(new_pkt.get(), pkt2.get())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("new_pkt.get()"
, "pkt2.get()", new_pkt.get(), pkt2.get()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1381, gtest_ar
.failure_message()) = ::testing::Message()
;
1382 }
1383 i++;
1384 } else {
1385 j++;
1386 }
1387 }
1388
1389 for (auto i = expected.begin(); i!= expected.end(); ++i) {
1390 EXPECT_EQ(loop_count, i->second)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("loop_count"
, "i->second", loop_count, i->second))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1390, gtest_ar
.failure_message()) = ::testing::Message()
;
1391 }
1392
1393 EXPECT_EQ((3 * loop_count + j) / 2 + j % 2, callback_count)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("(3 * loop_count + j) / 2 + j % 2"
, "callback_count", (3 * loop_count + j) / 2 + j % 2, callback_count
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1393, gtest_ar.failure_message()) = ::testing::Message()
;
1394 EXPECT_EQ((3 * loop_count + j) / 2, callback2_count)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("(3 * loop_count + j) / 2"
, "callback2_count", (3 * loop_count + j) / 2, callback2_count
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1394, gtest_ar.failure_message()) = ::testing::Message()
;
1395
1396 // close both pipe ends
1397 close(pipefd[1]);
1398 close(pipefd[0]);
1399
1400 close(secondpipe[1]);
1401 close(secondpipe[0]);
1402
1403 ASSERT_NO_THROW(IfaceMgr::instance().stopDHCPReceiver())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().stopDHCPReceiver(); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1403; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1403; } } else gtest_label_testnothrow_1403
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1403, ("Expected: " "IfaceMgr::instance().stopDHCPReceiver()"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1404 }
1405
1406 /// @brief Test that iface sockets are rotated when ifaces are under load.
1407 ///
1408 /// @param direct Flag which indicates if direct or indirect receive should
1409 /// be used.
1410 void testReceive4RotateIfaces(bool direct = true) {
1411 const size_t loop_count = 1024;
1412 IfaceMgr::instance().clearIfaces();
1413 IfaceMgr::instance().deleteAllExternalSockets();
1414 PktFilterPtr filter(new PktFilter4IfaceSocketTest(true, false));
1415 IfaceMgr::instance().setPacketFilter(filter);
1416 IfacePtr iface0(new Iface("eth0", 0));
1417 iface0->flag_up_ = true;
1418 iface0->flag_running_ = true;
1419 iface0->addAddress(IOAddress("192.168.0.1"));
1420 IfaceMgr::instance().addInterface(iface0);
1421 IfacePtr iface1(new Iface("eth1", 1));
1422 iface1->flag_up_ = true;
1423 iface1->flag_running_ = true;
1424 iface1->addAddress(IOAddress("192.168.0.2"));
1425 IfaceMgr::instance().addInterface(iface1);
1426 IfacePtr iface2(new Iface("eth2", 2));
1427 iface2->flag_up_ = true;
1428 iface2->flag_running_ = true;
1429 iface2->addAddress(IOAddress("192.168.0.3"));
1430 IfaceMgr::instance().addInterface(iface2);
1431 for (size_t i = 3; i < 250; ++i) {
1432 string name = "eth";
1433 name += std::to_string(i);
1434 IfacePtr iface_n(new Iface(name, i));
1435 iface_n->flag_up_ = true;
1436 iface_n->flag_running_ = true;
1437 iface_n->addAddress(IOAddress(string("192.168.0.") + std::to_string(i)));
1438 IfaceMgr::instance().addInterface(iface_n);
1439 }
1440 if (!direct) {
1441 auto queue_control = makeQueueConfig(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4, 50000, true);
1442 IfaceMgr::instance().configureDHCPPacketQueue(AF_INET2, queue_control);
1443 } else {
1444 IfaceMgr::instance().configureDHCPPacketQueue(AF_INET2, data::ConstElementPtr());
1445 }
1446 IfaceMgr::instance().openSockets4(9999, true, IfaceMgrErrorMsgCallback(), false);
1447 EXPECT_EQ((boost::dynamic_pointer_cast<PktFilter4IfaceSocketTest>(filter))->socket_fds_.size(), 250U)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("(boost::dynamic_pointer_cast<PktFilter4IfaceSocketTest>(filter))->socket_fds_.size()"
, "250U", (boost::dynamic_pointer_cast<PktFilter4IfaceSocketTest
>(filter))->socket_fds_.size(), 250U))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1447, gtest_ar
.failure_message()) = ::testing::Message()
;
1448 Pkt4Ptr pkt0(new Pkt4(DHCPDISCOVER, 1234));
1449 pkt0->setIface("eth0");
1450 pkt0->setIndex(0);
1451 Pkt4Ptr pkt1(new Pkt4(DHCPDISCOVER, 2345));
1452 pkt1->setIface("eth1");
1453 pkt1->setIndex(1);
1454 Pkt4Ptr pkt2(new Pkt4(DHCPDISCOVER, 3456));
1455 pkt2->setIface("eth2");
1456 pkt2->setIndex(2);
1457 IfaceMgr::instance().send(pkt0);
1458 IfaceMgr::instance().send(pkt1);
1459 IfaceMgr::instance().send(pkt2);
1460 std::unordered_map<Pkt4Ptr, size_t, hash_pkt4> expected;
1461 expected[pkt0] = 0;
1462 expected[pkt1] = 0;
1463 expected[pkt2] = 0;
1464 for (size_t i = 0, j = 0; i < 3 * loop_count && j < 2 * loop_count;) {
1465 Pkt4Ptr new_pkt = IfaceMgr::instance().receive4(1, 0);
1466 if (new_pkt) {
1467 expected[new_pkt]++;
1468 if (i % 3 == 0) {
1469 EXPECT_EQ(new_pkt.get(), pkt0.get())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("new_pkt.get()"
, "pkt0.get()", new_pkt.get(), pkt0.get()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1469, gtest_ar
.failure_message()) = ::testing::Message()
;
1470 } else if (i % 3 == 1) {
1471 EXPECT_EQ(new_pkt.get(), pkt1.get())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("new_pkt.get()"
, "pkt1.get()", new_pkt.get(), pkt1.get()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1471, gtest_ar
.failure_message()) = ::testing::Message()
;
1472 } else {
1473 EXPECT_EQ(new_pkt.get(), pkt2.get())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("new_pkt.get()"
, "pkt2.get()", new_pkt.get(), pkt2.get()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1473, gtest_ar
.failure_message()) = ::testing::Message()
;
1474 }
1475 i++;
1476 } else {
1477 j++;
1478 }
1479 }
1480 for (auto i = expected.begin(); i!= expected.end(); ++i) {
1481 EXPECT_EQ(loop_count, i->second)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("loop_count"
, "i->second", loop_count, i->second))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1481, gtest_ar
.failure_message()) = ::testing::Message()
;
1482 }
1483 ASSERT_NO_THROW(IfaceMgr::instance().stopDHCPReceiver())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().stopDHCPReceiver(); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1483; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1483; } } else gtest_label_testnothrow_1483
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1483, ("Expected: " "IfaceMgr::instance().stopDHCPReceiver()"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1484 }
1485
1486 /// @brief Test that iface sockets are rotated when ifaces are under load.
1487 ///
1488 /// @param direct Flag which indicates if direct or indirect receive should
1489 /// be used.
1490 void testReceive6RotateIfaces(bool direct = true) {
1491 const size_t loop_count = 1024;
1492 IfaceMgr::instance().clearIfaces();
1493 IfaceMgr::instance().deleteAllExternalSockets();
1494 PktFilter6Ptr filter(new PktFilter6IfaceSocketTest(true, false));
1495 IfaceMgr::instance().setPacketFilter(filter);
1496 IfacePtr iface0(new Iface("eth0", 0));
1497 iface0->flag_up_ = true;
1498 iface0->flag_running_ = true;
1499 iface0->addAddress(IOAddress("2003:db8::1"));
1500 iface0->addAddress(IOAddress("fe80::3a60:77ff:fed5:abcd"));
1501 IfaceMgr::instance().addInterface(iface0);
1502 IfacePtr iface1(new Iface("eth1", 1));
1503 iface1->flag_up_ = true;
1504 iface1->flag_running_ = true;
1505 iface1->addAddress(IOAddress("2003:db8::2"));
1506 iface1->addAddress(IOAddress("fe80::3a60:77ff:fed5:bcde"));
1507 IfaceMgr::instance().addInterface(iface1);
1508 IfacePtr iface2(new Iface("eth2", 2));
1509 iface2->flag_up_ = true;
1510 iface2->flag_running_ = true;
1511 iface2->addAddress(IOAddress("2003:db8::3"));
1512 iface2->addAddress(IOAddress("fe80::3a60:77ff:fed5:cdef"));
1513 IfaceMgr::instance().addInterface(iface2);
1514 for (size_t i = 3; i < 250; ++i) {
1515 string name = "eth";
1516 name += std::to_string(i);
1517 IfacePtr iface_n(new Iface(name, i));
1518 iface_n->flag_up_ = true;
1519 iface_n->flag_running_ = true;
1520 iface_n->addAddress(IOAddress(string("2003:db8::") + std::to_string(i)));
1521 iface_n->addAddress(IOAddress(string("fe80::3a60:77ff:fed5:") + std::to_string(i)));
1522 IfaceMgr::instance().addInterface(iface_n);
1523 }
1524 if (!direct) {
1525 auto queue_control = makeQueueConfig(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6, 50000, true);
1526 IfaceMgr::instance().configureDHCPPacketQueue(AF_INET610, queue_control);
1527 } else {
1528 IfaceMgr::instance().configureDHCPPacketQueue(AF_INET610, data::ConstElementPtr());
1529 }
1530 IfaceMgr::instance().openSockets6(9999, IfaceMgrErrorMsgCallback(), false);
1531 EXPECT_EQ((boost::dynamic_pointer_cast<PktFilter6IfaceSocketTest>(filter))->socket_fds_.size(), 250U)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("(boost::dynamic_pointer_cast<PktFilter6IfaceSocketTest>(filter))->socket_fds_.size()"
, "250U", (boost::dynamic_pointer_cast<PktFilter6IfaceSocketTest
>(filter))->socket_fds_.size(), 250U))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1531, gtest_ar
.failure_message()) = ::testing::Message()
;
1532 Pkt6Ptr pkt0(new Pkt6(DHCPV6_SOLICIT, 1234));
1533 pkt0->setIface("eth0");
1534 pkt0->setIndex(0);
1535 Pkt6Ptr pkt1(new Pkt6(DHCPV6_SOLICIT, 2345));
1536 pkt1->setIface("eth1");
1537 pkt1->setIndex(1);
1538 Pkt6Ptr pkt2(new Pkt6(DHCPV6_SOLICIT, 3456));
1539 pkt2->setIface("eth2");
1540 pkt2->setIndex(2);
1541 IfaceMgr::instance().send(pkt0);
1542 IfaceMgr::instance().send(pkt1);
1543 IfaceMgr::instance().send(pkt2);
1544 std::unordered_map<Pkt6Ptr, size_t, hash_pkt6> expected;
1545 expected[pkt0] = 0;
1546 expected[pkt1] = 0;
1547 expected[pkt2] = 0;
1548 for (size_t i = 0, j = 0; i < 3 * loop_count && j < 2 * loop_count;) {
1549 Pkt6Ptr new_pkt = IfaceMgr::instance().receive6(1, 0);
1550 if (new_pkt) {
1551 expected[new_pkt]++;
1552 if (i % 3 == 0) {
1553 EXPECT_EQ(new_pkt.get(), pkt0.get())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("new_pkt.get()"
, "pkt0.get()", new_pkt.get(), pkt0.get()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1553, gtest_ar
.failure_message()) = ::testing::Message()
;
1554 } else if (i % 3 == 1) {
1555 EXPECT_EQ(new_pkt.get(), pkt1.get())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("new_pkt.get()"
, "pkt1.get()", new_pkt.get(), pkt1.get()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1555, gtest_ar
.failure_message()) = ::testing::Message()
;
1556 } else {
1557 EXPECT_EQ(new_pkt.get(), pkt2.get())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("new_pkt.get()"
, "pkt2.get()", new_pkt.get(), pkt2.get()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1557, gtest_ar
.failure_message()) = ::testing::Message()
;
1558 }
1559 i++;
1560 } else {
1561 j++;
1562 }
1563 }
1564 for (auto i = expected.begin(); i!= expected.end(); ++i) {
1565 EXPECT_EQ(loop_count, i->second)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("loop_count"
, "i->second", loop_count, i->second))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1565, gtest_ar
.failure_message()) = ::testing::Message()
;
1566 }
1567 ASSERT_NO_THROW(IfaceMgr::instance().stopDHCPReceiver())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().stopDHCPReceiver(); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1567; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1567; } } else gtest_label_testnothrow_1567
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1567, ("Expected: " "IfaceMgr::instance().stopDHCPReceiver()"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1568 }
1569
1570 /// @brief Test that external sockets are rotated when external sockets are under load.
1571 ///
1572 /// @param direct Flag which indicates if direct or indirect receive should
1573 /// be used.
1574 void testExternalSockets4Rotation(bool direct = true) {
1575 IfaceMgr::instance().deleteAllExternalSockets();
1576 callback_ok = false;
1577 callback2_ok = false;
1578 size_t callback_count = 0;
1579 size_t callback2_count = 0;
1580
1581 const size_t loop_count = 1024;
1582
1583 if (!direct) {
1584 auto queue_control = makeQueueConfig(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4, 50000, true);
1585 IfaceMgr::instance().configureDHCPPacketQueue(AF_INET2, queue_control);
1586 } else {
1587 IfaceMgr::instance().configureDHCPPacketQueue(AF_INET2, data::ConstElementPtr());
1588 }
1589 IfaceMgr::instance().startDHCPReceiver(AF_INET2);
1590
1591 // Create first pipe and register it as extra socket
1592 int pipefd[2];
1593 EXPECT_TRUE(pipe(pipefd) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(pipefd) == 0)) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1593, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(pipefd) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
1594 EXPECT_NO_THROW(IfaceMgr::instance().addExternalSocket(pipefd[0], my_callback))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().addExternalSocket(pipefd[0], my_callback
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_1594; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1594
; } } else gtest_label_testnothrow_1594 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1594, ("Expected: " "IfaceMgr::instance().addExternalSocket(pipefd[0], my_callback)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1595
1596 // Let's create a second pipe and register it as well
1597 int secondpipe[2];
1598 EXPECT_TRUE(pipe(secondpipe) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(secondpipe) == 0
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1598, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(secondpipe) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
1599 EXPECT_NO_THROW(IfaceMgr::instance().addExternalSocket(secondpipe[0], my_callback2))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().addExternalSocket(secondpipe[0], my_callback2
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_1599; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1599
; } } else gtest_label_testnothrow_1599 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1599, ("Expected: " "IfaceMgr::instance().addExternalSocket(secondpipe[0], my_callback2)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1600
1601 Pkt4Ptr pkt4;
1602 ASSERT_NO_THROW(pkt4 = IfaceMgr::instance().receive4(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt4 = IfaceMgr::instance().receive4(1); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1602; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1602; } } else gtest_label_testnothrow_1602
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1602, ("Expected: " "pkt4 = IfaceMgr::instance().receive4(1)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1603
1604 // Our callbacks should not be called this time (there was no data)
1605 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1605, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1606 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1606, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1607
1608 // IfaceMgr should not process control socket data as incoming packets
1609 EXPECT_FALSE(pkt4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1609, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt4", "true", "false") .c_str()) = ::testing::Message()
;
1610
1611 // Now, send some data over the first pipe (38 bytes)
1612 EXPECT_EQ(38, write(pipefd[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(pipefd[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(pipefd[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1612, gtest_ar.failure_message()) = ::testing::Message()
;
1613
1614 // And try again, using the second pipe
1615 EXPECT_EQ(38, write(secondpipe[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(secondpipe[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(secondpipe[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1615, gtest_ar.failure_message()) = ::testing::Message()
;
1616
1617 for (size_t i = 0; i < loop_count; ++i) {
1618 // Clear the status...
1619 callback_ok = false;
1620 callback2_ok = false;
1621
1622 // ... and repeat
1623 ASSERT_NO_THROW(pkt4 = IfaceMgr::instance().receive4(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt4 = IfaceMgr::instance().receive4(1); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1623; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1623; } } else gtest_label_testnothrow_1623
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1623, ("Expected: " "pkt4 = IfaceMgr::instance().receive4(1)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1624
1625 // IfaceMgr should not process control socket data as incoming packets
1626 EXPECT_FALSE(pkt4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1626, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt4", "true", "false") .c_str()) = ::testing::Message()
;
1627
1628 // There was some data, so this time callback should be called
1629 EXPECT_TRUE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback_ok)) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1629, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"callback_ok", "false", "true") .c_str()) = ::testing::Message
()
;
1630 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1630, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1631 callback_count++;
1632 EXPECT_EQ(i + 1, callback_count)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("i + 1", "callback_count"
, i + 1, callback_count))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1632, gtest_ar.failure_message()) = ::testing::Message()
;
1633
1634 // Clear the status...
1635 callback_ok = false;
1636 callback2_ok = false;
1637
1638 // ... and repeat
1639 ASSERT_NO_THROW(pkt4 = IfaceMgr::instance().receive4(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt4 = IfaceMgr::instance().receive4(1); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1639; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1639; } } else gtest_label_testnothrow_1639
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1639, ("Expected: " "pkt4 = IfaceMgr::instance().receive4(1)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1640
1641 // IfaceMgr should not process control socket data as incoming packets
1642 EXPECT_FALSE(pkt4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1642, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt4", "true", "false") .c_str()) = ::testing::Message()
;
1643
1644 // There was some data, so this time second callback should be called
1645 // Without socket rotation this would call the first callback as the first
1646 // pipe data has not been read.
1647 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1647, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1648 EXPECT_TRUE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback2_ok)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1648, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "false", "true") .c_str()) = ::testing::Message
()
;
1649 callback2_count++;
1650 EXPECT_EQ(i + 1, callback2_count)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("i + 1", "callback2_count"
, i + 1, callback2_count))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1650, gtest_ar.failure_message()) = ::testing::Message()
;
1651 }
1652
1653 EXPECT_EQ(loop_count, callback_count)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("loop_count"
, "callback_count", loop_count, callback_count))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1653, gtest_ar
.failure_message()) = ::testing::Message()
;
1654 EXPECT_EQ(loop_count, callback2_count)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("loop_count"
, "callback2_count", loop_count, callback2_count))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1654, gtest_ar
.failure_message()) = ::testing::Message()
;
1655
1656 // close both pipe ends
1657 close(pipefd[1]);
1658 close(pipefd[0]);
1659
1660 close(secondpipe[1]);
1661 close(secondpipe[0]);
1662
1663 ASSERT_NO_THROW(IfaceMgr::instance().stopDHCPReceiver())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().stopDHCPReceiver(); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1663; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1663; } } else gtest_label_testnothrow_1663
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1663, ("Expected: " "IfaceMgr::instance().stopDHCPReceiver()"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1664 }
1665
1666 /// @brief Test that external sockets are rotated when external sockets are under load.
1667 ///
1668 /// @param direct Flag which indicates if direct or indirect receive should
1669 /// be used.
1670 void testExternalSockets6Rotation(bool direct = true) {
1671 IfaceMgr::instance().deleteAllExternalSockets();
1672 callback_ok = false;
1673 callback2_ok = false;
1674 size_t callback_count = 0;
1675 size_t callback2_count = 0;
1676
1677 const size_t loop_count = 1024;
1678
1679 if (!direct) {
1680 auto queue_control = makeQueueConfig(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6, 50000, true);
1681 IfaceMgr::instance().configureDHCPPacketQueue(AF_INET610, queue_control);
1682 } else {
1683 IfaceMgr::instance().configureDHCPPacketQueue(AF_INET610, data::ConstElementPtr());
1684 }
1685 IfaceMgr::instance().startDHCPReceiver(AF_INET610);
1686
1687 // Create first pipe and register it as extra socket
1688 int pipefd[2];
1689 EXPECT_TRUE(pipe(pipefd) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(pipefd) == 0)) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1689, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(pipefd) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
1690 EXPECT_NO_THROW(IfaceMgr::instance().addExternalSocket(pipefd[0], my_callback))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().addExternalSocket(pipefd[0], my_callback
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_1690; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1690
; } } else gtest_label_testnothrow_1690 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1690, ("Expected: " "IfaceMgr::instance().addExternalSocket(pipefd[0], my_callback)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1691
1692 // Let's create a second pipe and register it as well
1693 int secondpipe[2];
1694 EXPECT_TRUE(pipe(secondpipe) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(secondpipe) == 0
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1694, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(secondpipe) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
1695 EXPECT_NO_THROW(IfaceMgr::instance().addExternalSocket(secondpipe[0], my_callback2))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().addExternalSocket(secondpipe[0], my_callback2
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_1695; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1695
; } } else gtest_label_testnothrow_1695 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1695, ("Expected: " "IfaceMgr::instance().addExternalSocket(secondpipe[0], my_callback2)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1696
1697 Pkt6Ptr pkt6;
1698 ASSERT_NO_THROW(pkt6 = IfaceMgr::instance().receive6(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt6 = IfaceMgr::instance().receive6(1); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1698; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1698; } } else gtest_label_testnothrow_1698
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1698, ("Expected: " "pkt6 = IfaceMgr::instance().receive6(1)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1699
1700 // Our callbacks should not be called this time (there was no data)
1701 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1701, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1702 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1702, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1703
1704 // IfaceMgr should not process control socket data as incoming packets
1705 EXPECT_FALSE(pkt6)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1705, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt6", "true", "false") .c_str()) = ::testing::Message()
;
1706
1707 // Now, send some data over the first pipe (38 bytes)
1708 EXPECT_EQ(38, write(pipefd[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(pipefd[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(pipefd[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1708, gtest_ar.failure_message()) = ::testing::Message()
;
1709
1710 // And try again, using the second pipe
1711 EXPECT_EQ(38, write(secondpipe[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(secondpipe[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(secondpipe[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1711, gtest_ar.failure_message()) = ::testing::Message()
;
1712
1713 for (size_t i = 0; i < loop_count; ++i) {
1714 // Clear the status...
1715 callback_ok = false;
1716 callback2_ok = false;
1717
1718 // ... and repeat
1719 ASSERT_NO_THROW(pkt6 = IfaceMgr::instance().receive6(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt6 = IfaceMgr::instance().receive6(1); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1719; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1719; } } else gtest_label_testnothrow_1719
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1719, ("Expected: " "pkt6 = IfaceMgr::instance().receive6(1)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1720
1721 // IfaceMgr should not process control socket data as incoming packets
1722 EXPECT_FALSE(pkt6)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1722, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt6", "true", "false") .c_str()) = ::testing::Message()
;
1723
1724 // There was some data, so this time callback should be called
1725 EXPECT_TRUE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback_ok)) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1725, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"callback_ok", "false", "true") .c_str()) = ::testing::Message
()
;
1726 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1726, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1727 callback_count++;
1728 EXPECT_EQ(i + 1, callback_count)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("i + 1", "callback_count"
, i + 1, callback_count))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1728, gtest_ar.failure_message()) = ::testing::Message()
;
1729
1730 // Clear the status...
1731 callback_ok = false;
1732 callback2_ok = false;
1733
1734 // ... and repeat
1735 ASSERT_NO_THROW(pkt6 = IfaceMgr::instance().receive6(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt6 = IfaceMgr::instance().receive6(1); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1735; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1735; } } else gtest_label_testnothrow_1735
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1735, ("Expected: " "pkt6 = IfaceMgr::instance().receive6(1)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1736
1737 // IfaceMgr should not process control socket data as incoming packets
1738 EXPECT_FALSE(pkt6)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1738, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt6", "true", "false") .c_str()) = ::testing::Message()
;
1739
1740 // There was some data, so this time second callback should be called
1741 // Without socket rotation this would call the first callback as the first
1742 // pipe data has not been read.
1743 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1743, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
1744 EXPECT_TRUE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback2_ok)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1744, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "false", "true") .c_str()) = ::testing::Message
()
;
1745 callback2_count++;
1746 EXPECT_EQ(i + 1, callback2_count)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("i + 1", "callback2_count"
, i + 1, callback2_count))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1746, gtest_ar.failure_message()) = ::testing::Message()
;
1747 }
1748
1749 EXPECT_EQ(loop_count, callback_count)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("loop_count"
, "callback_count", loop_count, callback_count))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1749, gtest_ar
.failure_message()) = ::testing::Message()
;
1750 EXPECT_EQ(loop_count, callback2_count)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("loop_count"
, "callback2_count", loop_count, callback2_count))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1750, gtest_ar
.failure_message()) = ::testing::Message()
;
1751
1752 // close both pipe ends
1753 close(pipefd[1]);
1754 close(pipefd[0]);
1755
1756 close(secondpipe[1]);
1757 close(secondpipe[0]);
1758
1759 ASSERT_NO_THROW(IfaceMgr::instance().stopDHCPReceiver())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().stopDHCPReceiver(); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1759; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1759; } } else gtest_label_testnothrow_1759
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1759, ("Expected: " "IfaceMgr::instance().stopDHCPReceiver()"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1760 }
1761
1762 /// @brief Holds the invocation counter for ifaceMgrErrorHandler.
1763 int errors_count_;
1764
1765 /// @brief RAII wrapper for KEA_EVENT_HANDLER_TYPE env variable.
1766 EnvVarWrapper kea_event_handler_type_;
1767};
1768
1769// We need some known interface to work reliably. Loopback interface is named
1770// lo on Linux and lo0 on BSD boxes. We need to find out which is available.
1771// This is not a real test, but rather a workaround that will go away when
1772// interface detection is implemented on all OSes.
1773TEST_F(IfaceMgrTest, loDetect)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("loDetect") > 1, "test_name must not be empty"
); class IfaceMgrTest_loDetect_Test : public IfaceMgrTest { public
: IfaceMgrTest_loDetect_Test() = default; ~IfaceMgrTest_loDetect_Test
() override = default; IfaceMgrTest_loDetect_Test (const IfaceMgrTest_loDetect_Test
&) = delete; IfaceMgrTest_loDetect_Test & operator=(
const IfaceMgrTest_loDetect_Test &) = delete; IfaceMgrTest_loDetect_Test
(IfaceMgrTest_loDetect_Test &&) noexcept = delete; IfaceMgrTest_loDetect_Test
& operator=( IfaceMgrTest_loDetect_Test &&) noexcept
= delete; private: void TestBody() override; [[maybe_unused]
] static ::testing::TestInfo* const test_info_; }; ::testing::
TestInfo* const IfaceMgrTest_loDetect_Test::test_info_ = ::testing
::internal::MakeAndRegisterTestInfo( "IfaceMgrTest", "loDetect"
, nullptr, nullptr, ::testing::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1773), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1773), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1773), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_loDetect_Test
>); void IfaceMgrTest_loDetect_Test::TestBody()
{
1774 NakedIfaceMgr::loDetect();
1775}
1776
1777// Uncomment this test to create packet writer. It will
1778// write incoming DHCPv6 packets as C arrays. That is useful
1779// for generating test sequences based on actual traffic
1780//
1781// TODO: this potentially should be moved to a separate tool
1782//
1783
1784#if 0
1785TEST_F(IfaceMgrTest, dhcp6Sniffer)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("dhcp6Sniffer") > 1, "test_name must not be empty"
); class IfaceMgrTest_dhcp6Sniffer_Test : public IfaceMgrTest
{ public: IfaceMgrTest_dhcp6Sniffer_Test() = default; ~IfaceMgrTest_dhcp6Sniffer_Test
() override = default; IfaceMgrTest_dhcp6Sniffer_Test (const IfaceMgrTest_dhcp6Sniffer_Test
&) = delete; IfaceMgrTest_dhcp6Sniffer_Test & operator
=( const IfaceMgrTest_dhcp6Sniffer_Test &) = delete; IfaceMgrTest_dhcp6Sniffer_Test
(IfaceMgrTest_dhcp6Sniffer_Test &&) noexcept = delete
; IfaceMgrTest_dhcp6Sniffer_Test & operator=( IfaceMgrTest_dhcp6Sniffer_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_dhcp6Sniffer_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "dhcp6Sniffer", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1785), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1785), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1785), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_dhcp6Sniffer_Test
>); void IfaceMgrTest_dhcp6Sniffer_Test::TestBody()
{
1786 // Testing socket operation in a portable way is tricky
1787 // without interface detection implemented
1788
1789 static_cast<void>(remove("interfaces.txt"));
1790
1791 ofstream interfaces("interfaces.txt", ios::ate);
1792 interfaces << "eth0 fe80::21e:8cff:fe9b:7349";
1793 interfaces.close();
1794
1795 boost::scoped_ptr<NakedIfaceMgr> ifacemgr = new NakedIfaceMgr();
1796
1797 Pkt6Ptr pkt;
1798 int cnt = 0;
1799 cout << "---8X-----------------------------------------" << endl;
1800 while (true) {
1801 pkt.reset(ifacemgr->receive());
1802
1803 cout << "// this code is autogenerated. Do NOT edit." << endl;
1804 cout << "// Received " << pkt->data_len_ << " bytes packet:" << endl;
1805 cout << "Pkt6 *capture" << cnt++ << "() {" << endl;
1806 cout << " Pkt6* pkt;" << endl;
1807 cout << " pkt = new Pkt6(" << pkt->data_len_ << ");" << endl;
1808 cout << " pkt->remote_port_ = " << pkt-> remote_port_ << ";" << endl;
1809 cout << " pkt->remote_addr_ = IOAddress(\""
1810 << pkt->remote_addr_ << "\");" << endl;
1811 cout << " pkt->local_port_ = " << pkt-> local_port_ << ";" << endl;
1812 cout << " pkt->local_addr_ = IOAddress(\""
1813 << pkt->local_addr_ << "\");" << endl;
1814 cout << " pkt->ifindex_ = " << pkt->ifindex_ << ";" << endl;
1815 cout << " pkt->iface_ = \"" << pkt->iface_ << "\";" << endl;
1816
1817 // TODO it is better to declare statically initialize the array
1818 // and then memcpy it to packet.
1819 for (int i=0; i< pkt->data_len_; i++) {
1820 cout << " pkt->data_[" << i << "]="
1821 << (int)(unsigned char)pkt->data_[i] << "; ";
1822 if (!(i%4))
1823 cout << endl;
1824 }
1825 cout << endl;
1826 cout << " return (pkt);" << endl;
1827 cout << "}" << endl << endl;
1828
1829 pkt.reset();
1830 }
1831 cout << "---8X-----------------------------------------" << endl;
1832
1833 // Never happens. Infinite loop is infinite
1834}
1835#endif
1836
1837// This test verifies that creation of the IfaceMgr instance doesn't
1838// cause an exception.
1839TEST_F(IfaceMgrTest, instance)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("instance") > 1, "test_name must not be empty"
); class IfaceMgrTest_instance_Test : public IfaceMgrTest { public
: IfaceMgrTest_instance_Test() = default; ~IfaceMgrTest_instance_Test
() override = default; IfaceMgrTest_instance_Test (const IfaceMgrTest_instance_Test
&) = delete; IfaceMgrTest_instance_Test & operator=(
const IfaceMgrTest_instance_Test &) = delete; IfaceMgrTest_instance_Test
(IfaceMgrTest_instance_Test &&) noexcept = delete; IfaceMgrTest_instance_Test
& operator=( IfaceMgrTest_instance_Test &&) noexcept
= delete; private: void TestBody() override; [[maybe_unused]
] static ::testing::TestInfo* const test_info_; }; ::testing::
TestInfo* const IfaceMgrTest_instance_Test::test_info_ = ::testing
::internal::MakeAndRegisterTestInfo( "IfaceMgrTest", "instance"
, nullptr, nullptr, ::testing::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1839), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1839), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1839), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_instance_Test
>); void IfaceMgrTest_instance_Test::TestBody()
{
1840 EXPECT_NO_THROW(IfaceMgr::instance())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance(); } else static_assert(true, ""); } catch
(std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1840
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1840
; } } else gtest_label_testnothrow_1840 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1840, ("Expected: " "IfaceMgr::instance()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
1841}
1842
1843// Basic tests for Iface inner class.
1844TEST_F(IfaceMgrTest, ifaceClass)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("ifaceClass") > 1, "test_name must not be empty"
); class IfaceMgrTest_ifaceClass_Test : public IfaceMgrTest {
public: IfaceMgrTest_ifaceClass_Test() = default; ~IfaceMgrTest_ifaceClass_Test
() override = default; IfaceMgrTest_ifaceClass_Test (const IfaceMgrTest_ifaceClass_Test
&) = delete; IfaceMgrTest_ifaceClass_Test & operator
=( const IfaceMgrTest_ifaceClass_Test &) = delete; IfaceMgrTest_ifaceClass_Test
(IfaceMgrTest_ifaceClass_Test &&) noexcept = delete;
IfaceMgrTest_ifaceClass_Test & operator=( IfaceMgrTest_ifaceClass_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_ifaceClass_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "ifaceClass", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1844), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1844), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1844), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_ifaceClass_Test
>); void IfaceMgrTest_ifaceClass_Test::TestBody()
{
1845
1846 IfacePtr iface(new Iface("eth5", 7));
1847 EXPECT_STREQ("eth5/7", iface->getFullName().c_str())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperSTREQ("\"eth5/7\""
, "iface->getFullName().c_str()", "eth5/7", iface->getFullName
().c_str()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1847, gtest_ar.failure_message()) = ::testing::Message()
;
1848
1849 EXPECT_THROW_MSG(iface.reset(new Iface("", 10)), BadValue,{ try { iface.reset(new Iface("", 10)); ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1850, "Failed") = ::testing::Message() << "no exception, expected: "
<< "BadValue"; } catch (const BadValue& ex) { switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar
= (::testing::internal::EqHelper::Compare("std::string(ex.what())"
, "\"Interface name must not be empty\"", std::string(ex.what
()), "Interface name must not be empty"))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1850, gtest_ar
.failure_message()) = ::testing::Message(); } catch (...) { ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1850, "Failed"
) = ::testing::Message() << "wrong exception type thrown, expected: "
<< "BadValue"; } }
1850 "Interface name must not be empty"){ try { iface.reset(new Iface("", 10)); ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1850, "Failed") = ::testing::Message() << "no exception, expected: "
<< "BadValue"; } catch (const BadValue& ex) { switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar
= (::testing::internal::EqHelper::Compare("std::string(ex.what())"
, "\"Interface name must not be empty\"", std::string(ex.what
()), "Interface name must not be empty"))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1850, gtest_ar
.failure_message()) = ::testing::Message(); } catch (...) { ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1850, "Failed"
) = ::testing::Message() << "wrong exception type thrown, expected: "
<< "BadValue"; } }
;
1851
1852 EXPECT_NO_THROW(iface.reset(new Iface("big-index", 66666)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface.reset(new Iface("big-index", 66666)); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_1852; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_1852; } } else gtest_label_testnothrow_1852
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1852, ("Expected: " "iface.reset(new Iface(\"big-index\", 66666))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
1853 EXPECT_EQ(66666U, iface->getIndex())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("66666U",
"iface->getIndex()", 66666U, iface->getIndex()))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1853, gtest_ar.failure_message()) = ::testing::Message()
;
1854}
1855
1856// This test checks the getIface by index method.
1857TEST_F(IfaceMgrTest, getIfaceByIndex)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("getIfaceByIndex") > 1, "test_name must not be empty"
); class IfaceMgrTest_getIfaceByIndex_Test : public IfaceMgrTest
{ public: IfaceMgrTest_getIfaceByIndex_Test() = default; ~IfaceMgrTest_getIfaceByIndex_Test
() override = default; IfaceMgrTest_getIfaceByIndex_Test (const
IfaceMgrTest_getIfaceByIndex_Test &) = delete; IfaceMgrTest_getIfaceByIndex_Test
& operator=( const IfaceMgrTest_getIfaceByIndex_Test &
) = delete; IfaceMgrTest_getIfaceByIndex_Test (IfaceMgrTest_getIfaceByIndex_Test
&&) noexcept = delete; IfaceMgrTest_getIfaceByIndex_Test
& operator=( IfaceMgrTest_getIfaceByIndex_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_getIfaceByIndex_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "getIfaceByIndex", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1857), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1857), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1857), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_getIfaceByIndex_Test
>); void IfaceMgrTest_getIfaceByIndex_Test::TestBody()
{
1858 NakedIfaceMgr ifacemgr;
1859
1860 // Create a set of fake interfaces. At the same time, remove the actual
1861 // interfaces that have been detected by the IfaceMgr.
1862 ifacemgr.createIfaces();
1863
1864 // Getting an unset index should throw.
1865 EXPECT_THROW_MSG(ifacemgr.getIface(UNSET_IFINDEX), BadValue, "interface index was not set"){ try { ifacemgr.getIface(UNSET_IFINDEX); ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1865, "Failed") = ::testing::Message() << "no exception, expected: "
<< "BadValue"; } catch (const BadValue& ex) { switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar
= (::testing::internal::EqHelper::Compare("std::string(ex.what())"
, "\"interface index was not set\"", std::string(ex.what()), "interface index was not set"
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1865, gtest_ar.failure_message()) = ::testing::Message(); }
catch (...) { ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1865, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: "
<< "BadValue"; } }
;
1866
1867 // Historically -1 was used as an unset value. Let's also check that it throws in case we didn't
1868 // migrate all code to UNSET_IFINDEX and in case the values diverge.
1869 EXPECT_THROW_MSG(ifacemgr.getIface(-1), BadValue, "interface index was not set"){ try { ifacemgr.getIface(-1); ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1869, "Failed") = ::testing::Message() << "no exception, expected: "
<< "BadValue"; } catch (const BadValue& ex) { switch
(0) case 0: default: if (const ::testing::AssertionResult gtest_ar
= (::testing::internal::EqHelper::Compare("std::string(ex.what())"
, "\"interface index was not set\"", std::string(ex.what()), "interface index was not set"
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1869, gtest_ar.failure_message()) = ::testing::Message(); }
catch (...) { ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1869, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: "
<< "BadValue"; } }
;
1870
1871 // Get the first interface defined.
1872 IfacePtr iface(ifacemgr.getIface(0));
1873 ASSERT_TRUE(iface)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1873, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface", "false", "true") .c_str()) = ::testing::Message()
;
1874 EXPECT_EQ("lo", iface->getName())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"lo\"",
"iface->getName()", "lo", iface->getName()))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1874, gtest_ar
.failure_message()) = ::testing::Message()
;
1875
1876 // Attempt to get an undefined interface.
1877 iface = ifacemgr.getIface(3);
1878 EXPECT_FALSE(iface)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(iface))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1878, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"iface", "true", "false") .c_str()) = ::testing::Message()
;
1879
1880 // Check that we can go past INT_MAX.
1881 unsigned int int_max(numeric_limits<int>::max());
1882 iface = ifacemgr.getIface(int_max);
1883 EXPECT_FALSE(iface)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(iface))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1883, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"iface", "true", "false") .c_str()) = ::testing::Message()
;
1884 iface = ifacemgr.createIface("wlan0", int_max);
1885 ifacemgr.addInterface(iface);
1886 iface = ifacemgr.getIface(int_max);
1887 EXPECT_TRUE(iface)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1887, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"iface", "false", "true") .c_str()) = ::testing::Message()
;
1888 iface = ifacemgr.getIface(int_max + 1);
1889 EXPECT_FALSE(iface)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(iface))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1889, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"iface", "true", "false") .c_str()) = ::testing::Message()
;
1890 iface = ifacemgr.createIface("wlan1", int_max + 1);
1891 ifacemgr.addInterface(iface);
1892 iface = ifacemgr.getIface(int_max + 1);
1893 EXPECT_TRUE(iface)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1893, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"iface", "false", "true") .c_str()) = ::testing::Message()
;
1894}
1895
1896// This test checks the getIface by index method.
1897TEST_F(IfaceMgrTest, interfacesToElement)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("interfacesToElement") > 1, "test_name must not be empty"
); class IfaceMgrTest_interfacesToElement_Test : public IfaceMgrTest
{ public: IfaceMgrTest_interfacesToElement_Test() = default;
~IfaceMgrTest_interfacesToElement_Test() override = default;
IfaceMgrTest_interfacesToElement_Test (const IfaceMgrTest_interfacesToElement_Test
&) = delete; IfaceMgrTest_interfacesToElement_Test &
operator=( const IfaceMgrTest_interfacesToElement_Test &
) = delete; IfaceMgrTest_interfacesToElement_Test (IfaceMgrTest_interfacesToElement_Test
&&) noexcept = delete; IfaceMgrTest_interfacesToElement_Test
& operator=( IfaceMgrTest_interfacesToElement_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_interfacesToElement_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "interfacesToElement", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1897), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1897), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1897), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_interfacesToElement_Test
>); void IfaceMgrTest_interfacesToElement_Test::TestBody()
{
1898 NakedIfaceMgr ifacemgr;
1899
1900 // Create a set of fake interfaces. At the same time, remove the actual
1901 // interfaces that have been detected by the IfaceMgr.
1902 ifacemgr.createIfaces();
1903
1904 auto ifaces = ifacemgr.ifacesToElement();
1905 std::string expected = "[ { "
1906 "\"addresses\": [ \"127.0.0.1\", \"::1\" ], "
1907 "\"flag-broadcast\": false, "
1908 "\"flag-loopback\": true, "
1909 "\"flag-multicast\": true, "
1910 "\"flag-running\": true, "
1911 "\"flag-up\": true, "
1912 "\"in-use\": false, "
1913 "\"index\": 0, "
1914 "\"mac\": \"\", "
1915 "\"name\": \"lo\", "
1916 "\"type\": 0 "
1917 "}, { "
1918 "\"addresses\": [ \"10.0.0.1\", \"fe80::3a60:77ff:fed5:cdef\", \"2001:db8:1::1\" ], "
1919 "\"flag-broadcast\": false, "
1920 "\"flag-loopback\": false, "
1921 "\"flag-multicast\": true, "
1922 "\"flag-running\": true, "
1923 "\"flag-up\": true, "
1924 "\"in-use\": true, "
1925 "\"index\": 1, "
1926 "\"mac\": \"\", "
1927 "\"name\": \"eth0\", "
1928 "\"type\": 0 "
1929 "}, { "
1930 "\"addresses\": [ \"192.0.2.3\", \"fe80::3a60:77ff:fed5:abcd\" ], "
1931 "\"flag-broadcast\": false, "
1932 "\"flag-loopback\": false, "
1933 "\"flag-multicast\": true, "
1934 "\"flag-running\": true, "
1935 "\"flag-up\": true, "
1936 "\"in-use\": true, "
1937 "\"index\": 2, "
1938 "\"mac\": \"\", "
1939 "\"name\": \"eth1\", "
1940 "\"type\": 0 "
1941 "} ]";
1942 EXPECT_EQ(ifaces->str(), expected)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ifaces->str()"
, "expected", ifaces->str(), expected))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1942, gtest_ar
.failure_message()) = ::testing::Message()
;
1943}
1944
1945// This test checks the getIface by packet method.
1946TEST_F(IfaceMgrTest, getIfaceByPkt)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("getIfaceByPkt") > 1, "test_name must not be empty"
); class IfaceMgrTest_getIfaceByPkt_Test : public IfaceMgrTest
{ public: IfaceMgrTest_getIfaceByPkt_Test() = default; ~IfaceMgrTest_getIfaceByPkt_Test
() override = default; IfaceMgrTest_getIfaceByPkt_Test (const
IfaceMgrTest_getIfaceByPkt_Test &) = delete; IfaceMgrTest_getIfaceByPkt_Test
& operator=( const IfaceMgrTest_getIfaceByPkt_Test &
) = delete; IfaceMgrTest_getIfaceByPkt_Test (IfaceMgrTest_getIfaceByPkt_Test
&&) noexcept = delete; IfaceMgrTest_getIfaceByPkt_Test
& operator=( IfaceMgrTest_getIfaceByPkt_Test &&)
noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_getIfaceByPkt_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "getIfaceByPkt", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1946), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1946), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1946), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_getIfaceByPkt_Test
>); void IfaceMgrTest_getIfaceByPkt_Test::TestBody()
{
1947 NakedIfaceMgr ifacemgr;
1948 // Create a set of fake interfaces. At the same time, remove the actual
1949 // interfaces that have been detected by the IfaceMgr.
1950 ifacemgr.createIfaces();
1951
1952 // Try IPv4 packet by name.
1953 Pkt4Ptr pkt4(new Pkt4(DHCPDISCOVER, 1234));
1954 IfacePtr iface = ifacemgr.getIface(pkt4);
1955 EXPECT_FALSE(iface)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(iface))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1955, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"iface", "true", "false") .c_str()) = ::testing::Message()
;
1956 pkt4->setIface("eth0");
1957 iface = ifacemgr.getIface(pkt4);
1958 EXPECT_TRUE(iface)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1958, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"iface", "false", "true") .c_str()) = ::testing::Message()
;
1959 EXPECT_FALSE(pkt4->indexSet())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4->indexSet()
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1959, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pkt4->indexSet()", "true", "false") .c_str()) = ::testing
::Message()
;
1960
1961 // Try IPv6 packet by index.
1962 Pkt6Ptr pkt6(new Pkt6(DHCPV6_REPLY, 123456));
1963 iface = ifacemgr.getIface(pkt6);
1964 EXPECT_FALSE(iface)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(iface))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1964, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"iface", "true", "false") .c_str()) = ::testing::Message()
;
1965 ASSERT_TRUE(ifacemgr.getIface("eth0"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface("eth0"
))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1965, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(\"eth0\")", "false", "true") .c_str()) =
::testing::Message()
;
1966 pkt6->setIndex(ifacemgr.getIface("eth0")->getIndex() + 1);
1967 iface = ifacemgr.getIface(pkt6);
1968 ASSERT_TRUE(iface)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1968, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface", "false", "true") .c_str()) = ::testing::Message()
;
1969 EXPECT_TRUE(pkt6->indexSet())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pkt6->indexSet()))
; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1969, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pkt6->indexSet()", "false", "true") .c_str()) = ::testing
::Message()
;
1970
1971 // Index has precedence when both name and index are available.
1972 EXPECT_EQ("eth1", iface->getName())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"eth1\""
, "iface->getName()", "eth1", iface->getName()))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1972, gtest_ar.failure_message()) = ::testing::Message()
;
1973 pkt6->setIface("eth0");
1974 iface = ifacemgr.getIface(pkt6);
1975 ASSERT_TRUE(iface)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1975, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface", "false", "true") .c_str()) = ::testing::Message()
;
1976 EXPECT_EQ("eth1", iface->getName())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"eth1\""
, "iface->getName()", "eth1", iface->getName()))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1976, gtest_ar.failure_message()) = ::testing::Message()
;
1977
1978 // Not existing name fails.
1979 pkt4->setIface("eth2");
1980 iface = ifacemgr.getIface(pkt4);
1981 EXPECT_FALSE(iface)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(iface))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 1981, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"iface", "true", "false") .c_str()) = ::testing::Message()
;
1982
1983 // Not existing index fails.
1984 pkt6->setIndex(3);
1985 iface = ifacemgr.getIface(pkt6);
1986 ASSERT_FALSE(iface)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(iface))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1986, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface", "true", "false") .c_str()) = ::testing::Message()
;
1987
1988 // Test that resetting the index is verifiable.
1989 pkt4->resetIndex();
1990 EXPECT_FALSE(pkt4->indexSet())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4->indexSet()
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1990, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pkt4->indexSet()", "true", "false") .c_str()) = ::testing
::Message()
;
1991 pkt6->resetIndex();
1992 EXPECT_FALSE(pkt6->indexSet())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6->indexSet()
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1992, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pkt6->indexSet()", "true", "false") .c_str()) = ::testing
::Message()
;
1993
1994 // Test that you can also reset the index via setIndex().
1995 pkt4->setIndex(UNSET_IFINDEX);
1996 EXPECT_FALSE(pkt4->indexSet())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4->indexSet()
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1996, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pkt4->indexSet()", "true", "false") .c_str()) = ::testing
::Message()
;
1997 pkt6->setIndex(UNSET_IFINDEX);
1998 EXPECT_FALSE(pkt6->indexSet())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6->indexSet()
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 1998, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pkt6->indexSet()", "true", "false") .c_str()) = ::testing
::Message()
;
1999}
2000
2001// Test that the IPv4 address can be retrieved for the interface.
2002TEST_F(IfaceMgrTest, ifaceGetAddress)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("ifaceGetAddress") > 1, "test_name must not be empty"
); class IfaceMgrTest_ifaceGetAddress_Test : public IfaceMgrTest
{ public: IfaceMgrTest_ifaceGetAddress_Test() = default; ~IfaceMgrTest_ifaceGetAddress_Test
() override = default; IfaceMgrTest_ifaceGetAddress_Test (const
IfaceMgrTest_ifaceGetAddress_Test &) = delete; IfaceMgrTest_ifaceGetAddress_Test
& operator=( const IfaceMgrTest_ifaceGetAddress_Test &
) = delete; IfaceMgrTest_ifaceGetAddress_Test (IfaceMgrTest_ifaceGetAddress_Test
&&) noexcept = delete; IfaceMgrTest_ifaceGetAddress_Test
& operator=( IfaceMgrTest_ifaceGetAddress_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_ifaceGetAddress_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "ifaceGetAddress", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2002), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2002), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2002), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_ifaceGetAddress_Test
>); void IfaceMgrTest_ifaceGetAddress_Test::TestBody()
{
2003 Iface iface("eth0", 0);
2004
2005 IOAddress addr("::1");
2006 // Initially, the Iface has no addresses assigned.
2007 EXPECT_FALSE(iface.getAddress4(addr))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(iface.getAddress4(addr
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2007, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface.getAddress4(addr)", "true", "false") .c_str()) = ::testing
::Message()
;
2008 // Add some addresses with IPv4 address in the middle.
2009 iface.addAddress(IOAddress("fe80::3a60:77ff:fed5:cdef"));
2010 iface.addAddress(IOAddress("10.1.2.3"));
2011 iface.addAddress(IOAddress("2001:db8:1::2"));
2012 // The v4 address should be returned.
2013 EXPECT_TRUE(iface.getAddress4(addr))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface.getAddress4(addr
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2013, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface.getAddress4(addr)", "false", "true") .c_str()) = ::testing
::Message()
;
2014 EXPECT_EQ("10.1.2.3", addr.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"10.1.2.3\""
, "addr.toText()", "10.1.2.3", addr.toText()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2014, gtest_ar
.failure_message()) = ::testing::Message()
;
2015 // Delete the IPv4 address and leave only two IPv6 addresses.
2016 ASSERT_NO_THROW(iface.delAddress(IOAddress("10.1.2.3")))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface.delAddress(IOAddress("10.1.2.3")); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2016; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2016; } } else gtest_label_testnothrow_2016
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2016, ("Expected: " "iface.delAddress(IOAddress(\"10.1.2.3\"))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2017 // The IPv4 address should not be returned.
2018 EXPECT_FALSE(iface.getAddress4(addr))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(iface.getAddress4(addr
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2018, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface.getAddress4(addr)", "true", "false") .c_str()) = ::testing
::Message()
;
2019 // Add a different IPv4 address at the end of the list.
2020 iface.addAddress(IOAddress("192.0.2.3"));
2021 // This new address should now be returned.
2022 EXPECT_TRUE(iface.getAddress4(addr))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface.getAddress4(addr
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2022, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface.getAddress4(addr)", "false", "true") .c_str()) = ::testing
::Message()
;
2023 EXPECT_EQ("192.0.2.3", addr.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.3\""
, "addr.toText()", "192.0.2.3", addr.toText()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2023, gtest_ar
.failure_message()) = ::testing::Message()
;
2024}
2025
2026// This test checks if it is possible to check that the specific address is
2027// assigned to the interface.
2028TEST_F(IfaceMgrTest, ifaceHasAddress)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("ifaceHasAddress") > 1, "test_name must not be empty"
); class IfaceMgrTest_ifaceHasAddress_Test : public IfaceMgrTest
{ public: IfaceMgrTest_ifaceHasAddress_Test() = default; ~IfaceMgrTest_ifaceHasAddress_Test
() override = default; IfaceMgrTest_ifaceHasAddress_Test (const
IfaceMgrTest_ifaceHasAddress_Test &) = delete; IfaceMgrTest_ifaceHasAddress_Test
& operator=( const IfaceMgrTest_ifaceHasAddress_Test &
) = delete; IfaceMgrTest_ifaceHasAddress_Test (IfaceMgrTest_ifaceHasAddress_Test
&&) noexcept = delete; IfaceMgrTest_ifaceHasAddress_Test
& operator=( IfaceMgrTest_ifaceHasAddress_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_ifaceHasAddress_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "ifaceHasAddress", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2028), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2028), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2028), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_ifaceHasAddress_Test
>); void IfaceMgrTest_ifaceHasAddress_Test::TestBody()
{
2029 IfaceMgrTestConfig config(true);
2030
2031 IfacePtr iface = IfaceMgr::instance().getIface("eth0");
2032 ASSERT_TRUE(iface)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2032, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface", "false", "true") .c_str()) = ::testing::Message()
;
2033 EXPECT_TRUE(iface->hasAddress(IOAddress("10.0.0.1")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface->hasAddress(
IOAddress("10.0.0.1")))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2033, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface->hasAddress(IOAddress(\"10.0.0.1\"))", "false", "true"
) .c_str()) = ::testing::Message()
;
2034 EXPECT_FALSE(iface->hasAddress(IOAddress("10.0.0.2")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(iface->hasAddress
(IOAddress("10.0.0.2"))))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2034, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface->hasAddress(IOAddress(\"10.0.0.2\"))", "true", "false"
) .c_str()) = ::testing::Message()
;
2035 EXPECT_TRUE(iface->hasAddress(IOAddress("fe80::3a60:77ff:fed5:cdef")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface->hasAddress(
IOAddress("fe80::3a60:77ff:fed5:cdef")))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2035, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface->hasAddress(IOAddress(\"fe80::3a60:77ff:fed5:cdef\"))"
, "false", "true") .c_str()) = ::testing::Message()
;
2036 EXPECT_TRUE(iface->hasAddress(IOAddress("2001:db8:1::1")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface->hasAddress(
IOAddress("2001:db8:1::1")))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2036, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface->hasAddress(IOAddress(\"2001:db8:1::1\"))", "false"
, "true") .c_str()) = ::testing::Message()
;
2037 EXPECT_FALSE(iface->hasAddress(IOAddress("2001:db8:1::2")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(iface->hasAddress
(IOAddress("2001:db8:1::2"))))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2037, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface->hasAddress(IOAddress(\"2001:db8:1::2\"))", "true"
, "false") .c_str()) = ::testing::Message()
;
2038}
2039
2040// This test checks it is not allowed to add duplicate interfaces.
2041TEST_F(IfaceMgrTest, addInterface)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("addInterface") > 1, "test_name must not be empty"
); class IfaceMgrTest_addInterface_Test : public IfaceMgrTest
{ public: IfaceMgrTest_addInterface_Test() = default; ~IfaceMgrTest_addInterface_Test
() override = default; IfaceMgrTest_addInterface_Test (const IfaceMgrTest_addInterface_Test
&) = delete; IfaceMgrTest_addInterface_Test & operator
=( const IfaceMgrTest_addInterface_Test &) = delete; IfaceMgrTest_addInterface_Test
(IfaceMgrTest_addInterface_Test &&) noexcept = delete
; IfaceMgrTest_addInterface_Test & operator=( IfaceMgrTest_addInterface_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_addInterface_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "addInterface", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2041), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2041), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2041), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_addInterface_Test
>); void IfaceMgrTest_addInterface_Test::TestBody()
{
2042 IfaceMgrTestConfig config(true);
2043
2044 IfacePtr dup_name(new Iface("eth1", 123));
2045 EXPECT_THROW_MSG(IfaceMgr::instance().addInterface(dup_name), Unexpected,{ try { IfaceMgr::instance().addInterface(dup_name); ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2046, "Failed"
) = ::testing::Message() << "no exception, expected: " <<
"Unexpected"; } catch (const Unexpected& ex) { switch (0
) case 0: default: if (const ::testing::AssertionResult gtest_ar
= (::testing::internal::EqHelper::Compare("std::string(ex.what())"
, "\"Can't add eth1/123 when eth1/2 already exists.\"", std::
string(ex.what()), "Can't add eth1/123 when eth1/2 already exists."
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2046, gtest_ar.failure_message()) = ::testing::Message(); }
catch (...) { ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2046, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: "
<< "Unexpected"; } }
2046 "Can't add eth1/123 when eth1/2 already exists."){ try { IfaceMgr::instance().addInterface(dup_name); ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2046, "Failed"
) = ::testing::Message() << "no exception, expected: " <<
"Unexpected"; } catch (const Unexpected& ex) { switch (0
) case 0: default: if (const ::testing::AssertionResult gtest_ar
= (::testing::internal::EqHelper::Compare("std::string(ex.what())"
, "\"Can't add eth1/123 when eth1/2 already exists.\"", std::
string(ex.what()), "Can't add eth1/123 when eth1/2 already exists."
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2046, gtest_ar.failure_message()) = ::testing::Message(); }
catch (...) { ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2046, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: "
<< "Unexpected"; } }
;
2047 IfacePtr dup_index(new Iface("eth2", 2));
2048 EXPECT_THROW_MSG(IfaceMgr::instance().addInterface(dup_index), Unexpected,{ try { IfaceMgr::instance().addInterface(dup_index); ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2049, "Failed"
) = ::testing::Message() << "no exception, expected: " <<
"Unexpected"; } catch (const Unexpected& ex) { switch (0
) case 0: default: if (const ::testing::AssertionResult gtest_ar
= (::testing::internal::EqHelper::Compare("std::string(ex.what())"
, "\"Can't add eth2/2 when eth1/2 already exists.\"", std::string
(ex.what()), "Can't add eth2/2 when eth1/2 already exists."))
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2049, gtest_ar.failure_message()) = ::testing::Message(); }
catch (...) { ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2049, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: "
<< "Unexpected"; } }
2049 "Can't add eth2/2 when eth1/2 already exists."){ try { IfaceMgr::instance().addInterface(dup_index); ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2049, "Failed"
) = ::testing::Message() << "no exception, expected: " <<
"Unexpected"; } catch (const Unexpected& ex) { switch (0
) case 0: default: if (const ::testing::AssertionResult gtest_ar
= (::testing::internal::EqHelper::Compare("std::string(ex.what())"
, "\"Can't add eth2/2 when eth1/2 already exists.\"", std::string
(ex.what()), "Can't add eth2/2 when eth1/2 already exists."))
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2049, gtest_ar.failure_message()) = ::testing::Message(); }
catch (...) { ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2049, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: "
<< "Unexpected"; } }
;
2050
2051 IfacePtr eth2(new Iface("eth2", 3));
2052 EXPECT_NO_THROW(IfaceMgr::instance().addInterface(eth2))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().addInterface(eth2); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2052; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2052; } } else gtest_label_testnothrow_2052
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2052, ("Expected: " "IfaceMgr::instance().addInterface(eth2)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2053}
2054
2055// TODO: Implement getPlainMac() test as soon as interface detection
2056// is implemented.
2057TEST_F(IfaceMgrTest, getIface)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("getIface") > 1, "test_name must not be empty"
); class IfaceMgrTest_getIface_Test : public IfaceMgrTest { public
: IfaceMgrTest_getIface_Test() = default; ~IfaceMgrTest_getIface_Test
() override = default; IfaceMgrTest_getIface_Test (const IfaceMgrTest_getIface_Test
&) = delete; IfaceMgrTest_getIface_Test & operator=(
const IfaceMgrTest_getIface_Test &) = delete; IfaceMgrTest_getIface_Test
(IfaceMgrTest_getIface_Test &&) noexcept = delete; IfaceMgrTest_getIface_Test
& operator=( IfaceMgrTest_getIface_Test &&) noexcept
= delete; private: void TestBody() override; [[maybe_unused]
] static ::testing::TestInfo* const test_info_; }; ::testing::
TestInfo* const IfaceMgrTest_getIface_Test::test_info_ = ::testing
::internal::MakeAndRegisterTestInfo( "IfaceMgrTest", "getIface"
, nullptr, nullptr, ::testing::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2057), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2057), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2057), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_getIface_Test
>); void IfaceMgrTest_getIface_Test::TestBody()
{
2058
2059 cout << "Interface checks. Please ignore socket binding errors." << endl;
2060 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
2061
2062 // Interface name, ifindex
2063 IfacePtr iface1(new Iface("lo1", 100));
2064 IfacePtr iface2(new Iface("eth9", 101));
2065 IfacePtr iface3(new Iface("en99", 102));
2066 IfacePtr iface4(new Iface("e1000g4", 103));
2067 cout << "This test assumes that there are less than 100 network interfaces"
2068 << " in the tested system and there are no lo1, eth9, en99, e1000g4"
2069 << " or wifi15 interfaces present." << endl;
2070
2071 // Note: real interfaces may be detected as well
2072 ifacemgr->addInterface(iface1);
2073 ifacemgr->addInterface(iface2);
2074 ifacemgr->addInterface(iface3);
2075 ifacemgr->addInterface(iface4);
2076
2077 cout << "There are " << ifacemgr->getIfaces().size()
2078 << " interfaces." << endl;
2079 for (auto const& iface : ifacemgr->getIfaces()) {
2080 cout << " " << iface->getFullName() << endl;
2081 }
2082
2083 // Check that interface can be retrieved by ifindex
2084 IfacePtr tmp = ifacemgr->getIface(102);
2085 ASSERT_TRUE(tmp)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(tmp)) ; else return ::
testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2085, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"tmp", "false", "true") .c_str()) = ::testing::Message()
;
2086
2087 EXPECT_EQ("en99", tmp->getName())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"en99\""
, "tmp->getName()", "en99", tmp->getName()))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2087, gtest_ar
.failure_message()) = ::testing::Message()
;
2088 EXPECT_EQ(102U, tmp->getIndex())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("102U", "tmp->getIndex()"
, 102U, tmp->getIndex()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2088, gtest_ar.failure_message()) = ::testing::Message()
;
2089
2090 // Check that interface can be retrieved by name
2091 tmp = ifacemgr->getIface("lo1");
2092 ASSERT_TRUE(tmp)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(tmp)) ; else return ::
testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2092, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"tmp", "false", "true") .c_str()) = ::testing::Message()
;
2093
2094 EXPECT_EQ("lo1", tmp->getName())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"lo1\""
, "tmp->getName()", "lo1", tmp->getName()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2094, gtest_ar
.failure_message()) = ::testing::Message()
;
2095 EXPECT_EQ(100U, tmp->getIndex())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("100U", "tmp->getIndex()"
, 100U, tmp->getIndex()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2095, gtest_ar.failure_message()) = ::testing::Message()
;
2096
2097 // Check that non-existing interfaces are not returned
2098 EXPECT_FALSE(ifacemgr->getIface("wifi15") )switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->getIface
("wifi15")))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2098, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->getIface(\"wifi15\")", "true", "false") .c_str
()) = ::testing::Message()
;
2099}
2100
2101TEST_F(IfaceMgrTest, clearIfaces)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("clearIfaces") > 1, "test_name must not be empty"
); class IfaceMgrTest_clearIfaces_Test : public IfaceMgrTest {
public: IfaceMgrTest_clearIfaces_Test() = default; ~IfaceMgrTest_clearIfaces_Test
() override = default; IfaceMgrTest_clearIfaces_Test (const IfaceMgrTest_clearIfaces_Test
&) = delete; IfaceMgrTest_clearIfaces_Test & operator
=( const IfaceMgrTest_clearIfaces_Test &) = delete; IfaceMgrTest_clearIfaces_Test
(IfaceMgrTest_clearIfaces_Test &&) noexcept = delete
; IfaceMgrTest_clearIfaces_Test & operator=( IfaceMgrTest_clearIfaces_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_clearIfaces_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "clearIfaces", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2101), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2101), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2101), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_clearIfaces_Test
>); void IfaceMgrTest_clearIfaces_Test::TestBody()
{
2102 NakedIfaceMgr ifacemgr;
2103 // Create a set of fake interfaces. At the same time, remove the actual
2104 // interfaces that have been detected by the IfaceMgr.
2105 ifacemgr.createIfaces();
2106
2107 ASSERT_GT(ifacemgr.countIfaces(), 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGT("ifacemgr.countIfaces()"
, "0", ifacemgr.countIfaces(), 0))) ; else return ::testing::
internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2107, gtest_ar
.failure_message()) = ::testing::Message()
;
2108
2109 boost::shared_ptr<TestPktFilter> custom_packet_filter(new TestPktFilter());
2110 ASSERT_TRUE(custom_packet_filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(custom_packet_filter)
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2110, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "custom_packet_filter", "false", "true") .c_str()) = ::testing
::Message()
;
2111 ASSERT_NO_THROW(ifacemgr.setPacketFilter(custom_packet_filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(custom_packet_filter); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2111; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2111; } } else gtest_label_testnothrow_2111
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2111, ("Expected: " "ifacemgr.setPacketFilter(custom_packet_filter)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2112
2113 ASSERT_NO_THROW(ifacemgr.openSockets4())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSockets4(); } else static_assert(true, ""); } catch
(std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2113
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2113
; } } else gtest_label_testnothrow_2113 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2113, ("Expected: " "ifacemgr.openSockets4()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
2114
2115 ifacemgr.clearIfaces();
2116
2117 EXPECT_EQ(0U, ifacemgr.countIfaces())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "ifacemgr.countIfaces()"
, 0U, ifacemgr.countIfaces()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2117, gtest_ar.failure_message()) = ::testing::Message()
;
2118}
2119
2120// Verify that we have the expected default DHCPv4 packet queue.
2121TEST_F(IfaceMgrTest, packetQueue4)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("packetQueue4") > 1, "test_name must not be empty"
); class IfaceMgrTest_packetQueue4_Test : public IfaceMgrTest
{ public: IfaceMgrTest_packetQueue4_Test() = default; ~IfaceMgrTest_packetQueue4_Test
() override = default; IfaceMgrTest_packetQueue4_Test (const IfaceMgrTest_packetQueue4_Test
&) = delete; IfaceMgrTest_packetQueue4_Test & operator
=( const IfaceMgrTest_packetQueue4_Test &) = delete; IfaceMgrTest_packetQueue4_Test
(IfaceMgrTest_packetQueue4_Test &&) noexcept = delete
; IfaceMgrTest_packetQueue4_Test & operator=( IfaceMgrTest_packetQueue4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_packetQueue4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "packetQueue4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2121), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2121), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2121), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_packetQueue4_Test
>); void IfaceMgrTest_packetQueue4_Test::TestBody()
{
2122 NakedIfaceMgr ifacemgr;
2123
2124 // Should not have a queue at start up.
2125 ASSERT_FALSE(ifacemgr.getPacketQueue4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.getPacketQueue4
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2125, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getPacketQueue4()", "true", "false") .c_str()) = ::
testing::Message()
;
2126
2127 // Verify that we can create a queue with default factory.
2128 data::ConstElementPtr config = makeQueueConfig(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4, 2000);
2129 ASSERT_NO_THROW(ifacemgr.getPacketQueueMgr4()->createPacketQueue(config))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.getPacketQueueMgr4()->createPacketQueue(config);
} else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2129; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2129
; } } else gtest_label_testnothrow_2129 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2129, ("Expected: " "ifacemgr.getPacketQueueMgr4()->createPacketQueue(config)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2130 CHECK_QUEUE_INFO(ifacemgr.getPacketQueue4(), "{ \"capacity\": 2000, \"queue-type\": \""{ std::ostringstream oss__; oss__ << "{ \"capacity\": 2000, \"queue-type\": \""
<< PacketQueueMgr4::DEFAULT_QUEUE_TYPE4 << "\", \"size\": 0 }"
; checkInfo(ifacemgr.getPacketQueue4(), oss__.str().c_str());
}
2131 << PacketQueueMgr4::DEFAULT_QUEUE_TYPE4 << "\", \"size\": 0 }"){ std::ostringstream oss__; oss__ << "{ \"capacity\": 2000, \"queue-type\": \""
<< PacketQueueMgr4::DEFAULT_QUEUE_TYPE4 << "\", \"size\": 0 }"
; checkInfo(ifacemgr.getPacketQueue4(), oss__.str().c_str());
}
;
2132}
2133
2134// Verify that we have the expected default DHCPv6 packet queue.
2135TEST_F(IfaceMgrTest, packetQueue6)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("packetQueue6") > 1, "test_name must not be empty"
); class IfaceMgrTest_packetQueue6_Test : public IfaceMgrTest
{ public: IfaceMgrTest_packetQueue6_Test() = default; ~IfaceMgrTest_packetQueue6_Test
() override = default; IfaceMgrTest_packetQueue6_Test (const IfaceMgrTest_packetQueue6_Test
&) = delete; IfaceMgrTest_packetQueue6_Test & operator
=( const IfaceMgrTest_packetQueue6_Test &) = delete; IfaceMgrTest_packetQueue6_Test
(IfaceMgrTest_packetQueue6_Test &&) noexcept = delete
; IfaceMgrTest_packetQueue6_Test & operator=( IfaceMgrTest_packetQueue6_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_packetQueue6_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "packetQueue6", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2135), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2135), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2135), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_packetQueue6_Test
>); void IfaceMgrTest_packetQueue6_Test::TestBody()
{
2136 NakedIfaceMgr ifacemgr;
2137
2138 // Should not have a queue at start up.
2139 ASSERT_FALSE(ifacemgr.getPacketQueue6())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.getPacketQueue6
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2139, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getPacketQueue6()", "true", "false") .c_str()) = ::
testing::Message()
;
2140
2141 // Verify that we can create a queue with default factory.
2142 data::ConstElementPtr config = makeQueueConfig(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6, 2000);
2143 ASSERT_NO_THROW(ifacemgr.getPacketQueueMgr6()->createPacketQueue(config))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.getPacketQueueMgr6()->createPacketQueue(config);
} else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2143; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2143
; } } else gtest_label_testnothrow_2143 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2143, ("Expected: " "ifacemgr.getPacketQueueMgr6()->createPacketQueue(config)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2144 CHECK_QUEUE_INFO(ifacemgr.getPacketQueue6(), "{ \"capacity\": 2000, \"queue-type\": \""{ std::ostringstream oss__; oss__ << "{ \"capacity\": 2000, \"queue-type\": \""
<< PacketQueueMgr6::DEFAULT_QUEUE_TYPE6 << "\", \"size\": 0 }"
; checkInfo(ifacemgr.getPacketQueue6(), oss__.str().c_str());
}
2145 << PacketQueueMgr6::DEFAULT_QUEUE_TYPE6 << "\", \"size\": 0 }"){ std::ostringstream oss__; oss__ << "{ \"capacity\": 2000, \"queue-type\": \""
<< PacketQueueMgr6::DEFAULT_QUEUE_TYPE6 << "\", \"size\": 0 }"
; checkInfo(ifacemgr.getPacketQueue6(), oss__.str().c_str());
}
;
2146}
2147
2148void IfaceMgrTest::testReceiveTimeout6() {
2149 using namespace boost::posix_time;
2150 std::cout << "Testing DHCPv6 packet reception timeouts."
2151 << " Test will block for a few seconds when waiting"
2152 << " for timeout to occur." << std::endl;
2153
2154 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
2155 // Open socket on the lo interface.
2156 IOAddress lo_addr("::1");
2157 int socket1 = 0;
2158 ASSERT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2160; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2160
; } } else gtest_label_testnothrow_2160 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2160, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2159 socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2160; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2160
; } } else gtest_label_testnothrow_2160 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2160, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2160 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2160; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2160
; } } else gtest_label_testnothrow_2160 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2160, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2161 // Socket is open if result is non-negative.
2162 ASSERT_GE(socket1, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket1", "0",
socket1, 0))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2162, gtest_ar.failure_message()) = ::testing::Message()
;
2163 // Start receiver.
2164 ASSERT_NO_THROW(ifacemgr->startDHCPReceiver(AF_INET6))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->startDHCPReceiver(10); } else static_assert(true
, ""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2164
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2164
; } } else gtest_label_testnothrow_2164 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2164, ("Expected: " "ifacemgr->startDHCPReceiver(10)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
2165
2166 // Remember when we call receive6().
2167 ptime start_time = microsec_clock::universal_time();
2168 // Call receive with timeout of 1s + 400000us = 1.4s.
2169 Pkt6Ptr pkt;
2170 ASSERT_NO_THROW(pkt = ifacemgr->receive6(1, 400000))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt = ifacemgr->receive6(1, 400000); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2170; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2170; } } else gtest_label_testnothrow_2170
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2170, ("Expected: " "pkt = ifacemgr->receive6(1, 400000)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2171 // Remember when call to receive6() ended.
2172 ptime stop_time = microsec_clock::universal_time();
2173 // We did not send a packet to lo interface so we expect that
2174 // nothing has been received and timeout has been reached.
2175 ASSERT_FALSE(pkt)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2175, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pkt", "true", "false") .c_str()) = ::testing::Message()
;
2176 // Calculate duration of call to receive6().
2177 time_duration duration = stop_time - start_time;
2178 // We stop the clock when the call completes so it does not
2179 // precisely reflect the receive timeout. However the
2180 // uncertainty should be low enough to expect that measured
2181 // value is in the range <1.4s; 1.7s>.
2182 EXPECT_GE(duration.total_microseconds(),switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("duration.total_microseconds()"
, "1400000 - TIMEOUT_TOLERANCE", duration.total_microseconds(
), 1400000 - TIMEOUT_TOLERANCE))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2183, gtest_ar.failure_message()) = ::testing::Message()
2183 1400000 - TIMEOUT_TOLERANCE)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("duration.total_microseconds()"
, "1400000 - TIMEOUT_TOLERANCE", duration.total_microseconds(
), 1400000 - TIMEOUT_TOLERANCE))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2183, gtest_ar.failure_message()) = ::testing::Message()
;
2184 EXPECT_LE(duration.total_microseconds(), 1700000)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLE("duration.total_microseconds()"
, "1700000", duration.total_microseconds(), 1700000))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2184, gtest_ar.failure_message()) = ::testing::Message()
;
2185
2186 // Test timeout shorter than 1s.
2187 start_time = microsec_clock::universal_time();
2188 ASSERT_NO_THROW(pkt = ifacemgr->receive6(0, 500000))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt = ifacemgr->receive6(0, 500000); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2188; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2188; } } else gtest_label_testnothrow_2188
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2188, ("Expected: " "pkt = ifacemgr->receive6(0, 500000)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2189 stop_time = microsec_clock::universal_time();
2190 ASSERT_FALSE(pkt)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2190, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pkt", "true", "false") .c_str()) = ::testing::Message()
;
2191 duration = stop_time - start_time;
2192 // Check if measured duration is within <0.5s; 0.8s>.
2193 EXPECT_GE(duration.total_microseconds(),switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("duration.total_microseconds()"
, "500000 - TIMEOUT_TOLERANCE", duration.total_microseconds()
, 500000 - TIMEOUT_TOLERANCE))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2194, gtest_ar.failure_message()) = ::testing::Message()
2194 500000 - TIMEOUT_TOLERANCE)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("duration.total_microseconds()"
, "500000 - TIMEOUT_TOLERANCE", duration.total_microseconds()
, 500000 - TIMEOUT_TOLERANCE))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2194, gtest_ar.failure_message()) = ::testing::Message()
;
2195 EXPECT_LE(duration.total_microseconds(), 800000)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLE("duration.total_microseconds()"
, "800000", duration.total_microseconds(), 800000))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2195, gtest_ar
.failure_message()) = ::testing::Message()
;
2196
2197 // Test with invalid fractional timeout values.
2198 EXPECT_THROW(ifacemgr->receive6(0, 1000000), isc::BadValue)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->receive6(0,
1000000); } else static_assert(true, ""); } catch (isc::BadValue
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< isc::BadValue>::type
>::type, std::exception>::value, const ::testing::internal
::NeverThrown&, const std::exception&>::type e) { gtest_msg
.value = "Expected: " "ifacemgr->receive6(0, 1000000)" " throws an exception of type "
"isc::BadValue" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_2198; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->receive6(0, 1000000)"
" throws an exception of type " "isc::BadValue" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2198; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->receive6(0, 1000000)"
" throws an exception of type " "isc::BadValue" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2198; } } else gtest_label_testthrow_2198
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2198, gtest_msg.value.c_str()) = ::testing::Message()
;
2199 EXPECT_THROW(ifacemgr->receive6(1, 1000010), isc::BadValue)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->receive6(1,
1000010); } else static_assert(true, ""); } catch (isc::BadValue
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< isc::BadValue>::type
>::type, std::exception>::value, const ::testing::internal
::NeverThrown&, const std::exception&>::type e) { gtest_msg
.value = "Expected: " "ifacemgr->receive6(1, 1000010)" " throws an exception of type "
"isc::BadValue" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_2199; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->receive6(1, 1000010)"
" throws an exception of type " "isc::BadValue" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2199; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->receive6(1, 1000010)"
" throws an exception of type " "isc::BadValue" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2199; } } else gtest_label_testthrow_2199
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2199, gtest_msg.value.c_str()) = ::testing::Message()
;
2200
2201 // Stop receiver.
2202 EXPECT_NO_THROW(ifacemgr->stopDHCPReceiver())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->stopDHCPReceiver(); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2202
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2202
; } } else gtest_label_testnothrow_2202 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2202, ("Expected: " "ifacemgr->stopDHCPReceiver()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
2203}
2204
2205TEST_F(IfaceMgrTest, receiveTimeout6Select)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("receiveTimeout6Select") > 1, "test_name must not be empty"
); class IfaceMgrTest_receiveTimeout6Select_Test : public IfaceMgrTest
{ public: IfaceMgrTest_receiveTimeout6Select_Test() = default
; ~IfaceMgrTest_receiveTimeout6Select_Test() override = default
; IfaceMgrTest_receiveTimeout6Select_Test (const IfaceMgrTest_receiveTimeout6Select_Test
&) = delete; IfaceMgrTest_receiveTimeout6Select_Test &
operator=( const IfaceMgrTest_receiveTimeout6Select_Test &
) = delete; IfaceMgrTest_receiveTimeout6Select_Test (IfaceMgrTest_receiveTimeout6Select_Test
&&) noexcept = delete; IfaceMgrTest_receiveTimeout6Select_Test
& operator=( IfaceMgrTest_receiveTimeout6Select_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_receiveTimeout6Select_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "receiveTimeout6Select", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2205), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2205), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2205), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_receiveTimeout6Select_Test
>); void IfaceMgrTest_receiveTimeout6Select_Test::TestBody
()
{
2206 kea_event_handler_type_.setValue("select");
2207 testReceiveTimeout6();
2208}
2209
2210TEST_F(IfaceMgrTest, receiveTimeout6Poll)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("receiveTimeout6Poll") > 1, "test_name must not be empty"
); class IfaceMgrTest_receiveTimeout6Poll_Test : public IfaceMgrTest
{ public: IfaceMgrTest_receiveTimeout6Poll_Test() = default;
~IfaceMgrTest_receiveTimeout6Poll_Test() override = default;
IfaceMgrTest_receiveTimeout6Poll_Test (const IfaceMgrTest_receiveTimeout6Poll_Test
&) = delete; IfaceMgrTest_receiveTimeout6Poll_Test &
operator=( const IfaceMgrTest_receiveTimeout6Poll_Test &
) = delete; IfaceMgrTest_receiveTimeout6Poll_Test (IfaceMgrTest_receiveTimeout6Poll_Test
&&) noexcept = delete; IfaceMgrTest_receiveTimeout6Poll_Test
& operator=( IfaceMgrTest_receiveTimeout6Poll_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_receiveTimeout6Poll_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "receiveTimeout6Poll", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2210), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2210), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2210), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_receiveTimeout6Poll_Test
>); void IfaceMgrTest_receiveTimeout6Poll_Test::TestBody()
{
2211 kea_event_handler_type_.setValue("poll");
2212 testReceiveTimeout6();
2213}
2214
2215void IfaceMgrTest::testReceiveTimeout4() {
2216 using namespace boost::posix_time;
2217 std::cout << "Testing DHCPv4 packet reception timeouts."
2218 << " Test will block for a few seconds when waiting"
2219 << " for timeout to occur." << std::endl;
2220
2221 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
2222 // Open socket on the lo interface.
2223 IOAddress lo_addr("127.0.0.1");
2224 int socket1 = 0;
2225 ASSERT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10067
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2227; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2227
; } } else gtest_label_testnothrow_2227 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2227, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10067)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2226 socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10067)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10067
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2227; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2227
; } } else gtest_label_testnothrow_2227 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2227, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10067)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2227 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10067
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2227; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2227
; } } else gtest_label_testnothrow_2227 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2227, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10067)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2228 // Socket is open if returned value is non-negative.
2229 ASSERT_GE(socket1, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket1", "0",
socket1, 0))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2229, gtest_ar.failure_message()) = ::testing::Message()
;
2230
2231 // Start receiver.
2232 ASSERT_NO_THROW(ifacemgr->startDHCPReceiver(AF_INET))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->startDHCPReceiver(2); } else static_assert(true
, ""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2232
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2232
; } } else gtest_label_testnothrow_2232 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2232, ("Expected: " "ifacemgr->startDHCPReceiver(2)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
2233
2234 Pkt4Ptr pkt;
2235 // Remember when we call receive4().
2236 ptime start_time = microsec_clock::universal_time();
2237 // Call receive with timeout of 2s + 300000us = 2.3s.
2238 ASSERT_NO_THROW(pkt = ifacemgr->receive4(2, 300000))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt = ifacemgr->receive4(2, 300000); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2238; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2238; } } else gtest_label_testnothrow_2238
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2238, ("Expected: " "pkt = ifacemgr->receive4(2, 300000)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2239 // Remember when call to receive4() ended.
2240 ptime stop_time = microsec_clock::universal_time();
2241 // We did not send a packet to lo interface so we expect that
2242 // nothing has been received and timeout has been reached.
2243 ASSERT_FALSE(pkt)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2243, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pkt", "true", "false") .c_str()) = ::testing::Message()
;
2244 // Calculate duration of call to receive4().
2245 time_duration duration = stop_time - start_time;
2246 // We stop the clock when the call completes so it does not
2247 // precisely reflect the receive timeout. However the
2248 // uncertainty should be low enough to expect that measured
2249 // value is in the range <2.3s; 2.6s>.
2250 EXPECT_GE(duration.total_microseconds(),switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("duration.total_microseconds()"
, "2300000 - TIMEOUT_TOLERANCE", duration.total_microseconds(
), 2300000 - TIMEOUT_TOLERANCE))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2251, gtest_ar.failure_message()) = ::testing::Message()
2251 2300000 - TIMEOUT_TOLERANCE)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("duration.total_microseconds()"
, "2300000 - TIMEOUT_TOLERANCE", duration.total_microseconds(
), 2300000 - TIMEOUT_TOLERANCE))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2251, gtest_ar.failure_message()) = ::testing::Message()
;
2252 EXPECT_LE(duration.total_microseconds(), 2600000)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLE("duration.total_microseconds()"
, "2600000", duration.total_microseconds(), 2600000))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2252, gtest_ar.failure_message()) = ::testing::Message()
;
2253
2254 // Test timeout shorter than 1s.
2255 start_time = microsec_clock::universal_time();
2256 ASSERT_NO_THROW(pkt = ifacemgr->receive4(0, 400000))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt = ifacemgr->receive4(0, 400000); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2256; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2256; } } else gtest_label_testnothrow_2256
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2256, ("Expected: " "pkt = ifacemgr->receive4(0, 400000)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2257 stop_time = microsec_clock::universal_time();
2258 ASSERT_FALSE(pkt)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2258, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pkt", "true", "false") .c_str()) = ::testing::Message()
;
2259 duration = stop_time - start_time;
2260 // Check if measured duration is within <0.4s; 0.7s>.
2261 EXPECT_GE(duration.total_microseconds(),switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("duration.total_microseconds()"
, "400000 - TIMEOUT_TOLERANCE", duration.total_microseconds()
, 400000 - TIMEOUT_TOLERANCE))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2262, gtest_ar.failure_message()) = ::testing::Message()
2262 400000 - TIMEOUT_TOLERANCE)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("duration.total_microseconds()"
, "400000 - TIMEOUT_TOLERANCE", duration.total_microseconds()
, 400000 - TIMEOUT_TOLERANCE))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2262, gtest_ar.failure_message()) = ::testing::Message()
;
2263 EXPECT_LE(duration.total_microseconds(), 700000)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLE("duration.total_microseconds()"
, "700000", duration.total_microseconds(), 700000))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2263, gtest_ar
.failure_message()) = ::testing::Message()
;
2264
2265 // Test with invalid fractional timeout values.
2266 EXPECT_THROW(ifacemgr->receive4(0, 1000000), isc::BadValue)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->receive4(0,
1000000); } else static_assert(true, ""); } catch (isc::BadValue
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< isc::BadValue>::type
>::type, std::exception>::value, const ::testing::internal
::NeverThrown&, const std::exception&>::type e) { gtest_msg
.value = "Expected: " "ifacemgr->receive4(0, 1000000)" " throws an exception of type "
"isc::BadValue" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_2266; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->receive4(0, 1000000)"
" throws an exception of type " "isc::BadValue" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2266; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->receive4(0, 1000000)"
" throws an exception of type " "isc::BadValue" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2266; } } else gtest_label_testthrow_2266
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2266, gtest_msg.value.c_str()) = ::testing::Message()
;
2267 EXPECT_THROW(ifacemgr->receive4(2, 1000005), isc::BadValue)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->receive4(2,
1000005); } else static_assert(true, ""); } catch (isc::BadValue
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< isc::BadValue>::type
>::type, std::exception>::value, const ::testing::internal
::NeverThrown&, const std::exception&>::type e) { gtest_msg
.value = "Expected: " "ifacemgr->receive4(2, 1000005)" " throws an exception of type "
"isc::BadValue" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_2267; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->receive4(2, 1000005)"
" throws an exception of type " "isc::BadValue" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2267; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->receive4(2, 1000005)"
" throws an exception of type " "isc::BadValue" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2267; } } else gtest_label_testthrow_2267
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2267, gtest_msg.value.c_str()) = ::testing::Message()
;
2268
2269 // Stop receiver.
2270 EXPECT_NO_THROW(ifacemgr->stopDHCPReceiver())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->stopDHCPReceiver(); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2270
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2270
; } } else gtest_label_testnothrow_2270 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2270, ("Expected: " "ifacemgr->stopDHCPReceiver()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
2271}
2272
2273TEST_F(IfaceMgrTest, receiveTimeout4Select)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("receiveTimeout4Select") > 1, "test_name must not be empty"
); class IfaceMgrTest_receiveTimeout4Select_Test : public IfaceMgrTest
{ public: IfaceMgrTest_receiveTimeout4Select_Test() = default
; ~IfaceMgrTest_receiveTimeout4Select_Test() override = default
; IfaceMgrTest_receiveTimeout4Select_Test (const IfaceMgrTest_receiveTimeout4Select_Test
&) = delete; IfaceMgrTest_receiveTimeout4Select_Test &
operator=( const IfaceMgrTest_receiveTimeout4Select_Test &
) = delete; IfaceMgrTest_receiveTimeout4Select_Test (IfaceMgrTest_receiveTimeout4Select_Test
&&) noexcept = delete; IfaceMgrTest_receiveTimeout4Select_Test
& operator=( IfaceMgrTest_receiveTimeout4Select_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_receiveTimeout4Select_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "receiveTimeout4Select", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2273), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2273), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2273), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_receiveTimeout4Select_Test
>); void IfaceMgrTest_receiveTimeout4Select_Test::TestBody
()
{
2274 kea_event_handler_type_.setValue("select");
2275 testReceiveTimeout4();
2276}
2277
2278TEST_F(IfaceMgrTest, receiveTimeout4Poll)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("receiveTimeout4Poll") > 1, "test_name must not be empty"
); class IfaceMgrTest_receiveTimeout4Poll_Test : public IfaceMgrTest
{ public: IfaceMgrTest_receiveTimeout4Poll_Test() = default;
~IfaceMgrTest_receiveTimeout4Poll_Test() override = default;
IfaceMgrTest_receiveTimeout4Poll_Test (const IfaceMgrTest_receiveTimeout4Poll_Test
&) = delete; IfaceMgrTest_receiveTimeout4Poll_Test &
operator=( const IfaceMgrTest_receiveTimeout4Poll_Test &
) = delete; IfaceMgrTest_receiveTimeout4Poll_Test (IfaceMgrTest_receiveTimeout4Poll_Test
&&) noexcept = delete; IfaceMgrTest_receiveTimeout4Poll_Test
& operator=( IfaceMgrTest_receiveTimeout4Poll_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_receiveTimeout4Poll_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "receiveTimeout4Poll", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2278), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2278), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2278), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_receiveTimeout4Poll_Test
>); void IfaceMgrTest_receiveTimeout4Poll_Test::TestBody()
{
2279 kea_event_handler_type_.setValue("poll");
2280 testReceiveTimeout4();
2281}
2282
2283TEST_F(IfaceMgrTest, multipleSockets)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("multipleSockets") > 1, "test_name must not be empty"
); class IfaceMgrTest_multipleSockets_Test : public IfaceMgrTest
{ public: IfaceMgrTest_multipleSockets_Test() = default; ~IfaceMgrTest_multipleSockets_Test
() override = default; IfaceMgrTest_multipleSockets_Test (const
IfaceMgrTest_multipleSockets_Test &) = delete; IfaceMgrTest_multipleSockets_Test
& operator=( const IfaceMgrTest_multipleSockets_Test &
) = delete; IfaceMgrTest_multipleSockets_Test (IfaceMgrTest_multipleSockets_Test
&&) noexcept = delete; IfaceMgrTest_multipleSockets_Test
& operator=( IfaceMgrTest_multipleSockets_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_multipleSockets_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "multipleSockets", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2283), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2283), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2283), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_multipleSockets_Test
>); void IfaceMgrTest_multipleSockets_Test::TestBody()
{
2284 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
2285
2286 // Container for initialized socket descriptors
2287 std::list<uint16_t> init_sockets;
2288
2289 // Create socket #1
2290 int socket1 = 0;
2291 ASSERT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT1
, 2);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2293; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2293
; } } else gtest_label_testnothrow_2293 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2293, ("Expected: " "socket1 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT1, 2);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
1
Control jumps to 'case 0:' at line 2291
2
Taking true branch
3
Assuming the condition is false
4
Taking false branch
2292 socket1 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT1, AF_INET);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT1
, 2);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2293; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2293
; } } else gtest_label_testnothrow_2293 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2293, ("Expected: " "socket1 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT1, 2);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2293 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT1
, 2);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2293; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2293
; } } else gtest_label_testnothrow_2293 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2293, ("Expected: " "socket1 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT1, 2);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2294 ASSERT_GE(socket1, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket1", "0",
socket1, 0))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2294, gtest_ar.failure_message()) = ::testing::Message()
;
5
Control jumps to 'case 0:' at line 2294
6
Assuming the condition is true
7
Taking true branch
2295 init_sockets.push_back(socket1);
2296
2297 // Create socket #2
2298 IOAddress lo_addr("127.0.0.1");
2299 int socket2 = 0;
2300 ASSERT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket2 = ifacemgr->openSocketFromRemoteAddress(lo_addr, PORT2
);; } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2302; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2302
; } } else gtest_label_testnothrow_2302 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2302, ("Expected: " "socket2 = ifacemgr->openSocketFromRemoteAddress(lo_addr, PORT2);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
8
Control jumps to 'case 0:' at line 2300
9
Taking true branch
10
Assuming the condition is false
11
Taking false branch
2301 socket2 = ifacemgr->openSocketFromRemoteAddress(lo_addr, PORT2);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket2 = ifacemgr->openSocketFromRemoteAddress(lo_addr, PORT2
);; } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2302; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2302
; } } else gtest_label_testnothrow_2302 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2302, ("Expected: " "socket2 = ifacemgr->openSocketFromRemoteAddress(lo_addr, PORT2);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2302 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket2 = ifacemgr->openSocketFromRemoteAddress(lo_addr, PORT2
);; } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2302; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2302
; } } else gtest_label_testnothrow_2302 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2302, ("Expected: " "socket2 = ifacemgr->openSocketFromRemoteAddress(lo_addr, PORT2);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2303 ASSERT_GE(socket2, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket2", "0",
socket2, 0))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2303, gtest_ar.failure_message()) = ::testing::Message()
;
12
Control jumps to 'case 0:' at line 2303
13
Assuming the condition is true
14
Taking true branch
2304 init_sockets.push_back(socket2);
2305
2306 // Get loopback interface. If we don't find one we are unable to run
2307 // this test but we don't want to fail.
2308 IfacePtr iface_ptr = ifacemgr->getIface(LOOPBACK_NAME);
2309 if (iface_ptr == NULL__null) {
15
Taking false branch
2310 cout << "Local loopback interface not found. Skipping test. " << endl;
2311 return;
2312 }
2313 ASSERT_EQ(LOOPBACK_INDEX, iface_ptr->getIndex())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("LOOPBACK_INDEX"
, "iface_ptr->getIndex()", LOOPBACK_INDEX, iface_ptr->getIndex
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2313, gtest_ar.failure_message()) = ::testing::Message()
;
16
Control jumps to 'case 0:' at line 2313
17
Assuming the condition is true
18
Taking true branch
2314 // Once sockets have been successfully opened, they are supposed to
2315 // be on the list. Here we start to test if all expected sockets
2316 // are on the list and no other (unexpected) socket is there.
2317 Iface::SocketCollection sockets = iface_ptr->getSockets();
2318 size_t matched_sockets = 0;
2319 for (std::list<uint16_t>::iterator init_sockets_it =
19
Loop condition is false. Execution continues on line 2344
2320 init_sockets.begin();
2321 init_sockets_it != init_sockets.end(); ++init_sockets_it) {
2322 // Set socket descriptors non blocking in order to be able
2323 // to call recv() on them without hang.
2324 int flags = fcntl(*init_sockets_it, F_GETFL3, 0);
2325 ASSERT_GE(flags, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("flags", "0", flags
, 0))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2325, gtest_ar.failure_message()) = ::testing::Message()
;
2326 ASSERT_GE(fcntl(*init_sockets_it, F_SETFL, flags | O_NONBLOCK), 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("fcntl(*init_sockets_it, 4, flags | 04000)"
, "0", fcntl(*init_sockets_it, 4, flags | 04000), 0))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2326, gtest_ar.failure_message()) = ::testing::Message()
;
2327 // recv() is expected to result in EWOULDBLOCK error on non-blocking
2328 // socket in case socket is valid but simply no data are coming in.
2329 char buf;
2330 recv(*init_sockets_it, &buf, 1, MSG_PEEKMSG_PEEK);
2331 EXPECT_EQ(EWOULDBLOCK, errno)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("11", "(*__errno_location ())"
, 11, (*__errno_location ())))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2331, gtest_ar.failure_message()) = ::testing::Message()
;
2332 // Apart from the ability to use the socket we want to make
2333 // sure that socket on the list is the one that we created.
2334 for (Iface::SocketCollection::const_iterator socket_it =
2335 sockets.begin(); socket_it != sockets.end(); ++socket_it) {
2336 if (*init_sockets_it == socket_it->sockfd_) {
2337 // This socket is the one that we created.
2338 ++matched_sockets;
2339 break;
2340 }
2341 }
2342 }
2343 // All created sockets have been matched if this condition works.
2344 EXPECT_EQ(sockets.size(), matched_sockets)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("sockets.size()"
, "matched_sockets", sockets.size(), matched_sockets))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2344, gtest_ar.failure_message()) = ::testing::Message()
;
20
Control jumps to 'case 0:' at line 2344
21
Assuming the condition is true
22
Taking true branch
2345
2346 // closeSockets() is the other function that we want to test. It
2347 // is supposed to close all sockets so as we will not be able to use
2348 // them anymore communication.
2349 ifacemgr->closeSockets();
2350
2351 // Closed sockets are supposed to be removed from the list
2352 sockets = iface_ptr->getSockets();
2353 ASSERT_EQ(0U, sockets.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "sockets.size()"
, 0U, sockets.size()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2353, gtest_ar.failure_message()) = ::testing::Message()
;
23
Control jumps to 'case 0:' at line 2353
24
Assuming the condition is true
25
Taking true branch
2354
2355 // We are still in possession of socket descriptors that we created
2356 // on the beginning of this test. We can use them to check whether
2357 // closeSockets() only removed them from the list or they have been
2358 // really closed.
2359 for (std::list<uint16_t>::const_iterator init_sockets_it =
26
Loop condition is true. Entering loop body
2360 init_sockets.begin();
2361 init_sockets_it != init_sockets.end(); ++init_sockets_it) {
2362 // recv() must result in error when using invalid socket.
2363 char buf;
2364 static_cast<void>(recv(*init_sockets_it, &buf, 1, MSG_PEEKMSG_PEEK));
27
Assuming that 'recv' is successful; 'errno' becomes undefined after the call
2365 // EWOULDBLOCK would mean that socket is valid/open but
2366 // simply no data is received so we have to check for
2367 // other errors.
2368 EXPECT_NE(EWOULDBLOCK, errno)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("11", "(*__errno_location ())"
, 11, (*__errno_location ())))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2368, gtest_ar.failure_message()) = ::testing::Message()
;
28
Control jumps to 'case 0:' at line 2368
29
Calling 'CmpHelperNE<int, int>'
2369 }
2370}
2371
2372TEST_F(IfaceMgrTest, sockets6)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("sockets6") > 1, "test_name must not be empty"
); class IfaceMgrTest_sockets6_Test : public IfaceMgrTest { public
: IfaceMgrTest_sockets6_Test() = default; ~IfaceMgrTest_sockets6_Test
() override = default; IfaceMgrTest_sockets6_Test (const IfaceMgrTest_sockets6_Test
&) = delete; IfaceMgrTest_sockets6_Test & operator=(
const IfaceMgrTest_sockets6_Test &) = delete; IfaceMgrTest_sockets6_Test
(IfaceMgrTest_sockets6_Test &&) noexcept = delete; IfaceMgrTest_sockets6_Test
& operator=( IfaceMgrTest_sockets6_Test &&) noexcept
= delete; private: void TestBody() override; [[maybe_unused]
] static ::testing::TestInfo* const test_info_; }; ::testing::
TestInfo* const IfaceMgrTest_sockets6_Test::test_info_ = ::testing
::internal::MakeAndRegisterTestInfo( "IfaceMgrTest", "sockets6"
, nullptr, nullptr, ::testing::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2372), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2372), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2372), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_sockets6_Test
>); void IfaceMgrTest_sockets6_Test::TestBody()
{
2373 // Testing socket operation in a portable way is tricky
2374 // without interface detection implemented.
2375
2376 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
2377
2378 IOAddress lo_addr("::1");
2379
2380 Pkt6Ptr pkt6(new Pkt6(DHCPV6_SOLICIT, 123));
2381 pkt6->setIface(LOOPBACK_NAME);
2382
2383 // Bind multicast socket to port 10547
2384 int socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547);
2385 EXPECT_GE(socket1, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket1", "0",
socket1, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2385, gtest_ar.failure_message()) = ::testing::Message()
; // socket >= 0
2386
2387 EXPECT_EQ(socket1, ifacemgr->getSocket(pkt6))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("socket1"
, "ifacemgr->getSocket(pkt6)", socket1, ifacemgr->getSocket
(pkt6)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2387, gtest_ar.failure_message()) = ::testing::Message()
;
2388
2389 // Bind unicast socket to port 10548
2390 int socket2 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10548);
2391 EXPECT_GE(socket2, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket2", "0",
socket2, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2391, gtest_ar.failure_message()) = ::testing::Message()
;
2392
2393 // Removed code for binding socket twice to the same address/port
2394 // as it caused problems on some platforms (e.g. Mac OS X)
2395
2396 // Close sockets here because the following tests will want to
2397 // open sockets on the same ports.
2398 ifacemgr->closeSockets();
2399
2400 // Use address that is not assigned to LOOPBACK iface.
2401 IOAddress invalidAddr("::2");
2402 EXPECT_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->openSocket(
LOOPBACK_NAME, invalidAddr, 10547); } else static_assert(true
, ""); } catch (SocketConfigError const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
SocketConfigError>::type>::type, std::exception>::value
, const ::testing::internal::NeverThrown&, const std::exception
&>::type e) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(LOOPBACK_NAME, invalidAddr, 10547)"
" throws an exception of type " "SocketConfigError" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_2405
; } catch (...) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(LOOPBACK_NAME, invalidAddr, 10547)"
" throws an exception of type " "SocketConfigError" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2405; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(LOOPBACK_NAME, invalidAddr, 10547)"
" throws an exception of type " "SocketConfigError" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2405; } } else gtest_label_testthrow_2405
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2405, gtest_msg.value.c_str()) = ::testing::Message()
2403 ifacemgr->openSocket(LOOPBACK_NAME, invalidAddr, 10547),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->openSocket(
LOOPBACK_NAME, invalidAddr, 10547); } else static_assert(true
, ""); } catch (SocketConfigError const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
SocketConfigError>::type>::type, std::exception>::value
, const ::testing::internal::NeverThrown&, const std::exception
&>::type e) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(LOOPBACK_NAME, invalidAddr, 10547)"
" throws an exception of type " "SocketConfigError" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_2405
; } catch (...) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(LOOPBACK_NAME, invalidAddr, 10547)"
" throws an exception of type " "SocketConfigError" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2405; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(LOOPBACK_NAME, invalidAddr, 10547)"
" throws an exception of type " "SocketConfigError" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2405; } } else gtest_label_testthrow_2405
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2405, gtest_msg.value.c_str()) = ::testing::Message()
2404 SocketConfigErrorswitch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->openSocket(
LOOPBACK_NAME, invalidAddr, 10547); } else static_assert(true
, ""); } catch (SocketConfigError const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
SocketConfigError>::type>::type, std::exception>::value
, const ::testing::internal::NeverThrown&, const std::exception
&>::type e) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(LOOPBACK_NAME, invalidAddr, 10547)"
" throws an exception of type " "SocketConfigError" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_2405
; } catch (...) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(LOOPBACK_NAME, invalidAddr, 10547)"
" throws an exception of type " "SocketConfigError" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2405; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(LOOPBACK_NAME, invalidAddr, 10547)"
" throws an exception of type " "SocketConfigError" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2405; } } else gtest_label_testthrow_2405
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2405, gtest_msg.value.c_str()) = ::testing::Message()
2405 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->openSocket(
LOOPBACK_NAME, invalidAddr, 10547); } else static_assert(true
, ""); } catch (SocketConfigError const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
SocketConfigError>::type>::type, std::exception>::value
, const ::testing::internal::NeverThrown&, const std::exception
&>::type e) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(LOOPBACK_NAME, invalidAddr, 10547)"
" throws an exception of type " "SocketConfigError" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_2405
; } catch (...) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(LOOPBACK_NAME, invalidAddr, 10547)"
" throws an exception of type " "SocketConfigError" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2405; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(LOOPBACK_NAME, invalidAddr, 10547)"
" throws an exception of type " "SocketConfigError" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2405; } } else gtest_label_testthrow_2405
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2405, gtest_msg.value.c_str()) = ::testing::Message()
;
2406
2407 // Use non-existing interface name.
2408 EXPECT_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->openSocket(
"non_existing_interface", lo_addr, 10548); } else static_assert
(true, ""); } catch (BadValue const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
BadValue>::type>::type, std::exception>::value, const
::testing::internal::NeverThrown&, const std::exception&
>::type e) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(\"non_existing_interface\", lo_addr, 10548)"
" throws an exception of type " "BadValue" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_2411
; } catch (...) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(\"non_existing_interface\", lo_addr, 10548)"
" throws an exception of type " "BadValue" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2411; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(\"non_existing_interface\", lo_addr, 10548)"
" throws an exception of type " "BadValue" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2411; } } else gtest_label_testthrow_2411
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2411, gtest_msg.value.c_str()) = ::testing::Message()
2409 ifacemgr->openSocket("non_existing_interface", lo_addr, 10548),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->openSocket(
"non_existing_interface", lo_addr, 10548); } else static_assert
(true, ""); } catch (BadValue const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
BadValue>::type>::type, std::exception>::value, const
::testing::internal::NeverThrown&, const std::exception&
>::type e) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(\"non_existing_interface\", lo_addr, 10548)"
" throws an exception of type " "BadValue" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_2411
; } catch (...) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(\"non_existing_interface\", lo_addr, 10548)"
" throws an exception of type " "BadValue" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2411; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(\"non_existing_interface\", lo_addr, 10548)"
" throws an exception of type " "BadValue" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2411; } } else gtest_label_testthrow_2411
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2411, gtest_msg.value.c_str()) = ::testing::Message()
2410 BadValueswitch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->openSocket(
"non_existing_interface", lo_addr, 10548); } else static_assert
(true, ""); } catch (BadValue const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
BadValue>::type>::type, std::exception>::value, const
::testing::internal::NeverThrown&, const std::exception&
>::type e) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(\"non_existing_interface\", lo_addr, 10548)"
" throws an exception of type " "BadValue" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_2411
; } catch (...) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(\"non_existing_interface\", lo_addr, 10548)"
" throws an exception of type " "BadValue" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2411; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(\"non_existing_interface\", lo_addr, 10548)"
" throws an exception of type " "BadValue" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2411; } } else gtest_label_testthrow_2411
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2411, gtest_msg.value.c_str()) = ::testing::Message()
2411 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->openSocket(
"non_existing_interface", lo_addr, 10548); } else static_assert
(true, ""); } catch (BadValue const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
BadValue>::type>::type, std::exception>::value, const
::testing::internal::NeverThrown&, const std::exception&
>::type e) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(\"non_existing_interface\", lo_addr, 10548)"
" throws an exception of type " "BadValue" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_2411
; } catch (...) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(\"non_existing_interface\", lo_addr, 10548)"
" throws an exception of type " "BadValue" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2411; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->openSocket(\"non_existing_interface\", lo_addr, 10548)"
" throws an exception of type " "BadValue" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2411; } } else gtest_label_testthrow_2411
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2411, gtest_msg.value.c_str()) = ::testing::Message()
;
2412
2413 // Do not call closeSockets() because it is called by IfaceMgr's
2414 // virtual destructor.
2415}
2416
2417TEST_F(IfaceMgrTest, socketsFromIface)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("socketsFromIface") > 1, "test_name must not be empty"
); class IfaceMgrTest_socketsFromIface_Test : public IfaceMgrTest
{ public: IfaceMgrTest_socketsFromIface_Test() = default; ~IfaceMgrTest_socketsFromIface_Test
() override = default; IfaceMgrTest_socketsFromIface_Test (const
IfaceMgrTest_socketsFromIface_Test &) = delete; IfaceMgrTest_socketsFromIface_Test
& operator=( const IfaceMgrTest_socketsFromIface_Test &
) = delete; IfaceMgrTest_socketsFromIface_Test (IfaceMgrTest_socketsFromIface_Test
&&) noexcept = delete; IfaceMgrTest_socketsFromIface_Test
& operator=( IfaceMgrTest_socketsFromIface_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_socketsFromIface_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "socketsFromIface", nullptr, nullptr, ::testing::internal::
CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2417), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2417), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2417), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_socketsFromIface_Test
>); void IfaceMgrTest_socketsFromIface_Test::TestBody()
{
2418 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
2419
2420 // Open v6 socket on loopback interface and bind to port
2421 int socket1 = 0;
2422 EXPECT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT1
, 10);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2424; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2424
; } } else gtest_label_testnothrow_2424 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2424, ("Expected: " "socket1 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT1, 10);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2423 socket1 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT1, AF_INET6);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT1
, 10);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2424; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2424
; } } else gtest_label_testnothrow_2424 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2424, ("Expected: " "socket1 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT1, 10);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2424 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT1
, 10);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2424; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2424
; } } else gtest_label_testnothrow_2424 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2424, ("Expected: " "socket1 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT1, 10);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2425 // Socket descriptor must be non-negative integer
2426 EXPECT_GE(socket1, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket1", "0",
socket1, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2426, gtest_ar.failure_message()) = ::testing::Message()
;
2427 close(socket1);
2428
2429 // Open v4 socket on loopback interface and bind to different port
2430 int socket2 = 0;
2431 EXPECT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket2 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT2
, 2);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2433; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2433
; } } else gtest_label_testnothrow_2433 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2433, ("Expected: " "socket2 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT2, 2);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2432 socket2 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT2, AF_INET);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket2 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT2
, 2);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2433; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2433
; } } else gtest_label_testnothrow_2433 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2433, ("Expected: " "socket2 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT2, 2);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2433 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket2 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT2
, 2);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2433; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2433
; } } else gtest_label_testnothrow_2433 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2433, ("Expected: " "socket2 = ifacemgr->openSocketFromIface(LOOPBACK_NAME, PORT2, 2);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2434 // socket descriptor must be non-negative integer
2435 EXPECT_GE(socket2, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket2", "0",
socket2, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2435, gtest_ar.failure_message()) = ::testing::Message()
;
2436 close(socket2);
2437
2438 // Close sockets here because the following tests will want to
2439 // open sockets on the same ports.
2440 ifacemgr->closeSockets();
2441
2442 // Use invalid interface name.
2443 EXPECT_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->openSocketFromIface
("non_existing_interface", PORT1, 2); } else static_assert(true
, ""); } catch (BadValue const&) { gtest_caught_expected =
true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
BadValue>::type>::type, std::exception>::value, const
::testing::internal::NeverThrown&, const std::exception&
>::type e) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromIface(\"non_existing_interface\", PORT1, 2)"
" throws an exception of type " "BadValue" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_2446
; } catch (...) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromIface(\"non_existing_interface\", PORT1, 2)"
" throws an exception of type " "BadValue" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2446; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromIface(\"non_existing_interface\", PORT1, 2)"
" throws an exception of type " "BadValue" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2446; } } else gtest_label_testthrow_2446
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2446, gtest_msg.value.c_str()) = ::testing::Message()
2444 ifacemgr->openSocketFromIface("non_existing_interface", PORT1, AF_INET),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->openSocketFromIface
("non_existing_interface", PORT1, 2); } else static_assert(true
, ""); } catch (BadValue const&) { gtest_caught_expected =
true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
BadValue>::type>::type, std::exception>::value, const
::testing::internal::NeverThrown&, const std::exception&
>::type e) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromIface(\"non_existing_interface\", PORT1, 2)"
" throws an exception of type " "BadValue" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_2446
; } catch (...) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromIface(\"non_existing_interface\", PORT1, 2)"
" throws an exception of type " "BadValue" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2446; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromIface(\"non_existing_interface\", PORT1, 2)"
" throws an exception of type " "BadValue" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2446; } } else gtest_label_testthrow_2446
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2446, gtest_msg.value.c_str()) = ::testing::Message()
2445 BadValueswitch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->openSocketFromIface
("non_existing_interface", PORT1, 2); } else static_assert(true
, ""); } catch (BadValue const&) { gtest_caught_expected =
true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
BadValue>::type>::type, std::exception>::value, const
::testing::internal::NeverThrown&, const std::exception&
>::type e) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromIface(\"non_existing_interface\", PORT1, 2)"
" throws an exception of type " "BadValue" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_2446
; } catch (...) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromIface(\"non_existing_interface\", PORT1, 2)"
" throws an exception of type " "BadValue" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2446; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromIface(\"non_existing_interface\", PORT1, 2)"
" throws an exception of type " "BadValue" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2446; } } else gtest_label_testthrow_2446
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2446, gtest_msg.value.c_str()) = ::testing::Message()
2446 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->openSocketFromIface
("non_existing_interface", PORT1, 2); } else static_assert(true
, ""); } catch (BadValue const&) { gtest_caught_expected =
true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
BadValue>::type>::type, std::exception>::value, const
::testing::internal::NeverThrown&, const std::exception&
>::type e) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromIface(\"non_existing_interface\", PORT1, 2)"
" throws an exception of type " "BadValue" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_2446
; } catch (...) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromIface(\"non_existing_interface\", PORT1, 2)"
" throws an exception of type " "BadValue" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2446; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromIface(\"non_existing_interface\", PORT1, 2)"
" throws an exception of type " "BadValue" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2446; } } else gtest_label_testthrow_2446
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2446, gtest_msg.value.c_str()) = ::testing::Message()
;
2447
2448 // Do not call closeSockets() because it is called by IfaceMgr's
2449 // virtual destructor.
2450}
2451
2452
2453TEST_F(IfaceMgrTest, socketsFromAddress)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("socketsFromAddress") > 1, "test_name must not be empty"
); class IfaceMgrTest_socketsFromAddress_Test : public IfaceMgrTest
{ public: IfaceMgrTest_socketsFromAddress_Test() = default; ~
IfaceMgrTest_socketsFromAddress_Test() override = default; IfaceMgrTest_socketsFromAddress_Test
(const IfaceMgrTest_socketsFromAddress_Test &) = delete;
IfaceMgrTest_socketsFromAddress_Test & operator=( const IfaceMgrTest_socketsFromAddress_Test
&) = delete; IfaceMgrTest_socketsFromAddress_Test (IfaceMgrTest_socketsFromAddress_Test
&&) noexcept = delete; IfaceMgrTest_socketsFromAddress_Test
& operator=( IfaceMgrTest_socketsFromAddress_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_socketsFromAddress_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "socketsFromAddress", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2453), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2453), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2453), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_socketsFromAddress_Test
>); void IfaceMgrTest_socketsFromAddress_Test::TestBody()
{
2454 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
2455
2456 // Open v6 socket on loopback interface and bind to port
2457 int socket1 = 0;
2458 IOAddress lo_addr6("::1");
2459 EXPECT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocketFromAddress(lo_addr6, PORT1
);; } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2461; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2461
; } } else gtest_label_testnothrow_2461 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2461, ("Expected: " "socket1 = ifacemgr->openSocketFromAddress(lo_addr6, PORT1);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2460 socket1 = ifacemgr->openSocketFromAddress(lo_addr6, PORT1);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocketFromAddress(lo_addr6, PORT1
);; } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2461; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2461
; } } else gtest_label_testnothrow_2461 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2461, ("Expected: " "socket1 = ifacemgr->openSocketFromAddress(lo_addr6, PORT1);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2461 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocketFromAddress(lo_addr6, PORT1
);; } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2461; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2461
; } } else gtest_label_testnothrow_2461 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2461, ("Expected: " "socket1 = ifacemgr->openSocketFromAddress(lo_addr6, PORT1);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2462 // socket descriptor must be non-negative integer
2463 EXPECT_GE(socket1, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket1", "0",
socket1, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2463, gtest_ar.failure_message()) = ::testing::Message()
;
2464
2465 // Open v4 socket on loopback interface and bind to different port
2466 int socket2 = 0;
2467 IOAddress lo_addr("127.0.0.1");
2468 EXPECT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket2 = ifacemgr->openSocketFromAddress(lo_addr, PORT2)
;; } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2470; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2470
; } } else gtest_label_testnothrow_2470 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2470, ("Expected: " "socket2 = ifacemgr->openSocketFromAddress(lo_addr, PORT2);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2469 socket2 = ifacemgr->openSocketFromAddress(lo_addr, PORT2);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket2 = ifacemgr->openSocketFromAddress(lo_addr, PORT2)
;; } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2470; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2470
; } } else gtest_label_testnothrow_2470 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2470, ("Expected: " "socket2 = ifacemgr->openSocketFromAddress(lo_addr, PORT2);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2470 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket2 = ifacemgr->openSocketFromAddress(lo_addr, PORT2)
;; } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2470; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2470
; } } else gtest_label_testnothrow_2470 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2470, ("Expected: " "socket2 = ifacemgr->openSocketFromAddress(lo_addr, PORT2);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2471 // socket descriptor must be positive integer
2472 EXPECT_GE(socket2, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket2", "0",
socket2, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2472, gtest_ar.failure_message()) = ::testing::Message()
;
2473
2474 // Close sockets here because the following tests will want to
2475 // open sockets on the same ports.
2476 ifacemgr->closeSockets();
2477
2478 // Use non-existing address.
2479 IOAddress invalidAddr("1.2.3.4");
2480 EXPECT_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->openSocketFromAddress
(invalidAddr, PORT1); } else static_assert(true, ""); } catch
(BadValue const&) { gtest_caught_expected = true; } catch
(typename std::conditional< std::is_same<typename std::
remove_cv<typename std::remove_reference< BadValue>::
type>::type, std::exception>::value, const ::testing::internal
::NeverThrown&, const std::exception&>::type e) { gtest_msg
.value = "Expected: " "ifacemgr->openSocketFromAddress(invalidAddr, PORT1)"
" throws an exception of type " "BadValue" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_2482
; } catch (...) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromAddress(invalidAddr, PORT1)"
" throws an exception of type " "BadValue" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2482; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromAddress(invalidAddr, PORT1)"
" throws an exception of type " "BadValue" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2482; } } else gtest_label_testthrow_2482
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2482, gtest_msg.value.c_str()) = ::testing::Message()
2481 ifacemgr->openSocketFromAddress(invalidAddr, PORT1), BadValueswitch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->openSocketFromAddress
(invalidAddr, PORT1); } else static_assert(true, ""); } catch
(BadValue const&) { gtest_caught_expected = true; } catch
(typename std::conditional< std::is_same<typename std::
remove_cv<typename std::remove_reference< BadValue>::
type>::type, std::exception>::value, const ::testing::internal
::NeverThrown&, const std::exception&>::type e) { gtest_msg
.value = "Expected: " "ifacemgr->openSocketFromAddress(invalidAddr, PORT1)"
" throws an exception of type " "BadValue" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_2482
; } catch (...) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromAddress(invalidAddr, PORT1)"
" throws an exception of type " "BadValue" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2482; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromAddress(invalidAddr, PORT1)"
" throws an exception of type " "BadValue" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2482; } } else gtest_label_testthrow_2482
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2482, gtest_msg.value.c_str()) = ::testing::Message()
2482 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->openSocketFromAddress
(invalidAddr, PORT1); } else static_assert(true, ""); } catch
(BadValue const&) { gtest_caught_expected = true; } catch
(typename std::conditional< std::is_same<typename std::
remove_cv<typename std::remove_reference< BadValue>::
type>::type, std::exception>::value, const ::testing::internal
::NeverThrown&, const std::exception&>::type e) { gtest_msg
.value = "Expected: " "ifacemgr->openSocketFromAddress(invalidAddr, PORT1)"
" throws an exception of type " "BadValue" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_2482
; } catch (...) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromAddress(invalidAddr, PORT1)"
" throws an exception of type " "BadValue" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2482; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->openSocketFromAddress(invalidAddr, PORT1)"
" throws an exception of type " "BadValue" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2482; } } else gtest_label_testthrow_2482
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2482, gtest_msg.value.c_str()) = ::testing::Message()
;
2483
2484 // Do not call closeSockets() because it is called by IfaceMgr's
2485 // virtual destructor.
2486}
2487
2488TEST_F(IfaceMgrTest, socketsFromRemoteAddress)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("socketsFromRemoteAddress") > 1, "test_name must not be empty"
); class IfaceMgrTest_socketsFromRemoteAddress_Test : public IfaceMgrTest
{ public: IfaceMgrTest_socketsFromRemoteAddress_Test() = default
; ~IfaceMgrTest_socketsFromRemoteAddress_Test() override = default
; IfaceMgrTest_socketsFromRemoteAddress_Test (const IfaceMgrTest_socketsFromRemoteAddress_Test
&) = delete; IfaceMgrTest_socketsFromRemoteAddress_Test &
operator=( const IfaceMgrTest_socketsFromRemoteAddress_Test &
) = delete; IfaceMgrTest_socketsFromRemoteAddress_Test (IfaceMgrTest_socketsFromRemoteAddress_Test
&&) noexcept = delete; IfaceMgrTest_socketsFromRemoteAddress_Test
& operator=( IfaceMgrTest_socketsFromRemoteAddress_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_socketsFromRemoteAddress_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "socketsFromRemoteAddress", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2488), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2488), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2488), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_socketsFromRemoteAddress_Test
>); void IfaceMgrTest_socketsFromRemoteAddress_Test::TestBody
()
{
2489 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
2490
2491 // Open v6 socket to connect to remote address.
2492 // Loopback address is the only one that we know
2493 // so let's treat it as remote address.
2494 int socket1 = 0;
2495 IOAddress lo_addr6("::1");
2496 EXPECT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocketFromRemoteAddress(lo_addr6,
PORT1);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2498; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2498
; } } else gtest_label_testnothrow_2498 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2498, ("Expected: " "socket1 = ifacemgr->openSocketFromRemoteAddress(lo_addr6, PORT1);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2497 socket1 = ifacemgr->openSocketFromRemoteAddress(lo_addr6, PORT1);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocketFromRemoteAddress(lo_addr6,
PORT1);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2498; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2498
; } } else gtest_label_testnothrow_2498 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2498, ("Expected: " "socket1 = ifacemgr->openSocketFromRemoteAddress(lo_addr6, PORT1);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2498 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocketFromRemoteAddress(lo_addr6,
PORT1);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2498; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2498
; } } else gtest_label_testnothrow_2498 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2498, ("Expected: " "socket1 = ifacemgr->openSocketFromRemoteAddress(lo_addr6, PORT1);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2499 EXPECT_GE(socket1, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket1", "0",
socket1, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2499, gtest_ar.failure_message()) = ::testing::Message()
;
2500
2501 // Open v4 socket to connect to remote address.
2502 int socket2 = 0;
2503 IOAddress lo_addr("127.0.0.1");
2504 EXPECT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket2 = ifacemgr->openSocketFromRemoteAddress(lo_addr, PORT2
);; } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2506; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2506
; } } else gtest_label_testnothrow_2506 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2506, ("Expected: " "socket2 = ifacemgr->openSocketFromRemoteAddress(lo_addr, PORT2);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2505 socket2 = ifacemgr->openSocketFromRemoteAddress(lo_addr, PORT2);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket2 = ifacemgr->openSocketFromRemoteAddress(lo_addr, PORT2
);; } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2506; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2506
; } } else gtest_label_testnothrow_2506 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2506, ("Expected: " "socket2 = ifacemgr->openSocketFromRemoteAddress(lo_addr, PORT2);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2506 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket2 = ifacemgr->openSocketFromRemoteAddress(lo_addr, PORT2
);; } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2506; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2506
; } } else gtest_label_testnothrow_2506 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2506, ("Expected: " "socket2 = ifacemgr->openSocketFromRemoteAddress(lo_addr, PORT2);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2507 EXPECT_GE(socket2, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket2", "0",
socket2, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2507, gtest_ar.failure_message()) = ::testing::Message()
;
2508
2509 // Close sockets here because the following tests will want to
2510 // open sockets on the same ports.
2511 ifacemgr->closeSockets();
2512
2513 // There used to be a check here that verified the ability to open
2514 // suitable socket for sending broadcast request. However,
2515 // there is no guarantee for such test to work on all systems
2516 // because some systems may have no broadcast capable interfaces at all.
2517 // Thus, this check has been removed.
2518
2519 // Do not call closeSockets() because it is called by IfaceMgr's
2520 // virtual destructor.
2521}
2522
2523// TODO: disabled due to other naming on various systems
2524// (lo in Linux, lo0 in BSD systems)
2525TEST_F(IfaceMgrTest, DISABLED_sockets6Mcast)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("DISABLED_sockets6Mcast") > 1, "test_name must not be empty"
); class IfaceMgrTest_DISABLED_sockets6Mcast_Test : public IfaceMgrTest
{ public: IfaceMgrTest_DISABLED_sockets6Mcast_Test() = default
; ~IfaceMgrTest_DISABLED_sockets6Mcast_Test() override = default
; IfaceMgrTest_DISABLED_sockets6Mcast_Test (const IfaceMgrTest_DISABLED_sockets6Mcast_Test
&) = delete; IfaceMgrTest_DISABLED_sockets6Mcast_Test &
operator=( const IfaceMgrTest_DISABLED_sockets6Mcast_Test &
) = delete; IfaceMgrTest_DISABLED_sockets6Mcast_Test (IfaceMgrTest_DISABLED_sockets6Mcast_Test
&&) noexcept = delete; IfaceMgrTest_DISABLED_sockets6Mcast_Test
& operator=( IfaceMgrTest_DISABLED_sockets6Mcast_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_DISABLED_sockets6Mcast_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "DISABLED_sockets6Mcast", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2525), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2525), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2525), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_DISABLED_sockets6Mcast_Test
>); void IfaceMgrTest_DISABLED_sockets6Mcast_Test::TestBody
()
{
2526 // testing socket operation in a portable way is tricky
2527 // without interface detection implemented
2528
2529 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
2530
2531 IOAddress lo_addr("::1");
2532 IOAddress mcastAddrL("ff02::1:2");
2533 IOAddress mcastAddrS("ff05::1:3");
2534
2535 // bind multicast socket to port 10547
2536 int socket1 = ifacemgr->openSocket(LOOPBACK_NAME, mcastAddrL, 10547);
2537 EXPECT_GE(socket1, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket1", "0",
socket1, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2537, gtest_ar.failure_message()) = ::testing::Message()
; // socket > 0
2538 int socket2 = ifacemgr->openSocket(LOOPBACK_NAME, mcastAddrS, 10547);
2539 EXPECT_GE(socket2, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket2", "0",
socket2, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2539, gtest_ar.failure_message()) = ::testing::Message()
; // socket > 0
2540
2541 // expect success. This address/port is already bound, but
2542 // we are using SO_REUSEADDR, so we can bind it twice
2543 int socket3 = ifacemgr->openSocket(LOOPBACK_NAME, mcastAddrL, 10547);
2544 EXPECT_GE(socket3, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket3", "0",
socket3, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2544, gtest_ar.failure_message()) = ::testing::Message()
;
2545 int socket4 = ifacemgr->openSocket(LOOPBACK_NAME, mcastAddrS, 10547);
2546 EXPECT_GE(socket4, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket4", "0",
socket4, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2546, gtest_ar.failure_message()) = ::testing::Message()
;
2547
2548 // there's no good way to test negative case here.
2549 // we would need non-multicast interface. We will be able
2550 // to iterate thru available interfaces and check if there
2551 // are interfaces without multicast-capable flag.
2552
2553 close(socket1);
2554 close(socket2);
2555 close(socket3);
2556 close(socket4);
2557}
2558
2559// Verifies that basic DHCPv6 packet send and receive operates
2560// in either direct or indirect mode.
2561// No poll version as it depends on select() behavior.
2562TEST_F(IfaceMgrTest, sendReceive6Select)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("sendReceive6Select") > 1, "test_name must not be empty"
); class IfaceMgrTest_sendReceive6Select_Test : public IfaceMgrTest
{ public: IfaceMgrTest_sendReceive6Select_Test() = default; ~
IfaceMgrTest_sendReceive6Select_Test() override = default; IfaceMgrTest_sendReceive6Select_Test
(const IfaceMgrTest_sendReceive6Select_Test &) = delete;
IfaceMgrTest_sendReceive6Select_Test & operator=( const IfaceMgrTest_sendReceive6Select_Test
&) = delete; IfaceMgrTest_sendReceive6Select_Test (IfaceMgrTest_sendReceive6Select_Test
&&) noexcept = delete; IfaceMgrTest_sendReceive6Select_Test
& operator=( IfaceMgrTest_sendReceive6Select_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_sendReceive6Select_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "sendReceive6Select", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2562), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2562), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2562), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_sendReceive6Select_Test
>); void IfaceMgrTest_sendReceive6Select_Test::TestBody()
{
2563 kea_event_handler_type_.setValue("select");
2564 data::ElementPtr queue_control;
2565
2566 // Given an empty pointer, queueing should be disabled.
2567 // This should do direct reception.
2568 sendReceive6Test(queue_control, false);
2569
2570 // Now let's populate queue control.
2571 queue_control = makeQueueConfig(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6, 500, false);
2572 // With queueing disabled, we should use direct reception.
2573 sendReceive6Test(queue_control, false);
2574
2575 // Queuing enabled, indirection reception should work.
2576 queue_control = makeQueueConfig(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6, 500, true);
2577 sendReceive6Test(queue_control, true);
2578}
2579
2580// Verifies that basic DHCPv4 packet send and receive operates
2581// in either direct or indirect mode.
2582// No poll version as it depends on select() behavior.
2583TEST_F(IfaceMgrTest, sendReceive4Select)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("sendReceive4Select") > 1, "test_name must not be empty"
); class IfaceMgrTest_sendReceive4Select_Test : public IfaceMgrTest
{ public: IfaceMgrTest_sendReceive4Select_Test() = default; ~
IfaceMgrTest_sendReceive4Select_Test() override = default; IfaceMgrTest_sendReceive4Select_Test
(const IfaceMgrTest_sendReceive4Select_Test &) = delete;
IfaceMgrTest_sendReceive4Select_Test & operator=( const IfaceMgrTest_sendReceive4Select_Test
&) = delete; IfaceMgrTest_sendReceive4Select_Test (IfaceMgrTest_sendReceive4Select_Test
&&) noexcept = delete; IfaceMgrTest_sendReceive4Select_Test
& operator=( IfaceMgrTest_sendReceive4Select_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_sendReceive4Select_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "sendReceive4Select", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2583), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2583), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2583), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_sendReceive4Select_Test
>); void IfaceMgrTest_sendReceive4Select_Test::TestBody()
{
2584 kea_event_handler_type_.setValue("select");
2585 data::ElementPtr queue_control;
2586
2587 // Given an empty pointer, queueing should be disabled.
2588 // This should do direct reception.
2589 sendReceive4Test(queue_control, false);
2590
2591 // Now let's populate queue control.
2592 queue_control = makeQueueConfig(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4, 500, false);
2593 // With queueing disabled, we should use direct reception.
2594 sendReceive4Test(queue_control, false);
2595
2596 // Queuing enabled, indirection reception should work.
2597 queue_control = makeQueueConfig(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4, 500, true);
2598 sendReceive4Test(queue_control, true);
2599}
2600
2601// Verifies that it is possible to set custom packet filter object
2602// to handle sockets opening and send/receive operation.
2603TEST_F(IfaceMgrTest, setPacketFilter)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("setPacketFilter") > 1, "test_name must not be empty"
); class IfaceMgrTest_setPacketFilter_Test : public IfaceMgrTest
{ public: IfaceMgrTest_setPacketFilter_Test() = default; ~IfaceMgrTest_setPacketFilter_Test
() override = default; IfaceMgrTest_setPacketFilter_Test (const
IfaceMgrTest_setPacketFilter_Test &) = delete; IfaceMgrTest_setPacketFilter_Test
& operator=( const IfaceMgrTest_setPacketFilter_Test &
) = delete; IfaceMgrTest_setPacketFilter_Test (IfaceMgrTest_setPacketFilter_Test
&&) noexcept = delete; IfaceMgrTest_setPacketFilter_Test
& operator=( IfaceMgrTest_setPacketFilter_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_setPacketFilter_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "setPacketFilter", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2603), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2603), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2603), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_setPacketFilter_Test
>); void IfaceMgrTest_setPacketFilter_Test::TestBody()
{
2604
2605 // Create an instance of IfaceMgr.
2606 boost::scoped_ptr<NakedIfaceMgr> iface_mgr(new NakedIfaceMgr());
2607 ASSERT_TRUE(iface_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2607, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2608
2609 // Try to set NULL packet filter object and make sure it is rejected.
2610 boost::shared_ptr<TestPktFilter> custom_packet_filter;
2611 EXPECT_THROW(iface_mgr->setPacketFilter(custom_packet_filter),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { iface_mgr->setPacketFilter
(custom_packet_filter); } else static_assert(true, ""); } catch
(isc::dhcp::InvalidPacketFilter const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
isc::dhcp::InvalidPacketFilter>::type>::type, std::exception
>::value, const ::testing::internal::NeverThrown&, const
std::exception&>::type e) { gtest_msg.value = "Expected: "
"iface_mgr->setPacketFilter(custom_packet_filter)" " throws an exception of type "
"isc::dhcp::InvalidPacketFilter" ".\n Actual: it throws "; gtest_msg
.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg
.value += " with description \""; gtest_msg.value += e.what()
; gtest_msg.value += "\"."; goto gtest_label_testthrow_2612; }
catch (...) { gtest_msg.value = "Expected: " "iface_mgr->setPacketFilter(custom_packet_filter)"
" throws an exception of type " "isc::dhcp::InvalidPacketFilter"
".\n Actual: it throws a different type."; goto gtest_label_testthrow_2612
; } if (!gtest_caught_expected) { gtest_msg.value = "Expected: "
"iface_mgr->setPacketFilter(custom_packet_filter)" " throws an exception of type "
"isc::dhcp::InvalidPacketFilter" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2612; } } else gtest_label_testthrow_2612
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2612, gtest_msg.value.c_str()) = ::testing::Message()
2612 isc::dhcp::InvalidPacketFilter)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { iface_mgr->setPacketFilter
(custom_packet_filter); } else static_assert(true, ""); } catch
(isc::dhcp::InvalidPacketFilter const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
isc::dhcp::InvalidPacketFilter>::type>::type, std::exception
>::value, const ::testing::internal::NeverThrown&, const
std::exception&>::type e) { gtest_msg.value = "Expected: "
"iface_mgr->setPacketFilter(custom_packet_filter)" " throws an exception of type "
"isc::dhcp::InvalidPacketFilter" ".\n Actual: it throws "; gtest_msg
.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg
.value += " with description \""; gtest_msg.value += e.what()
; gtest_msg.value += "\"."; goto gtest_label_testthrow_2612; }
catch (...) { gtest_msg.value = "Expected: " "iface_mgr->setPacketFilter(custom_packet_filter)"
" throws an exception of type " "isc::dhcp::InvalidPacketFilter"
".\n Actual: it throws a different type."; goto gtest_label_testthrow_2612
; } if (!gtest_caught_expected) { gtest_msg.value = "Expected: "
"iface_mgr->setPacketFilter(custom_packet_filter)" " throws an exception of type "
"isc::dhcp::InvalidPacketFilter" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2612; } } else gtest_label_testthrow_2612
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2612, gtest_msg.value.c_str()) = ::testing::Message()
;
2613
2614 // Create valid object and check if it can be set.
2615 custom_packet_filter.reset(new TestPktFilter());
2616 ASSERT_TRUE(custom_packet_filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(custom_packet_filter)
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2616, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "custom_packet_filter", "false", "true") .c_str()) = ::testing
::Message()
;
2617 ASSERT_NO_THROW(iface_mgr->setPacketFilter(custom_packet_filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface_mgr->setPacketFilter(custom_packet_filter); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2617; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2617; } } else gtest_label_testnothrow_2617
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2617, ("Expected: " "iface_mgr->setPacketFilter(custom_packet_filter)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2618
2619 // Try to open socket using IfaceMgr. It should call the openSocket() function
2620 // on the packet filter object we have set.
2621 IOAddress lo_addr("127.0.0.1");
2622 int socket1 = 0;
2623 EXPECT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT
+ 10000);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2626; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2626
; } } else gtest_label_testnothrow_2626 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2626, ("Expected: " "socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2624 socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr,switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT
+ 10000);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2626; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2626
; } } else gtest_label_testnothrow_2626 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2626, ("Expected: " "socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2625 DHCP4_SERVER_PORT + 10000);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT
+ 10000);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2626; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2626
; } } else gtest_label_testnothrow_2626 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2626, ("Expected: " "socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2626 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT
+ 10000);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2626; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2626
; } } else gtest_label_testnothrow_2626 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2626, ("Expected: " "socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2627
2628 // Check that openSocket function was called.
2629 EXPECT_TRUE(custom_packet_filter->open_socket_called_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(custom_packet_filter->
open_socket_called_)) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2629, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "custom_packet_filter->open_socket_called_", "false", "true"
) .c_str()) = ::testing::Message()
;
2630 // This function always returns fake socket descriptor equal to 255.
2631 EXPECT_EQ(255, socket1)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("255", "socket1"
, 255, socket1))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2631, gtest_ar.failure_message()) = ::testing::Message()
;
2632
2633 // Replacing current packet filter object while there are IPv4
2634 // sockets open is not allowed!
2635 EXPECT_THROW(iface_mgr->setPacketFilter(custom_packet_filter),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { iface_mgr->setPacketFilter
(custom_packet_filter); } else static_assert(true, ""); } catch
(PacketFilterChangeDenied const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
PacketFilterChangeDenied>::type>::type, std::exception
>::value, const ::testing::internal::NeverThrown&, const
std::exception&>::type e) { gtest_msg.value = "Expected: "
"iface_mgr->setPacketFilter(custom_packet_filter)" " throws an exception of type "
"PacketFilterChangeDenied" ".\n Actual: it throws "; gtest_msg
.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg
.value += " with description \""; gtest_msg.value += e.what()
; gtest_msg.value += "\"."; goto gtest_label_testthrow_2636; }
catch (...) { gtest_msg.value = "Expected: " "iface_mgr->setPacketFilter(custom_packet_filter)"
" throws an exception of type " "PacketFilterChangeDenied" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2636; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "iface_mgr->setPacketFilter(custom_packet_filter)"
" throws an exception of type " "PacketFilterChangeDenied" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2636; } } else gtest_label_testthrow_2636
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2636, gtest_msg.value.c_str()) = ::testing::Message()
2636 PacketFilterChangeDenied)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { iface_mgr->setPacketFilter
(custom_packet_filter); } else static_assert(true, ""); } catch
(PacketFilterChangeDenied const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
PacketFilterChangeDenied>::type>::type, std::exception
>::value, const ::testing::internal::NeverThrown&, const
std::exception&>::type e) { gtest_msg.value = "Expected: "
"iface_mgr->setPacketFilter(custom_packet_filter)" " throws an exception of type "
"PacketFilterChangeDenied" ".\n Actual: it throws "; gtest_msg
.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg
.value += " with description \""; gtest_msg.value += e.what()
; gtest_msg.value += "\"."; goto gtest_label_testthrow_2636; }
catch (...) { gtest_msg.value = "Expected: " "iface_mgr->setPacketFilter(custom_packet_filter)"
" throws an exception of type " "PacketFilterChangeDenied" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2636; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "iface_mgr->setPacketFilter(custom_packet_filter)"
" throws an exception of type " "PacketFilterChangeDenied" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2636; } } else gtest_label_testthrow_2636
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2636, gtest_msg.value.c_str()) = ::testing::Message()
;
2637
2638 // So, let's close the open sockets and retry. Now it should succeed.
2639 iface_mgr->closeSockets();
2640 EXPECT_NO_THROW(iface_mgr->setPacketFilter(custom_packet_filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface_mgr->setPacketFilter(custom_packet_filter); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2640; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2640; } } else gtest_label_testnothrow_2640
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2640, ("Expected: " "iface_mgr->setPacketFilter(custom_packet_filter)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2641}
2642
2643// This test checks that the default packet filter for DHCPv6 can be replaced
2644// with the custom one.
2645TEST_F(IfaceMgrTest, setPacketFilter6)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("setPacketFilter6") > 1, "test_name must not be empty"
); class IfaceMgrTest_setPacketFilter6_Test : public IfaceMgrTest
{ public: IfaceMgrTest_setPacketFilter6_Test() = default; ~IfaceMgrTest_setPacketFilter6_Test
() override = default; IfaceMgrTest_setPacketFilter6_Test (const
IfaceMgrTest_setPacketFilter6_Test &) = delete; IfaceMgrTest_setPacketFilter6_Test
& operator=( const IfaceMgrTest_setPacketFilter6_Test &
) = delete; IfaceMgrTest_setPacketFilter6_Test (IfaceMgrTest_setPacketFilter6_Test
&&) noexcept = delete; IfaceMgrTest_setPacketFilter6_Test
& operator=( IfaceMgrTest_setPacketFilter6_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_setPacketFilter6_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "setPacketFilter6", nullptr, nullptr, ::testing::internal::
CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2645), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2645), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2645), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_setPacketFilter6_Test
>); void IfaceMgrTest_setPacketFilter6_Test::TestBody()
{
2646 // Create an instance of IfaceMgr.
2647 boost::scoped_ptr<NakedIfaceMgr> iface_mgr(new NakedIfaceMgr());
2648 ASSERT_TRUE(iface_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2648, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2649
2650 // Try to set NULL packet filter object and make sure it is rejected.
2651 boost::shared_ptr<PktFilter6Stub> custom_packet_filter;
2652 EXPECT_THROW(iface_mgr->setPacketFilter(custom_packet_filter),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { iface_mgr->setPacketFilter
(custom_packet_filter); } else static_assert(true, ""); } catch
(isc::dhcp::InvalidPacketFilter const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
isc::dhcp::InvalidPacketFilter>::type>::type, std::exception
>::value, const ::testing::internal::NeverThrown&, const
std::exception&>::type e) { gtest_msg.value = "Expected: "
"iface_mgr->setPacketFilter(custom_packet_filter)" " throws an exception of type "
"isc::dhcp::InvalidPacketFilter" ".\n Actual: it throws "; gtest_msg
.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg
.value += " with description \""; gtest_msg.value += e.what()
; gtest_msg.value += "\"."; goto gtest_label_testthrow_2653; }
catch (...) { gtest_msg.value = "Expected: " "iface_mgr->setPacketFilter(custom_packet_filter)"
" throws an exception of type " "isc::dhcp::InvalidPacketFilter"
".\n Actual: it throws a different type."; goto gtest_label_testthrow_2653
; } if (!gtest_caught_expected) { gtest_msg.value = "Expected: "
"iface_mgr->setPacketFilter(custom_packet_filter)" " throws an exception of type "
"isc::dhcp::InvalidPacketFilter" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2653; } } else gtest_label_testthrow_2653
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2653, gtest_msg.value.c_str()) = ::testing::Message()
2653 isc::dhcp::InvalidPacketFilter)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { iface_mgr->setPacketFilter
(custom_packet_filter); } else static_assert(true, ""); } catch
(isc::dhcp::InvalidPacketFilter const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
isc::dhcp::InvalidPacketFilter>::type>::type, std::exception
>::value, const ::testing::internal::NeverThrown&, const
std::exception&>::type e) { gtest_msg.value = "Expected: "
"iface_mgr->setPacketFilter(custom_packet_filter)" " throws an exception of type "
"isc::dhcp::InvalidPacketFilter" ".\n Actual: it throws "; gtest_msg
.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg
.value += " with description \""; gtest_msg.value += e.what()
; gtest_msg.value += "\"."; goto gtest_label_testthrow_2653; }
catch (...) { gtest_msg.value = "Expected: " "iface_mgr->setPacketFilter(custom_packet_filter)"
" throws an exception of type " "isc::dhcp::InvalidPacketFilter"
".\n Actual: it throws a different type."; goto gtest_label_testthrow_2653
; } if (!gtest_caught_expected) { gtest_msg.value = "Expected: "
"iface_mgr->setPacketFilter(custom_packet_filter)" " throws an exception of type "
"isc::dhcp::InvalidPacketFilter" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2653; } } else gtest_label_testthrow_2653
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2653, gtest_msg.value.c_str()) = ::testing::Message()
;
2654
2655 // Create valid object and check if it can be set.
2656 custom_packet_filter.reset(new PktFilter6Stub());
2657 ASSERT_TRUE(custom_packet_filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(custom_packet_filter)
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2657, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "custom_packet_filter", "false", "true") .c_str()) = ::testing
::Message()
;
2658 ASSERT_NO_THROW(iface_mgr->setPacketFilter(custom_packet_filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface_mgr->setPacketFilter(custom_packet_filter); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2658; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2658; } } else gtest_label_testnothrow_2658
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2658, ("Expected: " "iface_mgr->setPacketFilter(custom_packet_filter)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2659
2660 // Try to open socket using IfaceMgr. It should call the openSocket()
2661 // function on the packet filter object we have set.
2662 IOAddress lo_addr("::1");
2663 int socket1 = 0;
2664 EXPECT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP6_SERVER_PORT
+ 10000);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2667; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2667
; } } else gtest_label_testnothrow_2667 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2667, ("Expected: " "socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP6_SERVER_PORT + 10000);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2665 socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr,switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP6_SERVER_PORT
+ 10000);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2667; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2667
; } } else gtest_label_testnothrow_2667 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2667, ("Expected: " "socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP6_SERVER_PORT + 10000);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2666 DHCP6_SERVER_PORT + 10000);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP6_SERVER_PORT
+ 10000);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2667; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2667
; } } else gtest_label_testnothrow_2667 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2667, ("Expected: " "socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP6_SERVER_PORT + 10000);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2667 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP6_SERVER_PORT
+ 10000);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2667; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2667
; } } else gtest_label_testnothrow_2667 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2667, ("Expected: " "socket1 = iface_mgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP6_SERVER_PORT + 10000);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2668 // Check that openSocket function has been actually called on the packet
2669 // filter object.
2670 EXPECT_EQ(1, custom_packet_filter->open_socket_count_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "custom_packet_filter->open_socket_count_"
, 1, custom_packet_filter->open_socket_count_))) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2670, gtest_ar
.failure_message()) = ::testing::Message()
;
2671 // Also check that the returned socket descriptor has an expected value.
2672 EXPECT_EQ(0, socket1)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "socket1"
, 0, socket1))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2672, gtest_ar.failure_message()) = ::testing::Message()
;
2673
2674 // Replacing current packet filter object, while there are sockets open,
2675 // is not allowed!
2676 EXPECT_THROW(iface_mgr->setPacketFilter(custom_packet_filter),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { iface_mgr->setPacketFilter
(custom_packet_filter); } else static_assert(true, ""); } catch
(PacketFilterChangeDenied const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
PacketFilterChangeDenied>::type>::type, std::exception
>::value, const ::testing::internal::NeverThrown&, const
std::exception&>::type e) { gtest_msg.value = "Expected: "
"iface_mgr->setPacketFilter(custom_packet_filter)" " throws an exception of type "
"PacketFilterChangeDenied" ".\n Actual: it throws "; gtest_msg
.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg
.value += " with description \""; gtest_msg.value += e.what()
; gtest_msg.value += "\"."; goto gtest_label_testthrow_2677; }
catch (...) { gtest_msg.value = "Expected: " "iface_mgr->setPacketFilter(custom_packet_filter)"
" throws an exception of type " "PacketFilterChangeDenied" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2677; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "iface_mgr->setPacketFilter(custom_packet_filter)"
" throws an exception of type " "PacketFilterChangeDenied" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2677; } } else gtest_label_testthrow_2677
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2677, gtest_msg.value.c_str()) = ::testing::Message()
2677 PacketFilterChangeDenied)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { iface_mgr->setPacketFilter
(custom_packet_filter); } else static_assert(true, ""); } catch
(PacketFilterChangeDenied const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
PacketFilterChangeDenied>::type>::type, std::exception
>::value, const ::testing::internal::NeverThrown&, const
std::exception&>::type e) { gtest_msg.value = "Expected: "
"iface_mgr->setPacketFilter(custom_packet_filter)" " throws an exception of type "
"PacketFilterChangeDenied" ".\n Actual: it throws "; gtest_msg
.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg
.value += " with description \""; gtest_msg.value += e.what()
; gtest_msg.value += "\"."; goto gtest_label_testthrow_2677; }
catch (...) { gtest_msg.value = "Expected: " "iface_mgr->setPacketFilter(custom_packet_filter)"
" throws an exception of type " "PacketFilterChangeDenied" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_2677; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "iface_mgr->setPacketFilter(custom_packet_filter)"
" throws an exception of type " "PacketFilterChangeDenied" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2677; } } else gtest_label_testthrow_2677
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2677, gtest_msg.value.c_str()) = ::testing::Message()
;
2678
2679 // So, let's close the sockets and retry. Now it should succeed.
2680 iface_mgr->closeSockets();
2681 EXPECT_NO_THROW(iface_mgr->setPacketFilter(custom_packet_filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface_mgr->setPacketFilter(custom_packet_filter); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2681; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2681; } } else gtest_label_testnothrow_2681
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2681, ("Expected: " "iface_mgr->setPacketFilter(custom_packet_filter)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2682}
2683
2684#if defined(OS_LINUX) || defined(OS_BSD)
2685
2686// This test is only supported on Linux and BSD systems. It checks
2687// if it is possible to use the IfaceMgr to select the packet filter
2688// object which can be used to send direct responses to the host
2689// which doesn't have an address yet.
2690TEST_F(IfaceMgrTest, setMatchingPacketFilter)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("setMatchingPacketFilter") > 1, "test_name must not be empty"
); class IfaceMgrTest_setMatchingPacketFilter_Test : public IfaceMgrTest
{ public: IfaceMgrTest_setMatchingPacketFilter_Test() = default
; ~IfaceMgrTest_setMatchingPacketFilter_Test() override = default
; IfaceMgrTest_setMatchingPacketFilter_Test (const IfaceMgrTest_setMatchingPacketFilter_Test
&) = delete; IfaceMgrTest_setMatchingPacketFilter_Test &
operator=( const IfaceMgrTest_setMatchingPacketFilter_Test &
) = delete; IfaceMgrTest_setMatchingPacketFilter_Test (IfaceMgrTest_setMatchingPacketFilter_Test
&&) noexcept = delete; IfaceMgrTest_setMatchingPacketFilter_Test
& operator=( IfaceMgrTest_setMatchingPacketFilter_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_setMatchingPacketFilter_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "setMatchingPacketFilter", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2690), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2690), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2690), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_setMatchingPacketFilter_Test
>); void IfaceMgrTest_setMatchingPacketFilter_Test::TestBody
()
{
2691
2692 // Create an instance of IfaceMgr.
2693 boost::scoped_ptr<NakedIfaceMgr> iface_mgr(new NakedIfaceMgr());
2694 ASSERT_TRUE(iface_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2694, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2695
2696 // Let IfaceMgr figure out which Packet Filter to use when
2697 // direct response capability is not desired. It should pick
2698 // PktFilterInet on Linux.
2699 EXPECT_NO_THROW(iface_mgr->setMatchingPacketFilter(false))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface_mgr->setMatchingPacketFilter(false); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2699; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2699; } } else gtest_label_testnothrow_2699
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2699, ("Expected: " "iface_mgr->setMatchingPacketFilter(false)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2700 // The PktFilterInet is supposed to report lack of direct
2701 // response capability.
2702 EXPECT_FALSE(iface_mgr->isDirectResponseSupported())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(iface_mgr->isDirectResponseSupported
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2702, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface_mgr->isDirectResponseSupported()", "true", "false"
) .c_str()) = ::testing::Message()
;
2703
2704 // There is working implementation of direct responses on Linux
2705 // and BSD (using PktFilterLPF and PktFilterBPF. When direct
2706 // responses are desired the object of this class should be set.
2707 EXPECT_NO_THROW(iface_mgr->setMatchingPacketFilter(true))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface_mgr->setMatchingPacketFilter(true); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2707; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2707; } } else gtest_label_testnothrow_2707
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2707, ("Expected: " "iface_mgr->setMatchingPacketFilter(true)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2708 // This object should report that direct responses are supported.
2709 EXPECT_TRUE(iface_mgr->isDirectResponseSupported())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface_mgr->isDirectResponseSupported
())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2709, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface_mgr->isDirectResponseSupported()", "false", "true"
) .c_str()) = ::testing::Message()
;
2710}
2711
2712// This test checks that it is not possible to open two sockets: IP/UDP
2713// and raw socket and bind to the same address and port. The
2714// raw socket should be opened together with the fallback IP/UDP socket.
2715// The fallback socket should fail to open when there is another IP/UDP
2716// socket bound to the same address and port. Failing to open the fallback
2717// socket should preclude the raw socket from being open.
2718TEST_F(IfaceMgrTest, checkPacketFilterRawSocket)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("checkPacketFilterRawSocket") > 1,
"test_name must not be empty"); class IfaceMgrTest_checkPacketFilterRawSocket_Test
: public IfaceMgrTest { public: IfaceMgrTest_checkPacketFilterRawSocket_Test
() = default; ~IfaceMgrTest_checkPacketFilterRawSocket_Test()
override = default; IfaceMgrTest_checkPacketFilterRawSocket_Test
(const IfaceMgrTest_checkPacketFilterRawSocket_Test &) =
delete; IfaceMgrTest_checkPacketFilterRawSocket_Test & operator
=( const IfaceMgrTest_checkPacketFilterRawSocket_Test &) =
delete; IfaceMgrTest_checkPacketFilterRawSocket_Test (IfaceMgrTest_checkPacketFilterRawSocket_Test
&&) noexcept = delete; IfaceMgrTest_checkPacketFilterRawSocket_Test
& operator=( IfaceMgrTest_checkPacketFilterRawSocket_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_checkPacketFilterRawSocket_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "checkPacketFilterRawSocket", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2718), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2718), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2718), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_checkPacketFilterRawSocket_Test
>); void IfaceMgrTest_checkPacketFilterRawSocket_Test::TestBody
()
{
2719 IOAddress lo_addr("127.0.0.1");
2720 int socket1 = -1, socket2 = -1;
2721 // Create two instances of IfaceMgr.
2722 boost::scoped_ptr<NakedIfaceMgr> iface_mgr1(new NakedIfaceMgr());
2723 ASSERT_TRUE(iface_mgr1)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface_mgr1)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2723, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface_mgr1", "false", "true") .c_str()) = ::testing::Message
()
;
2724 boost::scoped_ptr<NakedIfaceMgr> iface_mgr2(new NakedIfaceMgr());
2725 ASSERT_TRUE(iface_mgr2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface_mgr2)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2725, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface_mgr2", "false", "true") .c_str()) = ::testing::Message
()
;
2726
2727 // Let IfaceMgr figure out which Packet Filter to use when
2728 // direct response capability is not desired. It should pick
2729 // PktFilterInet.
2730 EXPECT_NO_THROW(iface_mgr1->setMatchingPacketFilter(false))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface_mgr1->setMatchingPacketFilter(false); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2730; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2730; } } else gtest_label_testnothrow_2730
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2730, ("Expected: " "iface_mgr1->setMatchingPacketFilter(false)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2731 // Let's open a loopback socket with handy unpriviliged port number
2732 socket1 = iface_mgr1->openSocket(LOOPBACK_NAME, lo_addr,
2733 DHCP4_SERVER_PORT + 10000);
2734
2735 EXPECT_GE(socket1, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket1", "0",
socket1, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2735, gtest_ar.failure_message()) = ::testing::Message()
;
2736
2737 // Then the second use PkFilterLPF mode
2738 EXPECT_NO_THROW(iface_mgr2->setMatchingPacketFilter(true))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface_mgr2->setMatchingPacketFilter(true); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2738; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2738; } } else gtest_label_testnothrow_2738
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2738, ("Expected: " "iface_mgr2->setMatchingPacketFilter(true)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2739
2740 // The socket is open and bound. Another attempt to open socket and
2741 // bind to the same address and port should result in an exception.
2742 EXPECT_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { socket2 = iface_mgr2->
openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)
; } else static_assert(true, ""); } catch (isc::dhcp::SocketConfigError
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< isc::dhcp::SocketConfigError
>::type>::type, std::exception>::value, const ::testing
::internal::NeverThrown&, const std::exception&>::
type e) { gtest_msg.value = "Expected: " "socket2 = iface_mgr2->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)"
" throws an exception of type " "isc::dhcp::SocketConfigError"
".\n Actual: it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testthrow_2746; } catch (...) { gtest_msg.value =
"Expected: " "socket2 = iface_mgr2->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)"
" throws an exception of type " "isc::dhcp::SocketConfigError"
".\n Actual: it throws a different type."; goto gtest_label_testthrow_2746
; } if (!gtest_caught_expected) { gtest_msg.value = "Expected: "
"socket2 = iface_mgr2->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)"
" throws an exception of type " "isc::dhcp::SocketConfigError"
".\n Actual: it throws nothing."; goto gtest_label_testthrow_2746
; } } else gtest_label_testthrow_2746 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2746, gtest_msg.value.c_str()) = ::testing::Message()
2743 socket2 = iface_mgr2->openSocket(LOOPBACK_NAME, lo_addr,switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { socket2 = iface_mgr2->
openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)
; } else static_assert(true, ""); } catch (isc::dhcp::SocketConfigError
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< isc::dhcp::SocketConfigError
>::type>::type, std::exception>::value, const ::testing
::internal::NeverThrown&, const std::exception&>::
type e) { gtest_msg.value = "Expected: " "socket2 = iface_mgr2->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)"
" throws an exception of type " "isc::dhcp::SocketConfigError"
".\n Actual: it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testthrow_2746; } catch (...) { gtest_msg.value =
"Expected: " "socket2 = iface_mgr2->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)"
" throws an exception of type " "isc::dhcp::SocketConfigError"
".\n Actual: it throws a different type."; goto gtest_label_testthrow_2746
; } if (!gtest_caught_expected) { gtest_msg.value = "Expected: "
"socket2 = iface_mgr2->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)"
" throws an exception of type " "isc::dhcp::SocketConfigError"
".\n Actual: it throws nothing."; goto gtest_label_testthrow_2746
; } } else gtest_label_testthrow_2746 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2746, gtest_msg.value.c_str()) = ::testing::Message()
2744 DHCP4_SERVER_PORT + 10000),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { socket2 = iface_mgr2->
openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)
; } else static_assert(true, ""); } catch (isc::dhcp::SocketConfigError
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< isc::dhcp::SocketConfigError
>::type>::type, std::exception>::value, const ::testing
::internal::NeverThrown&, const std::exception&>::
type e) { gtest_msg.value = "Expected: " "socket2 = iface_mgr2->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)"
" throws an exception of type " "isc::dhcp::SocketConfigError"
".\n Actual: it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testthrow_2746; } catch (...) { gtest_msg.value =
"Expected: " "socket2 = iface_mgr2->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)"
" throws an exception of type " "isc::dhcp::SocketConfigError"
".\n Actual: it throws a different type."; goto gtest_label_testthrow_2746
; } if (!gtest_caught_expected) { gtest_msg.value = "Expected: "
"socket2 = iface_mgr2->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)"
" throws an exception of type " "isc::dhcp::SocketConfigError"
".\n Actual: it throws nothing."; goto gtest_label_testthrow_2746
; } } else gtest_label_testthrow_2746 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2746, gtest_msg.value.c_str()) = ::testing::Message()
2745 isc::dhcp::SocketConfigErrorswitch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { socket2 = iface_mgr2->
openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)
; } else static_assert(true, ""); } catch (isc::dhcp::SocketConfigError
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< isc::dhcp::SocketConfigError
>::type>::type, std::exception>::value, const ::testing
::internal::NeverThrown&, const std::exception&>::
type e) { gtest_msg.value = "Expected: " "socket2 = iface_mgr2->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)"
" throws an exception of type " "isc::dhcp::SocketConfigError"
".\n Actual: it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testthrow_2746; } catch (...) { gtest_msg.value =
"Expected: " "socket2 = iface_mgr2->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)"
" throws an exception of type " "isc::dhcp::SocketConfigError"
".\n Actual: it throws a different type."; goto gtest_label_testthrow_2746
; } if (!gtest_caught_expected) { gtest_msg.value = "Expected: "
"socket2 = iface_mgr2->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)"
" throws an exception of type " "isc::dhcp::SocketConfigError"
".\n Actual: it throws nothing."; goto gtest_label_testthrow_2746
; } } else gtest_label_testthrow_2746 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2746, gtest_msg.value.c_str()) = ::testing::Message()
2746 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { socket2 = iface_mgr2->
openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)
; } else static_assert(true, ""); } catch (isc::dhcp::SocketConfigError
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< isc::dhcp::SocketConfigError
>::type>::type, std::exception>::value, const ::testing
::internal::NeverThrown&, const std::exception&>::
type e) { gtest_msg.value = "Expected: " "socket2 = iface_mgr2->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)"
" throws an exception of type " "isc::dhcp::SocketConfigError"
".\n Actual: it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testthrow_2746; } catch (...) { gtest_msg.value =
"Expected: " "socket2 = iface_mgr2->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)"
" throws an exception of type " "isc::dhcp::SocketConfigError"
".\n Actual: it throws a different type."; goto gtest_label_testthrow_2746
; } if (!gtest_caught_expected) { gtest_msg.value = "Expected: "
"socket2 = iface_mgr2->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000)"
" throws an exception of type " "isc::dhcp::SocketConfigError"
".\n Actual: it throws nothing."; goto gtest_label_testthrow_2746
; } } else gtest_label_testthrow_2746 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2746, gtest_msg.value.c_str()) = ::testing::Message()
;
2747 // Surprisingly we managed to open another socket. We have to close it
2748 // to prevent resource leak.
2749 if (socket2 >= 0) {
2750 close(socket2);
2751 ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2751, "Failed") = ::testing::Message()
<< "Two sockets opened and bound to the same IP"
2752 " address and UDP port";
2753 }
2754
2755 if (socket1 >= 0) {
2756 close(socket1);
2757 }
2758}
2759
2760#else
2761
2762// Note: This test will only run on non-Linux and non-BSD systems.
2763// This test checks whether it is possible to use IfaceMgr to figure
2764// out which Packet Filter object should be used when direct responses
2765// to hosts, having no address assigned are desired or not desired.
2766// Since direct responses aren't supported on systems other than Linux
2767// and BSD the function under test should always set object of
2768// PktFilterInet type as current Packet Filter. This object does not
2769//support direct responses. Once implementation is added on systems
2770// other than BSD and Linux the OS specific version of the test will
2771// be removed.
2772TEST_F(IfaceMgrTest, setMatchingPacketFilter)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("setMatchingPacketFilter") > 1, "test_name must not be empty"
); class IfaceMgrTest_setMatchingPacketFilter_Test : public IfaceMgrTest
{ public: IfaceMgrTest_setMatchingPacketFilter_Test() = default
; ~IfaceMgrTest_setMatchingPacketFilter_Test() override = default
; IfaceMgrTest_setMatchingPacketFilter_Test (const IfaceMgrTest_setMatchingPacketFilter_Test
&) = delete; IfaceMgrTest_setMatchingPacketFilter_Test &
operator=( const IfaceMgrTest_setMatchingPacketFilter_Test &
) = delete; IfaceMgrTest_setMatchingPacketFilter_Test (IfaceMgrTest_setMatchingPacketFilter_Test
&&) noexcept = delete; IfaceMgrTest_setMatchingPacketFilter_Test
& operator=( IfaceMgrTest_setMatchingPacketFilter_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_setMatchingPacketFilter_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "setMatchingPacketFilter", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2772), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2772), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2772), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_setMatchingPacketFilter_Test
>); void IfaceMgrTest_setMatchingPacketFilter_Test::TestBody
()
{
2773
2774 // Create an instance of IfaceMgr.
2775 boost::scoped_ptr<NakedIfaceMgr> iface_mgr(new NakedIfaceMgr());
2776 ASSERT_TRUE(iface_mgr)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface_mgr)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2776, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface_mgr", "false", "true") .c_str()) = ::testing::Message
()
;
2777
2778 // Let IfaceMgr figure out which Packet Filter to use when
2779 // direct response capability is not desired. It should pick
2780 // PktFilterInet.
2781 EXPECT_NO_THROW(iface_mgr->setMatchingPacketFilter(false))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface_mgr->setMatchingPacketFilter(false); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2781; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2781; } } else gtest_label_testnothrow_2781
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2781, ("Expected: " "iface_mgr->setMatchingPacketFilter(false)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2782 // The PktFilterInet is supposed to report lack of direct
2783 // response capability.
2784 EXPECT_FALSE(iface_mgr->isDirectResponseSupported())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(iface_mgr->isDirectResponseSupported
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2784, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface_mgr->isDirectResponseSupported()", "true", "false"
) .c_str()) = ::testing::Message()
;
2785
2786 // On non-Linux systems, we are missing the direct traffic
2787 // implementation. Therefore, we expect that PktFilterInet
2788 // object will be set.
2789 EXPECT_NO_THROW(iface_mgr->setMatchingPacketFilter(true))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface_mgr->setMatchingPacketFilter(true); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2789; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2789; } } else gtest_label_testnothrow_2789
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2789, ("Expected: " "iface_mgr->setMatchingPacketFilter(true)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2790 // This object should report lack of direct response capability.
2791 EXPECT_FALSE(iface_mgr->isDirectResponseSupported())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(iface_mgr->isDirectResponseSupported
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2791, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface_mgr->isDirectResponseSupported()", "true", "false"
) .c_str()) = ::testing::Message()
;
2792}
2793
2794#endif
2795
2796TEST_F(IfaceMgrTest, socket4)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("socket4") > 1, "test_name must not be empty"
); class IfaceMgrTest_socket4_Test : public IfaceMgrTest { public
: IfaceMgrTest_socket4_Test() = default; ~IfaceMgrTest_socket4_Test
() override = default; IfaceMgrTest_socket4_Test (const IfaceMgrTest_socket4_Test
&) = delete; IfaceMgrTest_socket4_Test & operator=( const
IfaceMgrTest_socket4_Test &) = delete; IfaceMgrTest_socket4_Test
(IfaceMgrTest_socket4_Test &&) noexcept = delete; IfaceMgrTest_socket4_Test
& operator=( IfaceMgrTest_socket4_Test &&) noexcept
= delete; private: void TestBody() override; [[maybe_unused]
] static ::testing::TestInfo* const test_info_; }; ::testing::
TestInfo* const IfaceMgrTest_socket4_Test::test_info_ = ::testing
::internal::MakeAndRegisterTestInfo( "IfaceMgrTest", "socket4"
, nullptr, nullptr, ::testing::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2796), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2796), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2796), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_socket4_Test
>); void IfaceMgrTest_socket4_Test::TestBody()
{
2797
2798 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
2799
2800 // Let's assume that every supported OS have lo interface.
2801 IOAddress lo_addr("127.0.0.1");
2802 // Use unprivileged port (it's convenient for running tests as non-root).
2803 int socket1 = 0;
2804
2805 EXPECT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT
+ 10000);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2808; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2808
; } } else gtest_label_testnothrow_2808 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2808, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2806 socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr,switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT
+ 10000);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2808; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2808
; } } else gtest_label_testnothrow_2808 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2808, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2807 DHCP4_SERVER_PORT + 10000);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT
+ 10000);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2808; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2808
; } } else gtest_label_testnothrow_2808 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2808, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2808 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT
+ 10000);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2808; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2808
; } } else gtest_label_testnothrow_2808 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2808, ("Expected: " "socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, DHCP4_SERVER_PORT + 10000);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2809
2810 EXPECT_GE(socket1, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket1", "0",
socket1, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2810, gtest_ar.failure_message()) = ::testing::Message()
;
2811
2812 Pkt4Ptr pkt(new Pkt4(DHCPDISCOVER, 1234));
2813 pkt->setIface(LOOPBACK_NAME);
2814 pkt->setIndex(LOOPBACK_INDEX);
2815
2816 // Expect that we get the socket that we just opened.
2817 EXPECT_EQ(socket1, ifacemgr->getSocket(pkt).sockfd_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("socket1"
, "ifacemgr->getSocket(pkt).sockfd_", socket1, ifacemgr->
getSocket(pkt).sockfd_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2817, gtest_ar.failure_message()) = ::testing::Message()
;
2818
2819 close(socket1);
2820}
2821
2822// This test verifies that IPv4 sockets are open on all interfaces (except
2823// loopback), when interfaces are up, running and active (not disabled from
2824// the DHCP configuration).
2825TEST_F(IfaceMgrTest, openSockets4)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSockets4") > 1, "test_name must not be empty"
); class IfaceMgrTest_openSockets4_Test : public IfaceMgrTest
{ public: IfaceMgrTest_openSockets4_Test() = default; ~IfaceMgrTest_openSockets4_Test
() override = default; IfaceMgrTest_openSockets4_Test (const IfaceMgrTest_openSockets4_Test
&) = delete; IfaceMgrTest_openSockets4_Test & operator
=( const IfaceMgrTest_openSockets4_Test &) = delete; IfaceMgrTest_openSockets4_Test
(IfaceMgrTest_openSockets4_Test &&) noexcept = delete
; IfaceMgrTest_openSockets4_Test & operator=( IfaceMgrTest_openSockets4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_openSockets4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSockets4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2825), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2825), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2825), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_openSockets4_Test
>); void IfaceMgrTest_openSockets4_Test::TestBody()
{
2826 NakedIfaceMgr ifacemgr;
2827
2828 // Remove all real interfaces and create a set of dummy interfaces.
2829 ifacemgr.createIfaces();
2830
2831 // Use the custom packet filter object. This object mimics the socket
2832 // opening operation - the real socket is not open.
2833 boost::shared_ptr<TestPktFilter> custom_packet_filter(new TestPktFilter());
2834 ASSERT_TRUE(custom_packet_filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(custom_packet_filter)
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2834, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "custom_packet_filter", "false", "true") .c_str()) = ::testing
::Message()
;
2835 ASSERT_NO_THROW(ifacemgr.setPacketFilter(custom_packet_filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(custom_packet_filter); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2835; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2835; } } else gtest_label_testnothrow_2835
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2835, ("Expected: " "ifacemgr.setPacketFilter(custom_packet_filter)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2836
2837 // Simulate opening sockets using the dummy packet filter.
2838 ASSERT_NO_THROW(ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2838; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2838; } } else gtest_label_testnothrow_2838
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2838, ("Expected: " "ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2839
2840 // Expect that the sockets are open on both eth0 and eth1.
2841 EXPECT_EQ(1U, ifacemgr.getIface("eth0")->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(\"eth0\")->getSockets().size()"
, 1U, ifacemgr.getIface("eth0")->getSockets().size()))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2841, gtest_ar.failure_message()) = ::testing::Message()
;
2842 EXPECT_EQ(1U, ifacemgr.getIface(ETH0_INDEX)->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(ETH0_INDEX)->getSockets().size()"
, 1U, ifacemgr.getIface(ETH0_INDEX)->getSockets().size()))
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2842, gtest_ar.failure_message()) = ::testing::Message()
;
2843 EXPECT_EQ(1U, ifacemgr.getIface("eth1")->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(\"eth1\")->getSockets().size()"
, 1U, ifacemgr.getIface("eth1")->getSockets().size()))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2843, gtest_ar.failure_message()) = ::testing::Message()
;
2844 EXPECT_EQ(1U, ifacemgr.getIface(ETH1_INDEX)->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(ETH1_INDEX)->getSockets().size()"
, 1U, ifacemgr.getIface(ETH1_INDEX)->getSockets().size()))
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2844, gtest_ar.failure_message()) = ::testing::Message()
;
2845 // Socket shouldn't have been opened on loopback.
2846 EXPECT_TRUE(ifacemgr.getIface("lo")->getSockets().empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface("lo"
)->getSockets().empty())) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2846, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(\"lo\")->getSockets().empty()", "false"
, "true") .c_str()) = ::testing::Message()
;
2847 EXPECT_TRUE(ifacemgr.getIface(LO_INDEX)->getSockets().empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface(LO_INDEX
)->getSockets().empty())) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2847, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(LO_INDEX)->getSockets().empty()", "false"
, "true") .c_str()) = ::testing::Message()
;
2848}
2849
2850// This test verifies that IPv4 sockets are open on the loopback interface
2851// when the loopback is active and allowed.
2852TEST_F(IfaceMgrTest, openSockets4Loopback)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSockets4Loopback") > 1, "test_name must not be empty"
); class IfaceMgrTest_openSockets4Loopback_Test : public IfaceMgrTest
{ public: IfaceMgrTest_openSockets4Loopback_Test() = default
; ~IfaceMgrTest_openSockets4Loopback_Test() override = default
; IfaceMgrTest_openSockets4Loopback_Test (const IfaceMgrTest_openSockets4Loopback_Test
&) = delete; IfaceMgrTest_openSockets4Loopback_Test &
operator=( const IfaceMgrTest_openSockets4Loopback_Test &
) = delete; IfaceMgrTest_openSockets4Loopback_Test (IfaceMgrTest_openSockets4Loopback_Test
&&) noexcept = delete; IfaceMgrTest_openSockets4Loopback_Test
& operator=( IfaceMgrTest_openSockets4Loopback_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_openSockets4Loopback_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSockets4Loopback", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2852), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2852), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2852), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_openSockets4Loopback_Test
>); void IfaceMgrTest_openSockets4Loopback_Test::TestBody(
)
{
2853 NakedIfaceMgr ifacemgr;
2854
2855 // Remove all real interfaces and create a set of dummy interfaces.
2856 ifacemgr.createIfaces();
2857
2858 // Allow the loopback interface.
2859 ifacemgr.setAllowLoopBack(true);
2860
2861 // Make the loopback interface active.
2862 ifacemgr.getIface("lo")->inactive4_ = false;
2863
2864 // Use the custom packet filter object. This object mimics the socket
2865 // opening operation - the real socket is not open.
2866 boost::shared_ptr<TestPktFilter> custom_packet_filter(new TestPktFilter());
2867 ASSERT_TRUE(custom_packet_filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(custom_packet_filter)
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2867, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "custom_packet_filter", "false", "true") .c_str()) = ::testing
::Message()
;
2868 ASSERT_NO_THROW(ifacemgr.setPacketFilter(custom_packet_filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(custom_packet_filter); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2868; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2868; } } else gtest_label_testnothrow_2868
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2868, ("Expected: " "ifacemgr.setPacketFilter(custom_packet_filter)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2869
2870 // Simulate opening sockets using the dummy packet filter.
2871 ASSERT_NO_THROW(ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2871; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2871; } } else gtest_label_testnothrow_2871
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2871, ("Expected: " "ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2872
2873 // Expect that the sockets are open on all interfaces.
2874 EXPECT_EQ(1U, ifacemgr.getIface("eth0")->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(\"eth0\")->getSockets().size()"
, 1U, ifacemgr.getIface("eth0")->getSockets().size()))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2874, gtest_ar.failure_message()) = ::testing::Message()
;
2875 EXPECT_EQ(1U, ifacemgr.getIface(ETH0_INDEX)->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(ETH0_INDEX)->getSockets().size()"
, 1U, ifacemgr.getIface(ETH0_INDEX)->getSockets().size()))
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2875, gtest_ar.failure_message()) = ::testing::Message()
;
2876 EXPECT_EQ(1U, ifacemgr.getIface("eth1")->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(\"eth1\")->getSockets().size()"
, 1U, ifacemgr.getIface("eth1")->getSockets().size()))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2876, gtest_ar.failure_message()) = ::testing::Message()
;
2877 EXPECT_EQ(1U, ifacemgr.getIface(ETH1_INDEX)->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(ETH1_INDEX)->getSockets().size()"
, 1U, ifacemgr.getIface(ETH1_INDEX)->getSockets().size()))
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2877, gtest_ar.failure_message()) = ::testing::Message()
;
2878 EXPECT_EQ(1U, ifacemgr.getIface("lo")->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(\"lo\")->getSockets().size()"
, 1U, ifacemgr.getIface("lo")->getSockets().size()))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2878, gtest_ar.failure_message()) = ::testing::Message()
;
2879 EXPECT_EQ(1U, ifacemgr.getIface(LO_INDEX)->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(LO_INDEX)->getSockets().size()"
, 1U, ifacemgr.getIface(LO_INDEX)->getSockets().size()))) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2879, gtest_ar.failure_message()) = ::testing::Message()
;
2880}
2881
2882// This test verifies that the socket is not open on the interface which is
2883// down, but sockets are open on all other non-loopback interfaces.
2884TEST_F(IfaceMgrTest, openSockets4IfaceDown)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSockets4IfaceDown") > 1, "test_name must not be empty"
); class IfaceMgrTest_openSockets4IfaceDown_Test : public IfaceMgrTest
{ public: IfaceMgrTest_openSockets4IfaceDown_Test() = default
; ~IfaceMgrTest_openSockets4IfaceDown_Test() override = default
; IfaceMgrTest_openSockets4IfaceDown_Test (const IfaceMgrTest_openSockets4IfaceDown_Test
&) = delete; IfaceMgrTest_openSockets4IfaceDown_Test &
operator=( const IfaceMgrTest_openSockets4IfaceDown_Test &
) = delete; IfaceMgrTest_openSockets4IfaceDown_Test (IfaceMgrTest_openSockets4IfaceDown_Test
&&) noexcept = delete; IfaceMgrTest_openSockets4IfaceDown_Test
& operator=( IfaceMgrTest_openSockets4IfaceDown_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_openSockets4IfaceDown_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSockets4IfaceDown", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2884), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2884), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2884), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_openSockets4IfaceDown_Test
>); void IfaceMgrTest_openSockets4IfaceDown_Test::TestBody
()
{
2885 IfaceMgrTestConfig config(true);
2886
2887 // Boolean parameters specify that eth0 is:
2888 // - not a loopback
2889 // - is "down" (not up)
2890 // - is not running
2891 // - is active (is not inactive)
2892 config.setIfaceFlags("eth0", FlagLoopback(false), FlagUp(false),
2893 FlagRunning(false), FlagInactive4(false),
2894 FlagInactive6(false));
2895 ASSERT_FALSE(IfaceMgr::instance().getIface("eth0")->flag_up_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getIface("eth0")->flag_up_))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2895, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getIface(\"eth0\")->flag_up_", "true"
, "false") .c_str()) = ::testing::Message()
;
2896 ASSERT_FALSE(IfaceMgr::instance().getIface(ETH0_INDEX)->flag_up_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getIface(ETH0_INDEX)->flag_up_))) ; else return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2896, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"IfaceMgr::instance().getIface(ETH0_INDEX)->flag_up_", "true"
, "false") .c_str()) = ::testing::Message()
;
2897
2898 // Install an error handler before trying to open sockets. This handler
2899 // should be called when the IfaceMgr fails to open socket on an interface
2900 // on which the server is configured to listen.
2901 isc::dhcp::IfaceMgrErrorMsgCallback error_handler =
2902 std::bind(&IfaceMgrTest::ifaceMgrErrorHandler, this, ph::_1);
2903
2904 ASSERT_NO_THROW(IfaceMgr::instance().openSockets4(DHCP4_SERVER_PORT, true,switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().openSockets4(DHCP4_SERVER_PORT, true, error_handler
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2905; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2905
; } } else gtest_label_testnothrow_2905 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2905, ("Expected: " "IfaceMgr::instance().openSockets4(DHCP4_SERVER_PORT, true, error_handler)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2905 error_handler))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().openSockets4(DHCP4_SERVER_PORT, true, error_handler
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2905; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2905
; } } else gtest_label_testnothrow_2905 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2905, ("Expected: " "IfaceMgr::instance().openSockets4(DHCP4_SERVER_PORT, true, error_handler)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2906 // Since the interface is down, an attempt to open a socket should result
2907 // in error.
2908 EXPECT_EQ(1, errors_count_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "errors_count_"
, 1, errors_count_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2908, gtest_ar.failure_message()) = ::testing::Message()
;
2909
2910 // There should be no socket on eth0 open, because interface was down.
2911 EXPECT_TRUE(IfaceMgr::instance().getIface("eth0")->getSockets().empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(IfaceMgr::instance().
getIface("eth0")->getSockets().empty())) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2911, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"IfaceMgr::instance().getIface(\"eth0\")->getSockets().empty()"
, "false", "true") .c_str()) = ::testing::Message()
;
2912 EXPECT_TRUE(IfaceMgr::instance().getIface(ETH0_INDEX)->getSockets().empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(IfaceMgr::instance().
getIface(ETH0_INDEX)->getSockets().empty())) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2912, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"IfaceMgr::instance().getIface(ETH0_INDEX)->getSockets().empty()"
, "false", "true") .c_str()) = ::testing::Message()
;
2913
2914 // Expecting that the socket is open on eth1 because it was up, running
2915 // and active.
2916 EXPECT_EQ(2U, IfaceMgr::instance().getIface("eth1")->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("2U", "IfaceMgr::instance().getIface(\"eth1\")->getSockets().size()"
, 2U, IfaceMgr::instance().getIface("eth1")->getSockets().
size()))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2916, gtest_ar.failure_message()) = ::testing::Message()
;
2917 EXPECT_EQ(2U, IfaceMgr::instance().getIface(ETH1_INDEX)->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("2U", "IfaceMgr::instance().getIface(ETH1_INDEX)->getSockets().size()"
, 2U, IfaceMgr::instance().getIface(ETH1_INDEX)->getSockets
().size()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2917, gtest_ar.failure_message()) = ::testing::Message()
;
2918 // Same for eth1961.
2919 EXPECT_EQ(1U, IfaceMgr::instance().getIface("eth1961")->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "IfaceMgr::instance().getIface(\"eth1961\")->getSockets().size()"
, 1U, IfaceMgr::instance().getIface("eth1961")->getSockets
().size()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2919, gtest_ar.failure_message()) = ::testing::Message()
;
2920 EXPECT_EQ(1U, IfaceMgr::instance().getIface(ETH1961_INDEX)->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "IfaceMgr::instance().getIface(ETH1961_INDEX)->getSockets().size()"
, 1U, IfaceMgr::instance().getIface(ETH1961_INDEX)->getSockets
().size()))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2920, gtest_ar.failure_message()) = ::testing::Message()
;
2921 // Never open socket on loopback interface.
2922 EXPECT_TRUE(IfaceMgr::instance().getIface("lo")->getSockets().empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(IfaceMgr::instance().
getIface("lo")->getSockets().empty())) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2922, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getIface(\"lo\")->getSockets().empty()"
, "false", "true") .c_str()) = ::testing::Message()
;
2923 EXPECT_TRUE(IfaceMgr::instance().getIface(LO_INDEX)->getSockets().empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(IfaceMgr::instance().
getIface(LO_INDEX)->getSockets().empty())) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 2923, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"IfaceMgr::instance().getIface(LO_INDEX)->getSockets().empty()"
, "false", "true") .c_str()) = ::testing::Message()
;
2924}
2925
2926// This test verifies that the socket is not open on the interface which is
2927// disabled from the DHCP configuration, but sockets are open on all other
2928// non-loopback interfaces.
2929TEST_F(IfaceMgrTest, openSockets4IfaceInactive)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSockets4IfaceInactive") > 1, "test_name must not be empty"
); class IfaceMgrTest_openSockets4IfaceInactive_Test : public
IfaceMgrTest { public: IfaceMgrTest_openSockets4IfaceInactive_Test
() = default; ~IfaceMgrTest_openSockets4IfaceInactive_Test() override
= default; IfaceMgrTest_openSockets4IfaceInactive_Test (const
IfaceMgrTest_openSockets4IfaceInactive_Test &) = delete;
IfaceMgrTest_openSockets4IfaceInactive_Test & operator=(
const IfaceMgrTest_openSockets4IfaceInactive_Test &) = delete
; IfaceMgrTest_openSockets4IfaceInactive_Test (IfaceMgrTest_openSockets4IfaceInactive_Test
&&) noexcept = delete; IfaceMgrTest_openSockets4IfaceInactive_Test
& operator=( IfaceMgrTest_openSockets4IfaceInactive_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_openSockets4IfaceInactive_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSockets4IfaceInactive", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2929), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2929), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2929), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_openSockets4IfaceInactive_Test
>); void IfaceMgrTest_openSockets4IfaceInactive_Test::TestBody
()
{
2930 NakedIfaceMgr ifacemgr;
2931
2932 // Remove all real interfaces and create a set of dummy interfaces.
2933 ifacemgr.createIfaces();
2934
2935 boost::shared_ptr<TestPktFilter> custom_packet_filter(new TestPktFilter());
2936 ASSERT_TRUE(custom_packet_filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(custom_packet_filter)
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2936, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "custom_packet_filter", "false", "true") .c_str()) = ::testing
::Message()
;
2937 ASSERT_NO_THROW(ifacemgr.setPacketFilter(custom_packet_filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(custom_packet_filter); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2937; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2937; } } else gtest_label_testnothrow_2937
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2937, ("Expected: " "ifacemgr.setPacketFilter(custom_packet_filter)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2938
2939 // Boolean parameters specify that eth1 is:
2940 // - not a loopback
2941 // - is up
2942 // - is running
2943 // - is inactive
2944 ifacemgr.setIfaceFlags("eth1", false, true, true, true, false);
2945 ASSERT_TRUE(ifacemgr.getIface("eth1")->inactive4_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface("eth1"
)->inactive4_)) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2945, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(\"eth1\")->inactive4_", "false", "true"
) .c_str()) = ::testing::Message()
;
2946 ASSERT_TRUE(ifacemgr.getIface(ETH1_INDEX)->inactive4_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface(ETH1_INDEX
)->inactive4_)) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2946, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(ETH1_INDEX)->inactive4_", "false", "true"
) .c_str()) = ::testing::Message()
;
2947 ASSERT_NO_THROW(ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2947; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2947; } } else gtest_label_testnothrow_2947
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2947, ("Expected: " "ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2948
2949 // The socket on eth0 should be open because interface is up, running and
2950 // active (not disabled through DHCP configuration, for example).
2951 EXPECT_EQ(1U, ifacemgr.getIface("eth0")->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(\"eth0\")->getSockets().size()"
, 1U, ifacemgr.getIface("eth0")->getSockets().size()))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2951, gtest_ar.failure_message()) = ::testing::Message()
;
2952 EXPECT_EQ(1U, ifacemgr.getIface(ETH0_INDEX)->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(ETH0_INDEX)->getSockets().size()"
, 1U, ifacemgr.getIface(ETH0_INDEX)->getSockets().size()))
) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2952, gtest_ar.failure_message()) = ::testing::Message()
;
2953 // There should be no socket open on eth1 because it was marked inactive.
2954 EXPECT_TRUE(ifacemgr.getIface("eth1")->getSockets().empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface("eth1"
)->getSockets().empty())) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2954, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(\"eth1\")->getSockets().empty()", "false"
, "true") .c_str()) = ::testing::Message()
;
2955 EXPECT_TRUE(ifacemgr.getIface(ETH1_INDEX)->getSockets().empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface(ETH1_INDEX
)->getSockets().empty())) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2955, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(ETH1_INDEX)->getSockets().empty()", "false"
, "true") .c_str()) = ::testing::Message()
;
2956 // Sockets are not open on loopback interfaces too.
2957 EXPECT_TRUE(ifacemgr.getIface("lo")->getSockets().empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface("lo"
)->getSockets().empty())) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2957, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(\"lo\")->getSockets().empty()", "false"
, "true") .c_str()) = ::testing::Message()
;
2958 EXPECT_TRUE(ifacemgr.getIface(LO_INDEX)->getSockets().empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface(LO_INDEX
)->getSockets().empty())) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2958, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(LO_INDEX)->getSockets().empty()", "false"
, "true") .c_str()) = ::testing::Message()
;
2959}
2960
2961// Test that exception is thrown when trying to bind a new socket to the port
2962// and address which is already in use by another socket.
2963TEST_F(IfaceMgrTest, openSockets4NoErrorHandler)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSockets4NoErrorHandler") > 1,
"test_name must not be empty"); class IfaceMgrTest_openSockets4NoErrorHandler_Test
: public IfaceMgrTest { public: IfaceMgrTest_openSockets4NoErrorHandler_Test
() = default; ~IfaceMgrTest_openSockets4NoErrorHandler_Test()
override = default; IfaceMgrTest_openSockets4NoErrorHandler_Test
(const IfaceMgrTest_openSockets4NoErrorHandler_Test &) =
delete; IfaceMgrTest_openSockets4NoErrorHandler_Test & operator
=( const IfaceMgrTest_openSockets4NoErrorHandler_Test &) =
delete; IfaceMgrTest_openSockets4NoErrorHandler_Test (IfaceMgrTest_openSockets4NoErrorHandler_Test
&&) noexcept = delete; IfaceMgrTest_openSockets4NoErrorHandler_Test
& operator=( IfaceMgrTest_openSockets4NoErrorHandler_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_openSockets4NoErrorHandler_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSockets4NoErrorHandler", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2963), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2963), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2963), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_openSockets4NoErrorHandler_Test
>); void IfaceMgrTest_openSockets4NoErrorHandler_Test::TestBody
()
{
2964 NakedIfaceMgr ifacemgr;
2965
2966 // Remove all real interfaces and create a set of dummy interfaces.
2967 ifacemgr.createIfaces();
2968
2969 boost::shared_ptr<TestPktFilter> custom_packet_filter(new TestPktFilter());
2970 ASSERT_TRUE(custom_packet_filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(custom_packet_filter)
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2970, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "custom_packet_filter", "false", "true") .c_str()) = ::testing
::Message()
;
2971 ASSERT_NO_THROW(ifacemgr.setPacketFilter(custom_packet_filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(custom_packet_filter); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2971; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2971; } } else gtest_label_testnothrow_2971
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2971, ("Expected: " "ifacemgr.setPacketFilter(custom_packet_filter)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2972
2973 // Open socket on eth1. The openSockets4 should detect that this
2974 // socket has been already open and an attempt to open another socket
2975 // and bind to this address and port should fail.
2976 ASSERT_NO_THROW(ifacemgr.openSocket("eth1", IOAddress("192.0.2.3"),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSocket("eth1", IOAddress("192.0.2.3"), DHCP4_SERVER_PORT
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2977; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2977
; } } else gtest_label_testnothrow_2977 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2977, ("Expected: " "ifacemgr.openSocket(\"eth1\", IOAddress(\"192.0.2.3\"), DHCP4_SERVER_PORT)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
2977 DHCP4_SERVER_PORT))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSocket("eth1", IOAddress("192.0.2.3"), DHCP4_SERVER_PORT
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_2977; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2977
; } } else gtest_label_testnothrow_2977 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2977, ("Expected: " "ifacemgr.openSocket(\"eth1\", IOAddress(\"192.0.2.3\"), DHCP4_SERVER_PORT)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2978
2979 // The function throws an exception when it tries to open a socket
2980 // and bind it to the address in use.
2981 EXPECT_THROW(ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr.openSockets4(DHCP4_SERVER_PORT
, true, 0); } else static_assert(true, ""); } catch (isc::dhcp
::SocketConfigError const&) { gtest_caught_expected = true
; } catch (typename std::conditional< std::is_same<typename
std::remove_cv<typename std::remove_reference< isc::dhcp
::SocketConfigError>::type>::type, std::exception>::
value, const ::testing::internal::NeverThrown&, const std
::exception&>::type e) { gtest_msg.value = "Expected: "
"ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0)" " throws an exception of type "
"isc::dhcp::SocketConfigError" ".\n Actual: it throws "; gtest_msg
.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg
.value += " with description \""; gtest_msg.value += e.what()
; gtest_msg.value += "\"."; goto gtest_label_testthrow_2982; }
catch (...) { gtest_msg.value = "Expected: " "ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0)"
" throws an exception of type " "isc::dhcp::SocketConfigError"
".\n Actual: it throws a different type."; goto gtest_label_testthrow_2982
; } if (!gtest_caught_expected) { gtest_msg.value = "Expected: "
"ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0)" " throws an exception of type "
"isc::dhcp::SocketConfigError" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2982; } } else gtest_label_testthrow_2982
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2982, gtest_msg.value.c_str()) = ::testing::Message()
2982 isc::dhcp::SocketConfigError)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr.openSockets4(DHCP4_SERVER_PORT
, true, 0); } else static_assert(true, ""); } catch (isc::dhcp
::SocketConfigError const&) { gtest_caught_expected = true
; } catch (typename std::conditional< std::is_same<typename
std::remove_cv<typename std::remove_reference< isc::dhcp
::SocketConfigError>::type>::type, std::exception>::
value, const ::testing::internal::NeverThrown&, const std
::exception&>::type e) { gtest_msg.value = "Expected: "
"ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0)" " throws an exception of type "
"isc::dhcp::SocketConfigError" ".\n Actual: it throws "; gtest_msg
.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg
.value += " with description \""; gtest_msg.value += e.what()
; gtest_msg.value += "\"."; goto gtest_label_testthrow_2982; }
catch (...) { gtest_msg.value = "Expected: " "ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0)"
" throws an exception of type " "isc::dhcp::SocketConfigError"
".\n Actual: it throws a different type."; goto gtest_label_testthrow_2982
; } if (!gtest_caught_expected) { gtest_msg.value = "Expected: "
"ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0)" " throws an exception of type "
"isc::dhcp::SocketConfigError" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_2982; } } else gtest_label_testthrow_2982
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2982, gtest_msg.value.c_str()) = ::testing::Message()
;
2983}
2984
2985// Test that the external error handler is called when trying to bind a new
2986// socket to the address and port being in use. The sockets on the other
2987// interfaces should open just fine.
2988TEST_F(IfaceMgrTest, openSocket4ErrorHandler)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSocket4ErrorHandler") > 1, "test_name must not be empty"
); class IfaceMgrTest_openSocket4ErrorHandler_Test : public IfaceMgrTest
{ public: IfaceMgrTest_openSocket4ErrorHandler_Test() = default
; ~IfaceMgrTest_openSocket4ErrorHandler_Test() override = default
; IfaceMgrTest_openSocket4ErrorHandler_Test (const IfaceMgrTest_openSocket4ErrorHandler_Test
&) = delete; IfaceMgrTest_openSocket4ErrorHandler_Test &
operator=( const IfaceMgrTest_openSocket4ErrorHandler_Test &
) = delete; IfaceMgrTest_openSocket4ErrorHandler_Test (IfaceMgrTest_openSocket4ErrorHandler_Test
&&) noexcept = delete; IfaceMgrTest_openSocket4ErrorHandler_Test
& operator=( IfaceMgrTest_openSocket4ErrorHandler_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_openSocket4ErrorHandler_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSocket4ErrorHandler", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2988), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2988), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2988), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_openSocket4ErrorHandler_Test
>); void IfaceMgrTest_openSocket4ErrorHandler_Test::TestBody
()
{
2989 NakedIfaceMgr ifacemgr;
2990
2991 // Remove all real interfaces and create a set of dummy interfaces.
2992 ifacemgr.createIfaces();
2993
2994 boost::shared_ptr<TestPktFilter> custom_packet_filter(new TestPktFilter());
2995 ASSERT_TRUE(custom_packet_filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(custom_packet_filter)
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2995, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "custom_packet_filter", "false", "true") .c_str()) = ::testing
::Message()
;
2996 ASSERT_NO_THROW(ifacemgr.setPacketFilter(custom_packet_filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(custom_packet_filter); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_2996; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_2996; } } else gtest_label_testnothrow_2996
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 2996, ("Expected: " "ifacemgr.setPacketFilter(custom_packet_filter)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
2997
2998 // Open socket on eth0.
2999 ASSERT_NO_THROW(ifacemgr.openSocket("eth0", IOAddress("10.0.0.1"),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSocket("eth0", IOAddress("10.0.0.1"), DHCP4_SERVER_PORT
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_3000; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3000
; } } else gtest_label_testnothrow_3000 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3000, ("Expected: " "ifacemgr.openSocket(\"eth0\", IOAddress(\"10.0.0.1\"), DHCP4_SERVER_PORT)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
3000 DHCP4_SERVER_PORT))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSocket("eth0", IOAddress("10.0.0.1"), DHCP4_SERVER_PORT
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_3000; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3000
; } } else gtest_label_testnothrow_3000 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3000, ("Expected: " "ifacemgr.openSocket(\"eth0\", IOAddress(\"10.0.0.1\"), DHCP4_SERVER_PORT)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3001
3002 // Install an error handler before trying to open sockets. This handler
3003 // should be called when the IfaceMgr fails to open socket on eth0.
3004 isc::dhcp::IfaceMgrErrorMsgCallback error_handler =
3005 std::bind(&IfaceMgrTest::ifaceMgrErrorHandler, this, ph::_1);
3006 // The openSockets4 should detect that there is another socket already
3007 // open and bound to the same address and port. An attempt to open
3008 // another socket and bind to this address and port should fail.
3009 ASSERT_NO_THROW(ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, error_handler))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, error_handler
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_3009; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3009
; } } else gtest_label_testnothrow_3009 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3009, ("Expected: " "ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, error_handler)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3010 // We expect that an error occurred when we tried to open a socket on
3011 // eth0, but the socket on eth1 should open just fine.
3012 EXPECT_EQ(1, errors_count_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "errors_count_"
, 1, errors_count_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3012, gtest_ar.failure_message()) = ::testing::Message()
;
3013
3014 // Reset errors count.
3015 errors_count_ = 0;
3016
3017 // Now that we have two sockets open, we can try this again but this time
3018 // we should get two errors: one when opening a socket on eth0, another one
3019 // when opening a socket on eth1.
3020 ASSERT_NO_THROW(ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, error_handler))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, error_handler
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_3020; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3020
; } } else gtest_label_testnothrow_3020 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3020, ("Expected: " "ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, error_handler)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3021 EXPECT_EQ(2, errors_count_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("2", "errors_count_"
, 2, errors_count_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3021, gtest_ar.failure_message()) = ::testing::Message()
;
3022}
3023
3024// Test that no exception is thrown when a port is already bound but skip open
3025// flag is provided.
3026TEST_F(IfaceMgrTest, openSockets4SkipOpen)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSockets4SkipOpen") > 1, "test_name must not be empty"
); class IfaceMgrTest_openSockets4SkipOpen_Test : public IfaceMgrTest
{ public: IfaceMgrTest_openSockets4SkipOpen_Test() = default
; ~IfaceMgrTest_openSockets4SkipOpen_Test() override = default
; IfaceMgrTest_openSockets4SkipOpen_Test (const IfaceMgrTest_openSockets4SkipOpen_Test
&) = delete; IfaceMgrTest_openSockets4SkipOpen_Test &
operator=( const IfaceMgrTest_openSockets4SkipOpen_Test &
) = delete; IfaceMgrTest_openSockets4SkipOpen_Test (IfaceMgrTest_openSockets4SkipOpen_Test
&&) noexcept = delete; IfaceMgrTest_openSockets4SkipOpen_Test
& operator=( IfaceMgrTest_openSockets4SkipOpen_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_openSockets4SkipOpen_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSockets4SkipOpen", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3026), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3026), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3026), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_openSockets4SkipOpen_Test
>); void IfaceMgrTest_openSockets4SkipOpen_Test::TestBody(
)
{
3027 NakedIfaceMgr ifacemgr;
3028
3029 // Remove all real interfaces and create a set of dummy interfaces.
3030 ifacemgr.createIfaces();
3031
3032 boost::shared_ptr<TestPktFilter> custom_packet_filter(new TestPktFilter());
3033 ASSERT_TRUE(custom_packet_filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(custom_packet_filter)
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3033, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "custom_packet_filter", "false", "true") .c_str()) = ::testing
::Message()
;
3034 ASSERT_NO_THROW(ifacemgr.setPacketFilter(custom_packet_filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(custom_packet_filter); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3034; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3034; } } else gtest_label_testnothrow_3034
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3034, ("Expected: " "ifacemgr.setPacketFilter(custom_packet_filter)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3035
3036 // Open socket on eth1. The openSockets4 should detect that this
3037 // socket has been already open and an attempt to open another socket
3038 // and bind to this address and port should fail.
3039 ASSERT_NO_THROW(ifacemgr.openSocket("eth1", IOAddress("192.0.2.3"),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSocket("eth1", IOAddress("192.0.2.3"), DHCP4_SERVER_PORT
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_3040; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3040
; } } else gtest_label_testnothrow_3040 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3040, ("Expected: " "ifacemgr.openSocket(\"eth1\", IOAddress(\"192.0.2.3\"), DHCP4_SERVER_PORT)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
3040 DHCP4_SERVER_PORT))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSocket("eth1", IOAddress("192.0.2.3"), DHCP4_SERVER_PORT
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_3040; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3040
; } } else gtest_label_testnothrow_3040 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3040, ("Expected: " "ifacemgr.openSocket(\"eth1\", IOAddress(\"192.0.2.3\"), DHCP4_SERVER_PORT)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3041
3042 // The function doesn't throw an exception when it tries to open a socket
3043 // and bind it to the address in use but the skip open flag is provided.
3044 EXPECT_NO_THROW(ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0, true))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0, true); } else
static_assert(true, ""); } catch (std::exception const& e
) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3044; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3044; } } else gtest_label_testnothrow_3044
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3044, ("Expected: " "ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0, true)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3045
3046 // Check that the other port is bound.
3047 EXPECT_TRUE(ifacemgr.hasOpenSocket(IOAddress("10.0.0.1")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.hasOpenSocket
(IOAddress("10.0.0.1")))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3047, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.hasOpenSocket(IOAddress(\"10.0.0.1\"))", "false",
"true") .c_str()) = ::testing::Message()
;
3048}
3049
3050// This test verifies that the function correctly checks that the v4 socket is
3051// open and bound to a specific address.
3052TEST_F(IfaceMgrTest, hasOpenSocketForAddress4)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("hasOpenSocketForAddress4") > 1, "test_name must not be empty"
); class IfaceMgrTest_hasOpenSocketForAddress4_Test : public IfaceMgrTest
{ public: IfaceMgrTest_hasOpenSocketForAddress4_Test() = default
; ~IfaceMgrTest_hasOpenSocketForAddress4_Test() override = default
; IfaceMgrTest_hasOpenSocketForAddress4_Test (const IfaceMgrTest_hasOpenSocketForAddress4_Test
&) = delete; IfaceMgrTest_hasOpenSocketForAddress4_Test &
operator=( const IfaceMgrTest_hasOpenSocketForAddress4_Test &
) = delete; IfaceMgrTest_hasOpenSocketForAddress4_Test (IfaceMgrTest_hasOpenSocketForAddress4_Test
&&) noexcept = delete; IfaceMgrTest_hasOpenSocketForAddress4_Test
& operator=( IfaceMgrTest_hasOpenSocketForAddress4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_hasOpenSocketForAddress4_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "hasOpenSocketForAddress4", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3052), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3052), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3052), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_hasOpenSocketForAddress4_Test
>); void IfaceMgrTest_hasOpenSocketForAddress4_Test::TestBody
()
{
3053 NakedIfaceMgr ifacemgr;
3054
3055 // Remove all real interfaces and create a set of dummy interfaces.
3056 ifacemgr.createIfaces();
3057
3058 // Use the custom packet filter object. This object mimics the socket
3059 // opening operation - the real socket is not open.
3060 boost::shared_ptr<TestPktFilter> custom_packet_filter(new TestPktFilter());
3061 ASSERT_TRUE(custom_packet_filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(custom_packet_filter)
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3061, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "custom_packet_filter", "false", "true") .c_str()) = ::testing
::Message()
;
3062 ASSERT_NO_THROW(ifacemgr.setPacketFilter(custom_packet_filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(custom_packet_filter); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3062; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3062; } } else gtest_label_testnothrow_3062
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3062, ("Expected: " "ifacemgr.setPacketFilter(custom_packet_filter)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3063
3064 // Simulate opening sockets using the dummy packet filter.
3065 ASSERT_NO_THROW(ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3065; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3065; } } else gtest_label_testnothrow_3065
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3065, ("Expected: " "ifacemgr.openSockets4(DHCP4_SERVER_PORT, true, 0)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3066
3067 // Expect that the sockets are open on both eth0 and eth1.
3068 ASSERT_EQ(1U, ifacemgr.getIface("eth0")->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(\"eth0\")->getSockets().size()"
, 1U, ifacemgr.getIface("eth0")->getSockets().size()))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3068, gtest_ar.failure_message()) = ::testing::Message()
;
3069 ASSERT_EQ(1U, ifacemgr.getIface(ETH0_INDEX)->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(ETH0_INDEX)->getSockets().size()"
, 1U, ifacemgr.getIface(ETH0_INDEX)->getSockets().size()))
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3069, gtest_ar.failure_message()) = ::testing::Message()
;
3070 ASSERT_EQ(1U, ifacemgr.getIface("eth1")->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(\"eth1\")->getSockets().size()"
, 1U, ifacemgr.getIface("eth1")->getSockets().size()))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3070, gtest_ar.failure_message()) = ::testing::Message()
;
3071 ASSERT_EQ(1U, ifacemgr.getIface(ETH1_INDEX)->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(ETH1_INDEX)->getSockets().size()"
, 1U, ifacemgr.getIface(ETH1_INDEX)->getSockets().size()))
) ; else return ::testing::internal::AssertHelper(::testing::
TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3071, gtest_ar.failure_message()) = ::testing::Message()
;
3072 // Socket shouldn't have been opened on loopback.
3073 ASSERT_TRUE(ifacemgr.getIface("lo")->getSockets().empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface("lo"
)->getSockets().empty())) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3073, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(\"lo\")->getSockets().empty()", "false"
, "true") .c_str()) = ::testing::Message()
;
3074 ASSERT_TRUE(ifacemgr.getIface(LO_INDEX)->getSockets().empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface(LO_INDEX
)->getSockets().empty())) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3074, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(LO_INDEX)->getSockets().empty()", "false"
, "true") .c_str()) = ::testing::Message()
;
3075
3076 // Check that there are sockets bound to addresses that we have
3077 // set for interfaces.
3078 EXPECT_TRUE(ifacemgr.hasOpenSocket(IOAddress("192.0.2.3")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.hasOpenSocket
(IOAddress("192.0.2.3")))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3078, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.hasOpenSocket(IOAddress(\"192.0.2.3\"))", "false"
, "true") .c_str()) = ::testing::Message()
;
3079 EXPECT_TRUE(ifacemgr.hasOpenSocket(IOAddress("10.0.0.1")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.hasOpenSocket
(IOAddress("10.0.0.1")))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3079, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.hasOpenSocket(IOAddress(\"10.0.0.1\"))", "false",
"true") .c_str()) = ::testing::Message()
;
3080 // Check that there is no socket for the address which is not
3081 // configured on any interface.
3082 EXPECT_FALSE(ifacemgr.hasOpenSocket(IOAddress("10.1.1.1")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.hasOpenSocket
(IOAddress("10.1.1.1"))))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3082, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.hasOpenSocket(IOAddress(\"10.1.1.1\"))", "true", "false"
) .c_str()) = ::testing::Message()
;
3083
3084 // Check that v4 sockets are open, but no v6 socket is open.
3085 EXPECT_TRUE(ifacemgr.hasOpenSocket(AF_INET))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.hasOpenSocket
(2))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3085, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.hasOpenSocket(2)", "false", "true") .c_str()) = ::
testing::Message()
;
3086 EXPECT_FALSE(ifacemgr.hasOpenSocket(AF_INET6))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.hasOpenSocket
(10)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3086, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.hasOpenSocket(10)", "true", "false") .c_str()) = ::
testing::Message()
;
3087}
3088
3089// This test checks that the sockets are open and bound to link local addresses
3090// only, if unicast addresses are not specified.
3091TEST_F(IfaceMgrTest, openSockets6LinkLocal)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSockets6LinkLocal") > 1, "test_name must not be empty"
); class IfaceMgrTest_openSockets6LinkLocal_Test : public IfaceMgrTest
{ public: IfaceMgrTest_openSockets6LinkLocal_Test() = default
; ~IfaceMgrTest_openSockets6LinkLocal_Test() override = default
; IfaceMgrTest_openSockets6LinkLocal_Test (const IfaceMgrTest_openSockets6LinkLocal_Test
&) = delete; IfaceMgrTest_openSockets6LinkLocal_Test &
operator=( const IfaceMgrTest_openSockets6LinkLocal_Test &
) = delete; IfaceMgrTest_openSockets6LinkLocal_Test (IfaceMgrTest_openSockets6LinkLocal_Test
&&) noexcept = delete; IfaceMgrTest_openSockets6LinkLocal_Test
& operator=( IfaceMgrTest_openSockets6LinkLocal_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_openSockets6LinkLocal_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSockets6LinkLocal", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3091), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3091), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3091), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_openSockets6LinkLocal_Test
>); void IfaceMgrTest_openSockets6LinkLocal_Test::TestBody
()
{
3092 NakedIfaceMgr ifacemgr;
3093
3094 // Remove all real interfaces and create a set of dummy interfaces.
3095 ifacemgr.createIfaces();
3096
3097 boost::shared_ptr<PktFilter6IfaceSocketTest> filter(new PktFilter6IfaceSocketTest());
3098 ASSERT_TRUE(filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(filter)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3098, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "filter", "false", "true") .c_str()) = ::testing::Message()
;
3099 ASSERT_NO_THROW(ifacemgr.setPacketFilter(filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(filter); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3099
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3099
; } } else gtest_label_testnothrow_3099 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3099, ("Expected: " "ifacemgr.setPacketFilter(filter)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3100
3101 // Simulate opening sockets using the dummy packet filter.
3102 bool success = false;
3103 ASSERT_NO_THROW(success = ifacemgr.openSockets6(DHCP6_SERVER_PORT))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
success = ifacemgr.openSockets6(DHCP6_SERVER_PORT); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3103; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3103; } } else gtest_label_testnothrow_3103
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3103, ("Expected: " "success = ifacemgr.openSockets6(DHCP6_SERVER_PORT)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3104 EXPECT_TRUE(success)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(success)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3104, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"success", "false", "true") .c_str()) = ::testing::Message()
;
3105
3106 // Check that the number of sockets is correct on each interface.
3107 checkSocketsCount6(*ifacemgr.getIface("lo"), 0);
3108 checkSocketsCount6(*ifacemgr.getIface(LO_INDEX), 0);
3109 checkSocketsCount6(*ifacemgr.getIface("eth0"), 0);
3110 checkSocketsCount6(*ifacemgr.getIface(ETH0_INDEX), 0);
3111 checkSocketsCount6(*ifacemgr.getIface("eth1"), 0);
3112 checkSocketsCount6(*ifacemgr.getIface(ETH1_INDEX), 0);
3113
3114 // Sockets on eth0 should be bound to link-local and should not be bound
3115 // to global unicast address, even though this address is configured on
3116 // the eth0.
3117 EXPECT_TRUE(ifacemgr.isBound("eth0", "fe80::3a60:77ff:fed5:cdef"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth0"
, "fe80::3a60:77ff:fed5:cdef"))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3117, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"fe80::3a60:77ff:fed5:cdef\")"
, "false", "true") .c_str()) = ::testing::Message()
;
3118 EXPECT_FALSE(ifacemgr.isBound("eth0", "2001:db8:1::1"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth0"
, "2001:db8:1::1")))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3118, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"2001:db8:1::1\")", "true", "false"
) .c_str()) = ::testing::Message()
;
3119 // Socket on eth1 should be bound to link local only.
3120 EXPECT_TRUE(ifacemgr.isBound("eth1", "fe80::3a60:77ff:fed5:abcd"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "fe80::3a60:77ff:fed5:abcd"))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3120, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"fe80::3a60:77ff:fed5:abcd\")"
, "false", "true") .c_str()) = ::testing::Message()
;
3121
3122 // If we are on Linux, there are two more sockets bound to multicast
3123#if defined OS_LINUX
3124 EXPECT_TRUE(ifacemgr.isBound("eth0", ALL_DHCP_RELAY_AGENTS_AND_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth0"
, "ff02::1:2"))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3124, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"ff02::1:2\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3125 EXPECT_TRUE(ifacemgr.isBound("eth1", ALL_DHCP_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "ff05::1:3"))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3125, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"ff05::1:3\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3126 EXPECT_TRUE(ifacemgr.isBound("eth0", ALL_DHCP_RELAY_AGENTS_AND_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth0"
, "ff02::1:2"))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3126, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"ff02::1:2\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3127 EXPECT_TRUE(ifacemgr.isBound("eth1", ALL_DHCP_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "ff05::1:3"))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3127, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"ff05::1:3\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3128#endif
3129}
3130
3131// This test checks that the sockets are open on the loopback interface
3132// when the loopback is active and allowed.
3133TEST_F(IfaceMgrTest, openSockets6Loopback)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSockets6Loopback") > 1, "test_name must not be empty"
); class IfaceMgrTest_openSockets6Loopback_Test : public IfaceMgrTest
{ public: IfaceMgrTest_openSockets6Loopback_Test() = default
; ~IfaceMgrTest_openSockets6Loopback_Test() override = default
; IfaceMgrTest_openSockets6Loopback_Test (const IfaceMgrTest_openSockets6Loopback_Test
&) = delete; IfaceMgrTest_openSockets6Loopback_Test &
operator=( const IfaceMgrTest_openSockets6Loopback_Test &
) = delete; IfaceMgrTest_openSockets6Loopback_Test (IfaceMgrTest_openSockets6Loopback_Test
&&) noexcept = delete; IfaceMgrTest_openSockets6Loopback_Test
& operator=( IfaceMgrTest_openSockets6Loopback_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_openSockets6Loopback_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSockets6Loopback", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3133), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3133), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3133), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_openSockets6Loopback_Test
>); void IfaceMgrTest_openSockets6Loopback_Test::TestBody(
)
{
3134 NakedIfaceMgr ifacemgr;
3135
3136 // Remove all real interfaces and create a set of dummy interfaces.
3137 ifacemgr.createIfaces();
3138
3139 // Allow the loopback interface.
3140 ifacemgr.setAllowLoopBack(true);
3141
3142 // Make the loopback interface active.
3143 ifacemgr.getIface("lo")->inactive6_ = false;
3144
3145 // The loopback interface has no link-local (as for Linux but not BSD)
3146 // so add one.
3147 ifacemgr.getIface("lo")->addUnicast(IOAddress("::1"));
3148
3149 boost::shared_ptr<PktFilter6IfaceSocketTest> filter(new PktFilter6IfaceSocketTest());
3150 ASSERT_TRUE(filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(filter)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3150, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "filter", "false", "true") .c_str()) = ::testing::Message()
;
3151 ASSERT_NO_THROW(ifacemgr.setPacketFilter(filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(filter); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3151
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3151
; } } else gtest_label_testnothrow_3151 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3151, ("Expected: " "ifacemgr.setPacketFilter(filter)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3152
3153 // Simulate opening sockets using the dummy packet filter.
3154 bool success = false;
3155 ASSERT_NO_THROW(success = ifacemgr.openSockets6(DHCP6_SERVER_PORT))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
success = ifacemgr.openSockets6(DHCP6_SERVER_PORT); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3155; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3155; } } else gtest_label_testnothrow_3155
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3155, ("Expected: " "success = ifacemgr.openSockets6(DHCP6_SERVER_PORT)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3156 EXPECT_TRUE(success)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(success)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3156, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"success", "false", "true") .c_str()) = ::testing::Message()
;
3157
3158 // Check that the loopback interface has at least an open socket.
3159 EXPECT_EQ(1U, ifacemgr.getIface("lo")->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(\"lo\")->getSockets().size()"
, 1U, ifacemgr.getIface("lo")->getSockets().size()))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3159, gtest_ar.failure_message()) = ::testing::Message()
;
3160 EXPECT_EQ(1U, ifacemgr.getIface(LO_INDEX)->getSockets().size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "ifacemgr.getIface(LO_INDEX)->getSockets().size()"
, 1U, ifacemgr.getIface(LO_INDEX)->getSockets().size()))) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3160, gtest_ar.failure_message()) = ::testing::Message()
;
3161
3162 // This socket should be bound to ::1
3163 EXPECT_TRUE(ifacemgr.isBound("lo", "::1"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("lo"
, "::1"))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3163, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"lo\", \"::1\")", "false", "true") .c_str
()) = ::testing::Message()
;
3164}
3165
3166// This test checks that socket is not open on the interface which doesn't
3167// have a link-local address.
3168TEST_F(IfaceMgrTest, openSockets6NoLinkLocal)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSockets6NoLinkLocal") > 1, "test_name must not be empty"
); class IfaceMgrTest_openSockets6NoLinkLocal_Test : public IfaceMgrTest
{ public: IfaceMgrTest_openSockets6NoLinkLocal_Test() = default
; ~IfaceMgrTest_openSockets6NoLinkLocal_Test() override = default
; IfaceMgrTest_openSockets6NoLinkLocal_Test (const IfaceMgrTest_openSockets6NoLinkLocal_Test
&) = delete; IfaceMgrTest_openSockets6NoLinkLocal_Test &
operator=( const IfaceMgrTest_openSockets6NoLinkLocal_Test &
) = delete; IfaceMgrTest_openSockets6NoLinkLocal_Test (IfaceMgrTest_openSockets6NoLinkLocal_Test
&&) noexcept = delete; IfaceMgrTest_openSockets6NoLinkLocal_Test
& operator=( IfaceMgrTest_openSockets6NoLinkLocal_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_openSockets6NoLinkLocal_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSockets6NoLinkLocal", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3168), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3168), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3168), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_openSockets6NoLinkLocal_Test
>); void IfaceMgrTest_openSockets6NoLinkLocal_Test::TestBody
()
{
3169 NakedIfaceMgr ifacemgr;
3170
3171 // Remove all real interfaces and create a set of dummy interfaces.
3172 ifacemgr.createIfaces();
3173
3174 boost::shared_ptr<PktFilter6IfaceSocketTest> filter(new PktFilter6IfaceSocketTest());
3175 ASSERT_TRUE(filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(filter)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3175, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "filter", "false", "true") .c_str()) = ::testing::Message()
;
3176 ASSERT_NO_THROW(ifacemgr.setPacketFilter(filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(filter); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3176
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3176
; } } else gtest_label_testnothrow_3176 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3176, ("Expected: " "ifacemgr.setPacketFilter(filter)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3177
3178 // Remove a link local address from eth0. If there is no link-local
3179 // address, the socket should not open.
3180 ASSERT_TRUE(ifacemgr.getIface("eth0")->switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface("eth0"
)-> delAddress(IOAddress("fe80::3a60:77ff:fed5:cdef")))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3181, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(\"eth0\")-> delAddress(IOAddress(\"fe80::3a60:77ff:fed5:cdef\"))"
, "false", "true") .c_str()) = ::testing::Message()
3181 delAddress(IOAddress("fe80::3a60:77ff:fed5:cdef")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface("eth0"
)-> delAddress(IOAddress("fe80::3a60:77ff:fed5:cdef")))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3181, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(\"eth0\")-> delAddress(IOAddress(\"fe80::3a60:77ff:fed5:cdef\"))"
, "false", "true") .c_str()) = ::testing::Message()
;
3182
3183 // Simulate opening sockets using the dummy packet filter.
3184 bool success = false;
3185 ASSERT_NO_THROW(success = ifacemgr.openSockets6(DHCP6_SERVER_PORT))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
success = ifacemgr.openSockets6(DHCP6_SERVER_PORT); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3185; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3185; } } else gtest_label_testnothrow_3185
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3185, ("Expected: " "success = ifacemgr.openSockets6(DHCP6_SERVER_PORT)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3186 EXPECT_TRUE(success)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(success)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3186, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"success", "false", "true") .c_str()) = ::testing::Message()
;
3187
3188 // Check that the number of sockets is correct on each interface.
3189 checkSocketsCount6(*ifacemgr.getIface("lo"), 0);
3190 checkSocketsCount6(*ifacemgr.getIface(LO_INDEX), 0);
3191 // The third parameter specifies that the number of link-local
3192 // addresses for eth0 is equal to 0.
3193 checkSocketsCount6(*ifacemgr.getIface("eth0"), 0, 0);
3194 checkSocketsCount6(*ifacemgr.getIface(ETH0_INDEX), 0, 0);
3195 checkSocketsCount6(*ifacemgr.getIface("eth1"), 0, 1);
3196 checkSocketsCount6(*ifacemgr.getIface(ETH1_INDEX), 0, 1);
3197
3198 // There should be no sockets open on eth0 because it neither has
3199 // link-local nor global unicast addresses.
3200 EXPECT_FALSE(ifacemgr.isBound("eth0", "fe80::3a60:77ff:fed5:cdef"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth0"
, "fe80::3a60:77ff:fed5:cdef")))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3200, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"fe80::3a60:77ff:fed5:cdef\")"
, "true", "false") .c_str()) = ::testing::Message()
;
3201 EXPECT_FALSE(ifacemgr.isBound("eth0", "2001:db8:1::1"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth0"
, "2001:db8:1::1")))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3201, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"2001:db8:1::1\")", "true", "false"
) .c_str()) = ::testing::Message()
;
3202 // Socket on eth1 should be bound to link local only.
3203 EXPECT_TRUE(ifacemgr.isBound("eth1", "fe80::3a60:77ff:fed5:abcd"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "fe80::3a60:77ff:fed5:abcd"))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3203, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"fe80::3a60:77ff:fed5:abcd\")"
, "false", "true") .c_str()) = ::testing::Message()
;
3204
3205 // If we are on Linux, there are two more sockets bound to multicast
3206#if defined OS_LINUX
3207 EXPECT_FALSE(ifacemgr.isBound("eth0", ALL_DHCP_RELAY_AGENTS_AND_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth0"
, "ff02::1:2")))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3207, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"ff02::1:2\")", "true", "false"
) .c_str()) = ::testing::Message()
;
3208 EXPECT_FALSE(ifacemgr.isBound("eth0", ALL_DHCP_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth0"
, "ff05::1:3")))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3208, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"ff05::1:3\")", "true", "false"
) .c_str()) = ::testing::Message()
;
3209#endif
3210}
3211
3212// This test checks that socket is open on the non-multicast-capable
3213// interface. This socket simply doesn't join multicast group.
3214TEST_F(IfaceMgrTest, openSockets6NotMulticast)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSockets6NotMulticast") > 1, "test_name must not be empty"
); class IfaceMgrTest_openSockets6NotMulticast_Test : public IfaceMgrTest
{ public: IfaceMgrTest_openSockets6NotMulticast_Test() = default
; ~IfaceMgrTest_openSockets6NotMulticast_Test() override = default
; IfaceMgrTest_openSockets6NotMulticast_Test (const IfaceMgrTest_openSockets6NotMulticast_Test
&) = delete; IfaceMgrTest_openSockets6NotMulticast_Test &
operator=( const IfaceMgrTest_openSockets6NotMulticast_Test &
) = delete; IfaceMgrTest_openSockets6NotMulticast_Test (IfaceMgrTest_openSockets6NotMulticast_Test
&&) noexcept = delete; IfaceMgrTest_openSockets6NotMulticast_Test
& operator=( IfaceMgrTest_openSockets6NotMulticast_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_openSockets6NotMulticast_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSockets6NotMulticast", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3214), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3214), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3214), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_openSockets6NotMulticast_Test
>); void IfaceMgrTest_openSockets6NotMulticast_Test::TestBody
()
{
3215 NakedIfaceMgr ifacemgr;
3216
3217 // Remove all real interfaces and create a set of dummy interfaces.
3218 ifacemgr.createIfaces();
3219
3220 boost::shared_ptr<PktFilter6IfaceSocketTest> filter(new PktFilter6IfaceSocketTest());
3221 ASSERT_TRUE(filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(filter)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3221, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "filter", "false", "true") .c_str()) = ::testing::Message()
;
3222 ASSERT_NO_THROW(ifacemgr.setPacketFilter(filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(filter); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3222
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3222
; } } else gtest_label_testnothrow_3222 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3222, ("Expected: " "ifacemgr.setPacketFilter(filter)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3223
3224 // Make eth0 multicast-incapable.
3225 ifacemgr.getIface("eth0")->flag_multicast_ = false;
3226
3227 // Simulate opening sockets using the dummy packet filter.
3228 bool success = false;
3229 ASSERT_NO_THROW(success = ifacemgr.openSockets6(DHCP6_SERVER_PORT))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
success = ifacemgr.openSockets6(DHCP6_SERVER_PORT); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3229; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3229; } } else gtest_label_testnothrow_3229
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3229, ("Expected: " "success = ifacemgr.openSockets6(DHCP6_SERVER_PORT)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3230 EXPECT_TRUE(success)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(success)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3230, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"success", "false", "true") .c_str()) = ::testing::Message()
;
3231
3232 // Check that the number of sockets is correct on each interface.
3233 checkSocketsCount6(*ifacemgr.getIface("lo"), 0);
3234 checkSocketsCount6(*ifacemgr.getIface(LO_INDEX), 0);
3235 checkSocketsCount6(*ifacemgr.getIface("eth0"), 0);
3236 checkSocketsCount6(*ifacemgr.getIface(ETH0_INDEX), 0);
3237 checkSocketsCount6(*ifacemgr.getIface("eth1"), 0);
3238 checkSocketsCount6(*ifacemgr.getIface(ETH1_INDEX), 0);
3239
3240 // Sockets on eth0 should be bound to link-local and should not be bound
3241 // to global unicast address, even though this address is configured on
3242 // the eth0.
3243 EXPECT_TRUE(ifacemgr.isBound("eth0", "fe80::3a60:77ff:fed5:cdef"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth0"
, "fe80::3a60:77ff:fed5:cdef"))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3243, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"fe80::3a60:77ff:fed5:cdef\")"
, "false", "true") .c_str()) = ::testing::Message()
;
3244 EXPECT_FALSE(ifacemgr.isBound("eth0", "2001:db8:1::1"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth0"
, "2001:db8:1::1")))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3244, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"2001:db8:1::1\")", "true", "false"
) .c_str()) = ::testing::Message()
;
3245 // The eth0 is not a multicast-capable interface, so the socket should
3246 // not be bound to the multicast address.
3247 EXPECT_FALSE(ifacemgr.isBound("eth0", ALL_DHCP_RELAY_AGENTS_AND_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth0"
, "ff02::1:2")))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3247, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"ff02::1:2\")", "true", "false"
) .c_str()) = ::testing::Message()
;
3248 EXPECT_FALSE(ifacemgr.isBound("eth0", ALL_DHCP_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth0"
, "ff05::1:3")))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3248, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"ff05::1:3\")", "true", "false"
) .c_str()) = ::testing::Message()
;
3249 // Socket on eth1 should be bound to link local only.
3250 EXPECT_TRUE(ifacemgr.isBound("eth1", "fe80::3a60:77ff:fed5:abcd"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "fe80::3a60:77ff:fed5:abcd"))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3250, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"fe80::3a60:77ff:fed5:abcd\")"
, "false", "true") .c_str()) = ::testing::Message()
;
3251
3252 // If we are on Linux, there are two more sockets bound to multicast
3253 // on eth1.
3254#if defined OS_LINUX
3255 EXPECT_TRUE(ifacemgr.isBound("eth1", ALL_DHCP_RELAY_AGENTS_AND_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "ff02::1:2"))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3255, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"ff02::1:2\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3256 EXPECT_TRUE(ifacemgr.isBound("eth1", ALL_DHCP_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "ff05::1:3"))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3256, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"ff05::1:3\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3257#endif
3258}
3259
3260// This test checks that the sockets are opened and bound to link local
3261// and unicast addresses which have been explicitly specified.
3262TEST_F(IfaceMgrTest, openSockets6Unicast)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSockets6Unicast") > 1, "test_name must not be empty"
); class IfaceMgrTest_openSockets6Unicast_Test : public IfaceMgrTest
{ public: IfaceMgrTest_openSockets6Unicast_Test() = default;
~IfaceMgrTest_openSockets6Unicast_Test() override = default;
IfaceMgrTest_openSockets6Unicast_Test (const IfaceMgrTest_openSockets6Unicast_Test
&) = delete; IfaceMgrTest_openSockets6Unicast_Test &
operator=( const IfaceMgrTest_openSockets6Unicast_Test &
) = delete; IfaceMgrTest_openSockets6Unicast_Test (IfaceMgrTest_openSockets6Unicast_Test
&&) noexcept = delete; IfaceMgrTest_openSockets6Unicast_Test
& operator=( IfaceMgrTest_openSockets6Unicast_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_openSockets6Unicast_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSockets6Unicast", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3262), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3262), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3262), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_openSockets6Unicast_Test
>); void IfaceMgrTest_openSockets6Unicast_Test::TestBody()
{
3263 NakedIfaceMgr ifacemgr;
3264
3265 // Remove all real interfaces and create a set of dummy interfaces.
3266 ifacemgr.createIfaces();
3267
3268 boost::shared_ptr<PktFilter6IfaceSocketTest> filter(new PktFilter6IfaceSocketTest());
3269 ASSERT_TRUE(filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(filter)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3269, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "filter", "false", "true") .c_str()) = ::testing::Message()
;
3270 ASSERT_NO_THROW(ifacemgr.setPacketFilter(filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(filter); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3270
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3270
; } } else gtest_label_testnothrow_3270 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3270, ("Expected: " "ifacemgr.setPacketFilter(filter)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3271
3272 // Configure the eth0 to open socket on the unicast address, apart
3273 // from link-local address.
3274 ifacemgr.getIface("eth0")->addUnicast(IOAddress("2001:db8:1::1"));
3275
3276 // Simulate opening sockets using the dummy packet filter.
3277 bool success = false;
3278 ASSERT_NO_THROW(success = ifacemgr.openSockets6(DHCP6_SERVER_PORT))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
success = ifacemgr.openSockets6(DHCP6_SERVER_PORT); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3278; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3278; } } else gtest_label_testnothrow_3278
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3278, ("Expected: " "success = ifacemgr.openSockets6(DHCP6_SERVER_PORT)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3279 EXPECT_TRUE(success)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(success)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3279, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"success", "false", "true") .c_str()) = ::testing::Message()
;
3280
3281 // Check that we have correct number of sockets on each interface.
3282 checkSocketsCount6(*ifacemgr.getIface("lo"), 0);
3283 checkSocketsCount6(*ifacemgr.getIface(LO_INDEX), 0);
3284 checkSocketsCount6(*ifacemgr.getIface("eth0"), 1); // one unicast address.
3285 checkSocketsCount6(*ifacemgr.getIface(ETH0_INDEX), 1);
3286 checkSocketsCount6(*ifacemgr.getIface("eth1"), 0);
3287 checkSocketsCount6(*ifacemgr.getIface(ETH1_INDEX), 0);
3288
3289 // eth0 should have two sockets, one bound to link-local, another one
3290 // bound to unicast address.
3291 EXPECT_TRUE(ifacemgr.isBound("eth0", "fe80::3a60:77ff:fed5:cdef"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth0"
, "fe80::3a60:77ff:fed5:cdef"))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3291, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"fe80::3a60:77ff:fed5:cdef\")"
, "false", "true") .c_str()) = ::testing::Message()
;
3292 EXPECT_TRUE(ifacemgr.isBound("eth0", "2001:db8:1::1"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth0"
, "2001:db8:1::1"))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3292, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"2001:db8:1::1\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3293 // eth1 should have one socket, bound to link-local address.
3294 EXPECT_TRUE(ifacemgr.isBound("eth1", "fe80::3a60:77ff:fed5:abcd"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "fe80::3a60:77ff:fed5:abcd"))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3294, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"fe80::3a60:77ff:fed5:abcd\")"
, "false", "true") .c_str()) = ::testing::Message()
;
3295
3296 // If we are on Linux, there are two more sockets bound to multicast
3297#if defined OS_LINUX
3298 EXPECT_TRUE(ifacemgr.isBound("eth0", ALL_DHCP_RELAY_AGENTS_AND_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth0"
, "ff02::1:2"))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3298, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"ff02::1:2\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3299 EXPECT_TRUE(ifacemgr.isBound("eth1", ALL_DHCP_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "ff05::1:3"))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3299, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"ff05::1:3\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3300 EXPECT_TRUE(ifacemgr.isBound("eth0", ALL_DHCP_RELAY_AGENTS_AND_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth0"
, "ff02::1:2"))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3300, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"ff02::1:2\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3301 EXPECT_TRUE(ifacemgr.isBound("eth1", ALL_DHCP_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "ff05::1:3"))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3301, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"ff05::1:3\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3302#endif
3303}
3304
3305// This test checks that the socket is open and bound to a global unicast
3306// address if the link-local address does not exist for the particular
3307// interface.
3308TEST_F(IfaceMgrTest, openSockets6UnicastOnly)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSockets6UnicastOnly") > 1, "test_name must not be empty"
); class IfaceMgrTest_openSockets6UnicastOnly_Test : public IfaceMgrTest
{ public: IfaceMgrTest_openSockets6UnicastOnly_Test() = default
; ~IfaceMgrTest_openSockets6UnicastOnly_Test() override = default
; IfaceMgrTest_openSockets6UnicastOnly_Test (const IfaceMgrTest_openSockets6UnicastOnly_Test
&) = delete; IfaceMgrTest_openSockets6UnicastOnly_Test &
operator=( const IfaceMgrTest_openSockets6UnicastOnly_Test &
) = delete; IfaceMgrTest_openSockets6UnicastOnly_Test (IfaceMgrTest_openSockets6UnicastOnly_Test
&&) noexcept = delete; IfaceMgrTest_openSockets6UnicastOnly_Test
& operator=( IfaceMgrTest_openSockets6UnicastOnly_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_openSockets6UnicastOnly_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSockets6UnicastOnly", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3308), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3308), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3308), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_openSockets6UnicastOnly_Test
>); void IfaceMgrTest_openSockets6UnicastOnly_Test::TestBody
()
{
3309 NakedIfaceMgr ifacemgr;
3310
3311 // Remove all real interfaces and create a set of dummy interfaces.
3312 ifacemgr.createIfaces();
3313
3314 boost::shared_ptr<PktFilter6IfaceSocketTest> filter(new PktFilter6IfaceSocketTest());
3315 ASSERT_TRUE(filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(filter)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3315, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "filter", "false", "true") .c_str()) = ::testing::Message()
;
3316 ASSERT_NO_THROW(ifacemgr.setPacketFilter(filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(filter); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3316
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3316
; } } else gtest_label_testnothrow_3316 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3316, ("Expected: " "ifacemgr.setPacketFilter(filter)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3317
3318 // Configure the eth0 to open socket on the unicast address, apart
3319 // from link-local address.
3320 ifacemgr.getIface("eth0")->addUnicast(IOAddress("2001:db8:1::1"));
3321 // Explicitly remove the link-local address from eth0.
3322 ASSERT_TRUE(ifacemgr.getIface("eth0")->switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface("eth0"
)-> delAddress(IOAddress("fe80::3a60:77ff:fed5:cdef")))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3323, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(\"eth0\")-> delAddress(IOAddress(\"fe80::3a60:77ff:fed5:cdef\"))"
, "false", "true") .c_str()) = ::testing::Message()
3323 delAddress(IOAddress("fe80::3a60:77ff:fed5:cdef")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface("eth0"
)-> delAddress(IOAddress("fe80::3a60:77ff:fed5:cdef")))) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3323, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(\"eth0\")-> delAddress(IOAddress(\"fe80::3a60:77ff:fed5:cdef\"))"
, "false", "true") .c_str()) = ::testing::Message()
;
3324
3325 // Simulate opening sockets using the dummy packet filter.
3326 bool success = false;
3327 ASSERT_NO_THROW(success = ifacemgr.openSockets6(DHCP6_SERVER_PORT))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
success = ifacemgr.openSockets6(DHCP6_SERVER_PORT); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3327; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3327; } } else gtest_label_testnothrow_3327
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3327, ("Expected: " "success = ifacemgr.openSockets6(DHCP6_SERVER_PORT)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3328 EXPECT_TRUE(success)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(success)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3328, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"success", "false", "true") .c_str()) = ::testing::Message()
;
3329
3330 // Check that we have correct number of sockets on each interface.
3331 checkSocketsCount6(*ifacemgr.getIface("lo"), 0);
3332 checkSocketsCount6(*ifacemgr.getIface(LO_INDEX), 0);
3333 checkSocketsCount6(*ifacemgr.getIface("eth0"), 1, 0);
3334 checkSocketsCount6(*ifacemgr.getIface(ETH0_INDEX), 1, 0);
3335 checkSocketsCount6(*ifacemgr.getIface("eth1"), 0);
3336 checkSocketsCount6(*ifacemgr.getIface(ETH1_INDEX), 0);
3337
3338 // The link-local address is not present on eth0. Therefore, no socket
3339 // must be bound to this address, nor to multicast address.
3340 EXPECT_FALSE(ifacemgr.isBound("eth0", "fe80::3a60:77ff:fed5:cdef"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth0"
, "fe80::3a60:77ff:fed5:cdef")))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3340, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"fe80::3a60:77ff:fed5:cdef\")"
, "true", "false") .c_str()) = ::testing::Message()
;
3341 EXPECT_FALSE(ifacemgr.isBound("eth0", ALL_DHCP_RELAY_AGENTS_AND_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth0"
, "ff02::1:2")))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3341, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"ff02::1:2\")", "true", "false"
) .c_str()) = ::testing::Message()
;
3342 EXPECT_FALSE(ifacemgr.isBound("eth0", ALL_DHCP_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth0"
, "ff05::1:3")))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3342, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"ff05::1:3\")", "true", "false"
) .c_str()) = ::testing::Message()
;
3343 // There should be one socket bound to unicast address.
3344 EXPECT_TRUE(ifacemgr.isBound("eth0", "2001:db8:1::1"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth0"
, "2001:db8:1::1"))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3344, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"2001:db8:1::1\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3345 // eth1 should have one socket, bound to link-local address.
3346 EXPECT_TRUE(ifacemgr.isBound("eth1", "fe80::3a60:77ff:fed5:abcd"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "fe80::3a60:77ff:fed5:abcd"))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3346, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"fe80::3a60:77ff:fed5:abcd\")"
, "false", "true") .c_str()) = ::testing::Message()
;
3347
3348 // If we are on Linux, there are two more sockets bound to multicast
3349#if defined OS_LINUX
3350 EXPECT_TRUE(ifacemgr.isBound("eth1", ALL_DHCP_RELAY_AGENTS_AND_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "ff02::1:2"))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3350, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"ff02::1:2\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3351 EXPECT_TRUE(ifacemgr.isBound("eth1", ALL_DHCP_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "ff05::1:3"))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3351, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"ff05::1:3\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3352#endif
3353}
3354
3355// This test checks that no sockets are open for the interface which is down.
3356TEST_F(IfaceMgrTest, openSockets6IfaceDown)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSockets6IfaceDown") > 1, "test_name must not be empty"
); class IfaceMgrTest_openSockets6IfaceDown_Test : public IfaceMgrTest
{ public: IfaceMgrTest_openSockets6IfaceDown_Test() = default
; ~IfaceMgrTest_openSockets6IfaceDown_Test() override = default
; IfaceMgrTest_openSockets6IfaceDown_Test (const IfaceMgrTest_openSockets6IfaceDown_Test
&) = delete; IfaceMgrTest_openSockets6IfaceDown_Test &
operator=( const IfaceMgrTest_openSockets6IfaceDown_Test &
) = delete; IfaceMgrTest_openSockets6IfaceDown_Test (IfaceMgrTest_openSockets6IfaceDown_Test
&&) noexcept = delete; IfaceMgrTest_openSockets6IfaceDown_Test
& operator=( IfaceMgrTest_openSockets6IfaceDown_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_openSockets6IfaceDown_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSockets6IfaceDown", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3356), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3356), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3356), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_openSockets6IfaceDown_Test
>); void IfaceMgrTest_openSockets6IfaceDown_Test::TestBody
()
{
3357 NakedIfaceMgr ifacemgr;
3358
3359 // Remove all real interfaces and create a set of dummy interfaces.
3360 ifacemgr.createIfaces();
3361
3362 boost::shared_ptr<PktFilter6IfaceSocketTest> filter(new PktFilter6IfaceSocketTest());
3363 ASSERT_TRUE(filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(filter)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3363, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "filter", "false", "true") .c_str()) = ::testing::Message()
;
3364 ASSERT_NO_THROW(ifacemgr.setPacketFilter(filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(filter); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3364
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3364
; } } else gtest_label_testnothrow_3364 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3364, ("Expected: " "ifacemgr.setPacketFilter(filter)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3365
3366 // Configure the eth0 to open socket on the unicast address, apart
3367 // from link-local address.
3368 ifacemgr.getIface("eth0")->addUnicast(IOAddress("2001:db8:1::1"));
3369
3370 // Boolean parameters specify that eth0 is:
3371 // - not a loopback
3372 // - is "down" (not up)
3373 // - is not running
3374 // - is active for both v4 and v6
3375 ifacemgr.setIfaceFlags("eth0", false, false, false, false, false);
3376
3377 // Install an error handler before trying to open sockets. This handler
3378 // should be called when the IfaceMgr fails to open socket on eth0.
3379 isc::dhcp::IfaceMgrErrorMsgCallback error_handler =
3380 std::bind(&IfaceMgrTest::ifaceMgrErrorHandler, this, ph::_1);
3381
3382 // Simulate opening sockets using the dummy packet filter.
3383 bool success = false;
3384 ASSERT_NO_THROW(success = ifacemgr.openSockets6(DHCP6_SERVER_PORT,switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
success = ifacemgr.openSockets6(DHCP6_SERVER_PORT, error_handler
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_3385; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3385
; } } else gtest_label_testnothrow_3385 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3385, ("Expected: " "success = ifacemgr.openSockets6(DHCP6_SERVER_PORT, error_handler)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
3385 error_handler))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
success = ifacemgr.openSockets6(DHCP6_SERVER_PORT, error_handler
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_3385; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3385
; } } else gtest_label_testnothrow_3385 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3385, ("Expected: " "success = ifacemgr.openSockets6(DHCP6_SERVER_PORT, error_handler)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3386 EXPECT_TRUE(success)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(success)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3386, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"success", "false", "true") .c_str()) = ::testing::Message()
;
3387
3388 // Opening socket on the interface which is not configured, should
3389 // result in error.
3390 EXPECT_EQ(1, errors_count_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "errors_count_"
, 1, errors_count_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3390, gtest_ar.failure_message()) = ::testing::Message()
;
3391
3392 // Check that we have correct number of sockets on each interface.
3393 checkSocketsCount6(*ifacemgr.getIface("lo"), 0);
3394 checkSocketsCount6(*ifacemgr.getIface(LO_INDEX), 0);
3395 // There should be no sockets on eth0 because interface is down.
3396 ASSERT_TRUE(ifacemgr.getIface("eth0")->getSockets().empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface("eth0"
)->getSockets().empty())) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3396, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(\"eth0\")->getSockets().empty()", "false"
, "true") .c_str()) = ::testing::Message()
;
3397 ASSERT_TRUE(ifacemgr.getIface(ETH0_INDEX)->getSockets().empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface(ETH0_INDEX
)->getSockets().empty())) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3397, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(ETH0_INDEX)->getSockets().empty()", "false"
, "true") .c_str()) = ::testing::Message()
;
3398 checkSocketsCount6(*ifacemgr.getIface("eth1"), 0);
3399 checkSocketsCount6(*ifacemgr.getIface(ETH1_INDEX), 0);
3400
3401 // eth0 should have no sockets because the interface is down.
3402 EXPECT_FALSE(ifacemgr.isBound("eth0", "fe80::3a60:77ff:fed5:cdef"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth0"
, "fe80::3a60:77ff:fed5:cdef")))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3402, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"fe80::3a60:77ff:fed5:cdef\")"
, "true", "false") .c_str()) = ::testing::Message()
;
3403 EXPECT_FALSE(ifacemgr.isBound("eth0", "2001:db8:1::1"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth0"
, "2001:db8:1::1")))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3403, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"2001:db8:1::1\")", "true", "false"
) .c_str()) = ::testing::Message()
;
3404 EXPECT_FALSE(ifacemgr.isBound("eth0", ALL_DHCP_RELAY_AGENTS_AND_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth0"
, "ff02::1:2")))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3404, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"ff02::1:2\")", "true", "false"
) .c_str()) = ::testing::Message()
;
3405 EXPECT_FALSE(ifacemgr.isBound("eth0", ALL_DHCP_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth0"
, "ff05::1:3")))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3405, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"ff05::1:3\")", "true", "false"
) .c_str()) = ::testing::Message()
;
3406 // eth1 should have one socket, bound to link-local address.
3407 EXPECT_TRUE(ifacemgr.isBound("eth1", "fe80::3a60:77ff:fed5:abcd"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "fe80::3a60:77ff:fed5:abcd"))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3407, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"fe80::3a60:77ff:fed5:abcd\")"
, "false", "true") .c_str()) = ::testing::Message()
;
3408
3409 // If we are on Linux, there are two more sockets bound to multicast
3410#if defined OS_LINUX
3411 EXPECT_TRUE(ifacemgr.isBound("eth1", ALL_DHCP_RELAY_AGENTS_AND_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "ff02::1:2"))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3411, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"ff02::1:2\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3412 EXPECT_TRUE(ifacemgr.isBound("eth1", ALL_DHCP_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "ff05::1:3"))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3412, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"ff05::1:3\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3413#endif
3414}
3415
3416// This test checks that no sockets are open for the interface which is
3417// inactive.
3418TEST_F(IfaceMgrTest, openSockets6IfaceInactive)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSockets6IfaceInactive") > 1, "test_name must not be empty"
); class IfaceMgrTest_openSockets6IfaceInactive_Test : public
IfaceMgrTest { public: IfaceMgrTest_openSockets6IfaceInactive_Test
() = default; ~IfaceMgrTest_openSockets6IfaceInactive_Test() override
= default; IfaceMgrTest_openSockets6IfaceInactive_Test (const
IfaceMgrTest_openSockets6IfaceInactive_Test &) = delete;
IfaceMgrTest_openSockets6IfaceInactive_Test & operator=(
const IfaceMgrTest_openSockets6IfaceInactive_Test &) = delete
; IfaceMgrTest_openSockets6IfaceInactive_Test (IfaceMgrTest_openSockets6IfaceInactive_Test
&&) noexcept = delete; IfaceMgrTest_openSockets6IfaceInactive_Test
& operator=( IfaceMgrTest_openSockets6IfaceInactive_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_openSockets6IfaceInactive_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSockets6IfaceInactive", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3418), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3418), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3418), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_openSockets6IfaceInactive_Test
>); void IfaceMgrTest_openSockets6IfaceInactive_Test::TestBody
()
{
3419 NakedIfaceMgr ifacemgr;
3420
3421 // Remove all real interfaces and create a set of dummy interfaces.
3422 ifacemgr.createIfaces();
3423
3424 boost::shared_ptr<PktFilter6IfaceSocketTest> filter(new PktFilter6IfaceSocketTest());
3425 ASSERT_TRUE(filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(filter)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3425, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "filter", "false", "true") .c_str()) = ::testing::Message()
;
3426 ASSERT_NO_THROW(ifacemgr.setPacketFilter(filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(filter); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3426
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3426
; } } else gtest_label_testnothrow_3426 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3426, ("Expected: " "ifacemgr.setPacketFilter(filter)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3427
3428 // Configure the eth0 to open socket on the unicast address, apart
3429 // from link-local address.
3430 ifacemgr.getIface("eth0")->addUnicast(IOAddress("2001:db8:1::1"));
3431
3432 // Boolean parameters specify that eth1 is:
3433 // - not a loopback
3434 // - is up
3435 // - is running
3436 // - is active for v4
3437 // - is inactive for v6
3438 ifacemgr.setIfaceFlags("eth1", false, true, true, false, true);
3439
3440 // Simulate opening sockets using the dummy packet filter.
3441 bool success = false;
3442 ASSERT_NO_THROW(success = ifacemgr.openSockets6(DHCP6_SERVER_PORT))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
success = ifacemgr.openSockets6(DHCP6_SERVER_PORT); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3442; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3442; } } else gtest_label_testnothrow_3442
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3442, ("Expected: " "success = ifacemgr.openSockets6(DHCP6_SERVER_PORT)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3443 EXPECT_TRUE(success)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(success)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3443, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"success", "false", "true") .c_str()) = ::testing::Message()
;
3444
3445 // Check that we have correct number of sockets on each interface.
3446 checkSocketsCount6(*ifacemgr.getIface("lo"), 0);
3447 checkSocketsCount6(*ifacemgr.getIface(LO_INDEX), 0);
3448 checkSocketsCount6(*ifacemgr.getIface("eth0"), 1); // one unicast address
3449 checkSocketsCount6(*ifacemgr.getIface(ETH0_INDEX), 1);
3450 // There should be no sockets on eth1 because interface is inactive
3451 ASSERT_TRUE(ifacemgr.getIface("eth1")->getSockets().empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface("eth1"
)->getSockets().empty())) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3451, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(\"eth1\")->getSockets().empty()", "false"
, "true") .c_str()) = ::testing::Message()
;
3452 ASSERT_TRUE(ifacemgr.getIface(ETH1_INDEX)->getSockets().empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.getIface(ETH1_INDEX
)->getSockets().empty())) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3452, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.getIface(ETH1_INDEX)->getSockets().empty()", "false"
, "true") .c_str()) = ::testing::Message()
;
3453
3454 // eth0 should have one socket bound to a link-local address, another one
3455 // bound to unicast address.
3456 EXPECT_TRUE(ifacemgr.isBound("eth0", "fe80::3a60:77ff:fed5:cdef"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth0"
, "fe80::3a60:77ff:fed5:cdef"))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3456, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"fe80::3a60:77ff:fed5:cdef\")"
, "false", "true") .c_str()) = ::testing::Message()
;
3457 EXPECT_TRUE(ifacemgr.isBound("eth0", "2001:db8:1::1"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth0"
, "2001:db8:1::1"))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3457, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"2001:db8:1::1\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3458
3459 // eth1 shouldn't have a socket bound to link local address because
3460 // interface is inactive.
3461 EXPECT_FALSE(ifacemgr.isBound("eth1", "fe80::3a60:77ff:fed5:abcd"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth1"
, "fe80::3a60:77ff:fed5:abcd")))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3461, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"fe80::3a60:77ff:fed5:abcd\")"
, "true", "false") .c_str()) = ::testing::Message()
;
3462 EXPECT_FALSE(ifacemgr.isBound("eth1", ALL_DHCP_RELAY_AGENTS_AND_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth1"
, "ff02::1:2")))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3462, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"ff02::1:2\")", "true", "false"
) .c_str()) = ::testing::Message()
;
3463 EXPECT_FALSE(ifacemgr.isBound("eth1", ALL_DHCP_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.isBound("eth1"
, "ff05::1:3")))) ; else ::testing::internal::AssertHelper(::
testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3463, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"ff05::1:3\")", "true", "false"
) .c_str()) = ::testing::Message()
;
3464
3465 // If we are on Linux, there are two more sockets bound to multicast
3466#if defined OS_LINUX
3467 EXPECT_TRUE(ifacemgr.isBound("eth0", ALL_DHCP_RELAY_AGENTS_AND_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth0"
, "ff02::1:2"))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3467, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"ff02::1:2\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3468 EXPECT_TRUE(ifacemgr.isBound("eth0", ALL_DHCP_SERVERS))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth0"
, "ff05::1:3"))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3468, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"ff05::1:3\")", "false", "true"
) .c_str()) = ::testing::Message()
;
3469#endif
3470}
3471
3472// Test that the openSockets6 function does not throw if there are no interfaces
3473// detected. This function is expected to return false.
3474TEST_F(IfaceMgrTest, openSockets6NoIfaces)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSockets6NoIfaces") > 1, "test_name must not be empty"
); class IfaceMgrTest_openSockets6NoIfaces_Test : public IfaceMgrTest
{ public: IfaceMgrTest_openSockets6NoIfaces_Test() = default
; ~IfaceMgrTest_openSockets6NoIfaces_Test() override = default
; IfaceMgrTest_openSockets6NoIfaces_Test (const IfaceMgrTest_openSockets6NoIfaces_Test
&) = delete; IfaceMgrTest_openSockets6NoIfaces_Test &
operator=( const IfaceMgrTest_openSockets6NoIfaces_Test &
) = delete; IfaceMgrTest_openSockets6NoIfaces_Test (IfaceMgrTest_openSockets6NoIfaces_Test
&&) noexcept = delete; IfaceMgrTest_openSockets6NoIfaces_Test
& operator=( IfaceMgrTest_openSockets6NoIfaces_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_openSockets6NoIfaces_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSockets6NoIfaces", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3474), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3474), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3474), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_openSockets6NoIfaces_Test
>); void IfaceMgrTest_openSockets6NoIfaces_Test::TestBody(
)
{
3475 NakedIfaceMgr ifacemgr;
3476 // Remove existing interfaces.
3477 ifacemgr.clearIfaces();
3478
3479 boost::shared_ptr<PktFilter6IfaceSocketTest> filter(new PktFilter6IfaceSocketTest());
3480 ASSERT_TRUE(filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(filter)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3480, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "filter", "false", "true") .c_str()) = ::testing::Message()
;
3481 ASSERT_NO_THROW(ifacemgr.setPacketFilter(filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(filter); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3481
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3481
; } } else gtest_label_testnothrow_3481 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3481, ("Expected: " "ifacemgr.setPacketFilter(filter)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3482
3483 // This value indicates if at least one socket opens. There are no
3484 // interfaces, so it should be set to false.
3485 bool socket_open = false;
3486 ASSERT_NO_THROW(socket_open = ifacemgr.openSockets6(DHCP6_SERVER_PORT))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
socket_open = ifacemgr.openSockets6(DHCP6_SERVER_PORT); } else
static_assert(true, ""); } catch (std::exception const& e
) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3486; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3486; } } else gtest_label_testnothrow_3486
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3486, ("Expected: " "socket_open = ifacemgr.openSockets6(DHCP6_SERVER_PORT)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3487 EXPECT_FALSE(socket_open)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(socket_open))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3487, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "socket_open", "true", "false") .c_str()) = ::testing::Message
()
;
3488}
3489
3490// Test that the external error handler is called when trying to bind a new
3491// socket to the address and port being in use. The sockets on the other
3492// interfaces should open just fine.
3493TEST_F(IfaceMgrTest, openSockets6ErrorHandler)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSockets6ErrorHandler") > 1, "test_name must not be empty"
); class IfaceMgrTest_openSockets6ErrorHandler_Test : public IfaceMgrTest
{ public: IfaceMgrTest_openSockets6ErrorHandler_Test() = default
; ~IfaceMgrTest_openSockets6ErrorHandler_Test() override = default
; IfaceMgrTest_openSockets6ErrorHandler_Test (const IfaceMgrTest_openSockets6ErrorHandler_Test
&) = delete; IfaceMgrTest_openSockets6ErrorHandler_Test &
operator=( const IfaceMgrTest_openSockets6ErrorHandler_Test &
) = delete; IfaceMgrTest_openSockets6ErrorHandler_Test (IfaceMgrTest_openSockets6ErrorHandler_Test
&&) noexcept = delete; IfaceMgrTest_openSockets6ErrorHandler_Test
& operator=( IfaceMgrTest_openSockets6ErrorHandler_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_openSockets6ErrorHandler_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSockets6ErrorHandler", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3493), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3493), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3493), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_openSockets6ErrorHandler_Test
>); void IfaceMgrTest_openSockets6ErrorHandler_Test::TestBody
()
{
3494 NakedIfaceMgr ifacemgr;
3495
3496 // Remove all real interfaces and create a set of dummy interfaces.
3497 ifacemgr.createIfaces();
3498
3499 boost::shared_ptr<PktFilter6Stub> filter(new PktFilter6Stub());
3500 ASSERT_TRUE(filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(filter)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3500, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "filter", "false", "true") .c_str()) = ::testing::Message()
;
3501 ASSERT_NO_THROW(ifacemgr.setPacketFilter(filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(filter); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3501
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3501
; } } else gtest_label_testnothrow_3501 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3501, ("Expected: " "ifacemgr.setPacketFilter(filter)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3502
3503 // Open multicast socket on eth0.
3504 ASSERT_NO_THROW(ifacemgr.openSocket("eth0",switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSocket("eth0", IOAddress("fe80::3a60:77ff:fed5:cdef"
), DHCP6_SERVER_PORT, true); } else static_assert(true, ""); }
catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3506
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3506
; } } else gtest_label_testnothrow_3506 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3506, ("Expected: " "ifacemgr.openSocket(\"eth0\", IOAddress(\"fe80::3a60:77ff:fed5:cdef\"), DHCP6_SERVER_PORT, true)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
3505 IOAddress("fe80::3a60:77ff:fed5:cdef"),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSocket("eth0", IOAddress("fe80::3a60:77ff:fed5:cdef"
), DHCP6_SERVER_PORT, true); } else static_assert(true, ""); }
catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3506
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3506
; } } else gtest_label_testnothrow_3506 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3506, ("Expected: " "ifacemgr.openSocket(\"eth0\", IOAddress(\"fe80::3a60:77ff:fed5:cdef\"), DHCP6_SERVER_PORT, true)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
3506 DHCP6_SERVER_PORT, true))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSocket("eth0", IOAddress("fe80::3a60:77ff:fed5:cdef"
), DHCP6_SERVER_PORT, true); } else static_assert(true, ""); }
catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3506
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3506
; } } else gtest_label_testnothrow_3506 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3506, ("Expected: " "ifacemgr.openSocket(\"eth0\", IOAddress(\"fe80::3a60:77ff:fed5:cdef\"), DHCP6_SERVER_PORT, true)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3507
3508 // Install an error handler before trying to open sockets. This handler
3509 // should be called when the IfaceMgr fails to open socket on eth0.
3510 isc::dhcp::IfaceMgrErrorMsgCallback error_handler =
3511 std::bind(&IfaceMgrTest::ifaceMgrErrorHandler, this, ph::_1);
3512 // The openSockets6 should detect that a socket has been already
3513 // opened on eth0 and an attempt to open another socket and bind to
3514 // the same address and port should fail.
3515 ASSERT_NO_THROW(ifacemgr.openSockets6(DHCP6_SERVER_PORT, error_handler))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSockets6(DHCP6_SERVER_PORT, error_handler); } else
static_assert(true, ""); } catch (std::exception const& e
) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3515; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3515; } } else gtest_label_testnothrow_3515
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3515, ("Expected: " "ifacemgr.openSockets6(DHCP6_SERVER_PORT, error_handler)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3516 // We expect that an error occurred when we tried to open a socket on
3517 // eth0, but the socket on eth1 should open just fine.
3518 EXPECT_EQ(1, errors_count_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1", "errors_count_"
, 1, errors_count_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3518, gtest_ar.failure_message()) = ::testing::Message()
;
3519
3520 // Reset errors count.
3521 errors_count_ = 0;
3522
3523 // Now that we have two sockets open, we can try this again but this time
3524 // we should get two errors: one when opening a socket on eth0, another one
3525 // when opening a socket on eth1.
3526 ASSERT_NO_THROW(ifacemgr.openSockets6(DHCP6_SERVER_PORT, error_handler))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSockets6(DHCP6_SERVER_PORT, error_handler); } else
static_assert(true, ""); } catch (std::exception const& e
) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3526; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3526; } } else gtest_label_testnothrow_3526
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3526, ("Expected: " "ifacemgr.openSockets6(DHCP6_SERVER_PORT, error_handler)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3527 EXPECT_EQ(2, errors_count_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("2", "errors_count_"
, 2, errors_count_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3527, gtest_ar.failure_message()) = ::testing::Message()
;
3528}
3529
3530// Test that no exception is thrown when a port is already bound but skip open
3531// flag is provided.
3532TEST_F(IfaceMgrTest, openSockets6SkipOpen)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("openSockets6SkipOpen") > 1, "test_name must not be empty"
); class IfaceMgrTest_openSockets6SkipOpen_Test : public IfaceMgrTest
{ public: IfaceMgrTest_openSockets6SkipOpen_Test() = default
; ~IfaceMgrTest_openSockets6SkipOpen_Test() override = default
; IfaceMgrTest_openSockets6SkipOpen_Test (const IfaceMgrTest_openSockets6SkipOpen_Test
&) = delete; IfaceMgrTest_openSockets6SkipOpen_Test &
operator=( const IfaceMgrTest_openSockets6SkipOpen_Test &
) = delete; IfaceMgrTest_openSockets6SkipOpen_Test (IfaceMgrTest_openSockets6SkipOpen_Test
&&) noexcept = delete; IfaceMgrTest_openSockets6SkipOpen_Test
& operator=( IfaceMgrTest_openSockets6SkipOpen_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_openSockets6SkipOpen_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "openSockets6SkipOpen", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3532), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3532), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3532), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_openSockets6SkipOpen_Test
>); void IfaceMgrTest_openSockets6SkipOpen_Test::TestBody(
)
{
3533 NakedIfaceMgr ifacemgr;
3534
3535 // Remove all real interfaces and create a set of dummy interfaces.
3536 ifacemgr.createIfaces();
3537
3538 boost::shared_ptr<PktFilter6IfaceSocketTest> filter(new PktFilter6IfaceSocketTest());
3539 ASSERT_TRUE(filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(filter)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3539, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "filter", "false", "true") .c_str()) = ::testing::Message()
;
3540 ASSERT_NO_THROW(ifacemgr.setPacketFilter(filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(filter); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3540
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3540
; } } else gtest_label_testnothrow_3540 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3540, ("Expected: " "ifacemgr.setPacketFilter(filter)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3541
3542 // Open socket on eth0. The openSockets6 should detect that this
3543 // socket has been already open and an attempt to open another socket
3544 // and bind to this address and port should fail.
3545 ASSERT_NO_THROW(ifacemgr.openSocket("eth0",switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSocket("eth0", IOAddress("fe80::3a60:77ff:fed5:cdef"
), DHCP6_SERVER_PORT, true); } else static_assert(true, ""); }
catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3547
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3547
; } } else gtest_label_testnothrow_3547 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3547, ("Expected: " "ifacemgr.openSocket(\"eth0\", IOAddress(\"fe80::3a60:77ff:fed5:cdef\"), DHCP6_SERVER_PORT, true)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
3546 IOAddress("fe80::3a60:77ff:fed5:cdef"),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSocket("eth0", IOAddress("fe80::3a60:77ff:fed5:cdef"
), DHCP6_SERVER_PORT, true); } else static_assert(true, ""); }
catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3547
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3547
; } } else gtest_label_testnothrow_3547 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3547, ("Expected: " "ifacemgr.openSocket(\"eth0\", IOAddress(\"fe80::3a60:77ff:fed5:cdef\"), DHCP6_SERVER_PORT, true)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
3547 DHCP6_SERVER_PORT, true))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSocket("eth0", IOAddress("fe80::3a60:77ff:fed5:cdef"
), DHCP6_SERVER_PORT, true); } else static_assert(true, ""); }
catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3547
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3547
; } } else gtest_label_testnothrow_3547 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3547, ("Expected: " "ifacemgr.openSocket(\"eth0\", IOAddress(\"fe80::3a60:77ff:fed5:cdef\"), DHCP6_SERVER_PORT, true)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3548
3549 // The function doesn't throw an exception when it tries to open a socket
3550 // and bind it to the address in use but the skip open flag is provided.
3551 EXPECT_NO_THROW(ifacemgr.openSockets6(DHCP6_SERVER_PORT, 0, true))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.openSockets6(DHCP6_SERVER_PORT, 0, true); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3551; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3551; } } else gtest_label_testnothrow_3551
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3551, ("Expected: " "ifacemgr.openSockets6(DHCP6_SERVER_PORT, 0, true)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3552
3553 // Check that the other port is bound.
3554 EXPECT_TRUE(ifacemgr.isBound("eth1", "fe80::3a60:77ff:fed5:abcd"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "fe80::3a60:77ff:fed5:abcd"))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3554, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"fe80::3a60:77ff:fed5:abcd\")"
, "false", "true") .c_str()) = ::testing::Message()
;
3555}
3556
3557// This test verifies that the function correctly checks that the v6 socket is
3558// open and bound to a specific address.
3559TEST_F(IfaceMgrTest, hasOpenSocketForAddress6)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("hasOpenSocketForAddress6") > 1, "test_name must not be empty"
); class IfaceMgrTest_hasOpenSocketForAddress6_Test : public IfaceMgrTest
{ public: IfaceMgrTest_hasOpenSocketForAddress6_Test() = default
; ~IfaceMgrTest_hasOpenSocketForAddress6_Test() override = default
; IfaceMgrTest_hasOpenSocketForAddress6_Test (const IfaceMgrTest_hasOpenSocketForAddress6_Test
&) = delete; IfaceMgrTest_hasOpenSocketForAddress6_Test &
operator=( const IfaceMgrTest_hasOpenSocketForAddress6_Test &
) = delete; IfaceMgrTest_hasOpenSocketForAddress6_Test (IfaceMgrTest_hasOpenSocketForAddress6_Test
&&) noexcept = delete; IfaceMgrTest_hasOpenSocketForAddress6_Test
& operator=( IfaceMgrTest_hasOpenSocketForAddress6_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_hasOpenSocketForAddress6_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "hasOpenSocketForAddress6", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3559), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3559), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3559), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_hasOpenSocketForAddress6_Test
>); void IfaceMgrTest_hasOpenSocketForAddress6_Test::TestBody
()
{
3560 NakedIfaceMgr ifacemgr;
3561
3562 // Remove all real interfaces and create a set of dummy interfaces.
3563 ifacemgr.createIfaces();
3564
3565 boost::shared_ptr<PktFilter6IfaceSocketTest> filter(new PktFilter6IfaceSocketTest());
3566 ASSERT_TRUE(filter)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(filter)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3566, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "filter", "false", "true") .c_str()) = ::testing::Message()
;
3567 ASSERT_NO_THROW(ifacemgr.setPacketFilter(filter))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr.setPacketFilter(filter); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3567
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3567
; } } else gtest_label_testnothrow_3567 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3567, ("Expected: " "ifacemgr.setPacketFilter(filter)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3568
3569 ifacemgr.getIface("eth0")->addUnicast(IOAddress("2001:db8:1::1"));
3570 ifacemgr.getIface("eth1")->addAddress(IOAddress("3001:db8:1::1"));
3571
3572 // Simulate opening sockets using the dummy packet filter.
3573 bool success = false;
3574 ASSERT_NO_THROW(success = ifacemgr.openSockets6(DHCP6_SERVER_PORT))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
success = ifacemgr.openSockets6(DHCP6_SERVER_PORT); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3574; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3574; } } else gtest_label_testnothrow_3574
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3574, ("Expected: " "success = ifacemgr.openSockets6(DHCP6_SERVER_PORT)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3575 EXPECT_TRUE(success)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(success)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3575, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"success", "false", "true") .c_str()) = ::testing::Message()
;
3576
3577 // Make sure that the sockets are bound as expected.
3578 ASSERT_TRUE(ifacemgr.isBound("eth0", "fe80::3a60:77ff:fed5:cdef"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth0"
, "fe80::3a60:77ff:fed5:cdef"))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3578, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth0\", \"fe80::3a60:77ff:fed5:cdef\")"
, "false", "true") .c_str()) = ::testing::Message()
;
3579 EXPECT_TRUE(ifacemgr.isBound("eth1", "fe80::3a60:77ff:fed5:abcd"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.isBound("eth1"
, "fe80::3a60:77ff:fed5:abcd"))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3579, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.isBound(\"eth1\", \"fe80::3a60:77ff:fed5:abcd\")"
, "false", "true") .c_str()) = ::testing::Message()
;
3580
3581 // There should be v6 sockets only, no v4 sockets.
3582 EXPECT_TRUE(ifacemgr.hasOpenSocket(AF_INET6))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.hasOpenSocket
(10))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3582, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.hasOpenSocket(10)", "false", "true") .c_str()) = ::
testing::Message()
;
3583 EXPECT_FALSE(ifacemgr.hasOpenSocket(AF_INET))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.hasOpenSocket
(2)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3583, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.hasOpenSocket(2)", "true", "false") .c_str()) = ::
testing::Message()
;
3584
3585 // Check that there are sockets bound to the addresses we have configured
3586 // for interfaces.
3587 EXPECT_TRUE(ifacemgr.hasOpenSocket(IOAddress("fe80::3a60:77ff:fed5:cdef")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.hasOpenSocket
(IOAddress("fe80::3a60:77ff:fed5:cdef")))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3587, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"ifacemgr.hasOpenSocket(IOAddress(\"fe80::3a60:77ff:fed5:cdef\"))"
, "false", "true") .c_str()) = ::testing::Message()
;
3588 EXPECT_TRUE(ifacemgr.hasOpenSocket(IOAddress("fe80::3a60:77ff:fed5:abcd")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.hasOpenSocket
(IOAddress("fe80::3a60:77ff:fed5:abcd")))) ; else ::testing::
internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3588, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"ifacemgr.hasOpenSocket(IOAddress(\"fe80::3a60:77ff:fed5:abcd\"))"
, "false", "true") .c_str()) = ::testing::Message()
;
3589 EXPECT_TRUE(ifacemgr.hasOpenSocket(IOAddress("2001:db8:1::1")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.hasOpenSocket
(IOAddress("2001:db8:1::1")))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3589, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.hasOpenSocket(IOAddress(\"2001:db8:1::1\"))", "false"
, "true") .c_str()) = ::testing::Message()
;
3590 EXPECT_TRUE(ifacemgr.hasOpenSocket(IOAddress("2001:db8:1::1"), true))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.hasOpenSocket
(IOAddress("2001:db8:1::1"), true))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3590, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.hasOpenSocket(IOAddress(\"2001:db8:1::1\"), true)"
, "false", "true") .c_str()) = ::testing::Message()
;
3591 if (ifacemgr.hasOpenSocket(IOAddress("::"))) {
3592 // On BSD binding is done using "::" when address is multicast which
3593 // makes the address match interface address.
3594 EXPECT_TRUE(ifacemgr.hasOpenSocket(IOAddress("3001:db8:1::1")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr.hasOpenSocket
(IOAddress("3001:db8:1::1")))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3594, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.hasOpenSocket(IOAddress(\"3001:db8:1::1\"))", "false"
, "true") .c_str()) = ::testing::Message()
;
3595 } else {
3596 // On Linux binding is done using link-local and all-servers address
3597 // when address is multicast.
3598 EXPECT_FALSE(ifacemgr.hasOpenSocket(IOAddress("3001:db8:1::1")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.hasOpenSocket
(IOAddress("3001:db8:1::1"))))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3598, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.hasOpenSocket(IOAddress(\"3001:db8:1::1\"))", "true"
, "false") .c_str()) = ::testing::Message()
;
3599 }
3600 EXPECT_FALSE(ifacemgr.hasOpenSocket(IOAddress("3001:db8:1::1"), true))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.hasOpenSocket
(IOAddress("3001:db8:1::1"), true)))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3600, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.hasOpenSocket(IOAddress(\"3001:db8:1::1\"), true)"
, "true", "false") .c_str()) = ::testing::Message()
;
3601 // Check that there is no socket bound to the address which hasn't been
3602 // configured on any interface.
3603 EXPECT_FALSE(ifacemgr.hasOpenSocket(IOAddress("fe80::3a60:77ff:feed:1")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr.hasOpenSocket
(IOAddress("fe80::3a60:77ff:feed:1"))))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3603, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr.hasOpenSocket(IOAddress(\"fe80::3a60:77ff:feed:1\"))"
, "true", "false") .c_str()) = ::testing::Message()
;
3604}
3605
3606// Test the Iface structure itself
3607TEST_F(IfaceMgrTest, family)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("family") > 1, "test_name must not be empty"
); class IfaceMgrTest_family_Test : public IfaceMgrTest { public
: IfaceMgrTest_family_Test() = default; ~IfaceMgrTest_family_Test
() override = default; IfaceMgrTest_family_Test (const IfaceMgrTest_family_Test
&) = delete; IfaceMgrTest_family_Test & operator=( const
IfaceMgrTest_family_Test &) = delete; IfaceMgrTest_family_Test
(IfaceMgrTest_family_Test &&) noexcept = delete; IfaceMgrTest_family_Test
& operator=( IfaceMgrTest_family_Test &&) noexcept
= delete; private: void TestBody() override; [[maybe_unused]
] static ::testing::TestInfo* const test_info_; }; ::testing::
TestInfo* const IfaceMgrTest_family_Test::test_info_ = ::testing
::internal::MakeAndRegisterTestInfo( "IfaceMgrTest", "family"
, nullptr, nullptr, ::testing::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3607), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3607), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3607), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_family_Test
>); void IfaceMgrTest_family_Test::TestBody()
{
3608 NakedIfaceMgr ifacemgr;
3609 EXPECT_EQ(ifacemgr.getFamily(), AF_INET)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ifacemgr.getFamily()"
, "2", ifacemgr.getFamily(), 2))) ; else ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3609, gtest_ar.failure_message()) = ::testing::Message()
;
3610 ifacemgr.setFamily(AF_INET610);
3611 EXPECT_EQ(ifacemgr.getFamily(), AF_INET6)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("ifacemgr.getFamily()"
, "10", ifacemgr.getFamily(), 10))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3611, gtest_ar.failure_message()) = ::testing::Message()
;
3612}
3613
3614// Test the Iface structure itself
3615TEST_F(IfaceMgrTest, iface)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("iface") > 1, "test_name must not be empty"
); class IfaceMgrTest_iface_Test : public IfaceMgrTest { public
: IfaceMgrTest_iface_Test() = default; ~IfaceMgrTest_iface_Test
() override = default; IfaceMgrTest_iface_Test (const IfaceMgrTest_iface_Test
&) = delete; IfaceMgrTest_iface_Test & operator=( const
IfaceMgrTest_iface_Test &) = delete; IfaceMgrTest_iface_Test
(IfaceMgrTest_iface_Test &&) noexcept = delete; IfaceMgrTest_iface_Test
& operator=( IfaceMgrTest_iface_Test &&) noexcept
= delete; private: void TestBody() override; [[maybe_unused]
] static ::testing::TestInfo* const test_info_; }; ::testing::
TestInfo* const IfaceMgrTest_iface_Test::test_info_ = ::testing
::internal::MakeAndRegisterTestInfo( "IfaceMgrTest", "iface",
nullptr, nullptr, ::testing::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3615), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3615), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3615), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_iface_Test
>); void IfaceMgrTest_iface_Test::TestBody()
{
3616 boost::scoped_ptr<Iface> iface;
3617 EXPECT_NO_THROW(iface.reset(new Iface("eth0",1)))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface.reset(new Iface("eth0",1)); } else static_assert(true,
""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3617
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3617
; } } else gtest_label_testnothrow_3617 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3617, ("Expected: " "iface.reset(new Iface(\"eth0\",1))" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3618
3619 EXPECT_EQ("eth0", iface->getName())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"eth0\""
, "iface->getName()", "eth0", iface->getName()))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3619, gtest_ar.failure_message()) = ::testing::Message()
;
3620 EXPECT_EQ(1U, iface->getIndex())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "iface->getIndex()"
, 1U, iface->getIndex()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3620, gtest_ar.failure_message()) = ::testing::Message()
;
3621 EXPECT_EQ("eth0/1", iface->getFullName())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"eth0/1\""
, "iface->getFullName()", "eth0/1", iface->getFullName(
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3621, gtest_ar.failure_message()) = ::testing::Message()
;
3622
3623 // Let's make a copy of this address collection.
3624 Iface::AddressCollection addrs = iface->getAddresses();
3625
3626 EXPECT_EQ(0U, addrs.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "addrs.size()"
, 0U, addrs.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3626, gtest_ar.failure_message()) = ::testing::Message()
;
3627
3628 IOAddress addr1("192.0.2.6");
3629 iface->addAddress(addr1);
3630
3631 addrs = iface->getAddresses();
3632 ASSERT_EQ(1U, addrs.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "addrs.size()"
, 1U, addrs.size()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3632, gtest_ar.failure_message()) = ::testing::Message()
;
3633 EXPECT_EQ("192.0.2.6", addrs.begin()->get().toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.6\""
, "addrs.begin()->get().toText()", "192.0.2.6", addrs.begin
()->get().toText()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3633, gtest_ar.failure_message()) = ::testing::Message()
;
3634
3635 // No such address, should return false.
3636 EXPECT_FALSE(iface->delAddress(IOAddress("192.0.8.9")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(iface->delAddress
(IOAddress("192.0.8.9"))))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3636, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface->delAddress(IOAddress(\"192.0.8.9\"))", "true", "false"
) .c_str()) = ::testing::Message()
;
3637
3638 // This address is present, delete it!
3639 EXPECT_TRUE(iface->delAddress(IOAddress("192.0.2.6")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface->delAddress(
IOAddress("192.0.2.6")))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3639, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface->delAddress(IOAddress(\"192.0.2.6\"))", "false", "true"
) .c_str()) = ::testing::Message()
;
3640
3641 // Not really necessary, previous reference still points to the same
3642 // collection. Let's do it anyway, as test code may serve as example
3643 // usage code as well.
3644 addrs = iface->getAddresses();
3645
3646 EXPECT_EQ(0U, addrs.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "addrs.size()"
, 0U, addrs.size()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3646, gtest_ar.failure_message()) = ::testing::Message()
;
3647
3648 EXPECT_NO_THROW(iface.reset())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface.reset(); } else static_assert(true, ""); } catch (std::
exception const& e) { gtest_msg.value = "it throws "; gtest_msg
.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg
.value += " with description \""; gtest_msg.value += e.what()
; gtest_msg.value += "\"."; goto gtest_label_testnothrow_3648
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3648
; } } else gtest_label_testnothrow_3648 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3648, ("Expected: " "iface.reset()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
3649}
3650
3651TEST_F(IfaceMgrTest, iface_methods)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("iface_methods") > 1, "test_name must not be empty"
); class IfaceMgrTest_iface_methods_Test : public IfaceMgrTest
{ public: IfaceMgrTest_iface_methods_Test() = default; ~IfaceMgrTest_iface_methods_Test
() override = default; IfaceMgrTest_iface_methods_Test (const
IfaceMgrTest_iface_methods_Test &) = delete; IfaceMgrTest_iface_methods_Test
& operator=( const IfaceMgrTest_iface_methods_Test &
) = delete; IfaceMgrTest_iface_methods_Test (IfaceMgrTest_iface_methods_Test
&&) noexcept = delete; IfaceMgrTest_iface_methods_Test
& operator=( IfaceMgrTest_iface_methods_Test &&)
noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_iface_methods_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "iface_methods", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3651), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3651), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3651), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_iface_methods_Test
>); void IfaceMgrTest_iface_methods_Test::TestBody()
{
3652 Iface iface("foo", 1234);
3653
3654 iface.setHWType(42);
3655 EXPECT_EQ(42U, iface.getHWType())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("42U", "iface.getHWType()"
, 42U, iface.getHWType()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3655, gtest_ar.failure_message()) = ::testing::Message()
;
3656
3657 ASSERT_LT(Iface::MAX_MAC_LEN + 10, 255U)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLT("Iface::MAX_MAC_LEN + 10"
, "255U", Iface::MAX_MAC_LEN + 10, 255U))) ; else return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3657, gtest_ar
.failure_message()) = ::testing::Message()
;
3658
3659 uint8_t mac[Iface::MAX_MAC_LEN + 10];
3660 for (uint8_t i = 0; i < Iface::MAX_MAC_LEN + 10; i++) {
3661 mac[i] = 255 - i;
3662 }
3663
3664 EXPECT_EQ("foo", iface.getName())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"foo\""
, "iface.getName()", "foo", iface.getName()))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3664, gtest_ar
.failure_message()) = ::testing::Message()
;
3665 EXPECT_EQ(1234U, iface.getIndex())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1234U", "iface.getIndex()"
, 1234U, iface.getIndex()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3665, gtest_ar.failure_message()) = ::testing::Message()
;
3666
3667 // MAC is too long. Exception should be thrown and
3668 // MAC length should not be set.
3669 EXPECT_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { iface.setMac(mac, Iface::
MAX_MAC_LEN + 1); } else static_assert(true, ""); } catch (OutOfRange
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< OutOfRange>::type>
::type, std::exception>::value, const ::testing::internal::
NeverThrown&, const std::exception&>::type e) { gtest_msg
.value = "Expected: " "iface.setMac(mac, Iface::MAX_MAC_LEN + 1)"
" throws an exception of type " "OutOfRange" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_3672
; } catch (...) { gtest_msg.value = "Expected: " "iface.setMac(mac, Iface::MAX_MAC_LEN + 1)"
" throws an exception of type " "OutOfRange" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3672; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "iface.setMac(mac, Iface::MAX_MAC_LEN + 1)"
" throws an exception of type " "OutOfRange" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3672; } } else gtest_label_testthrow_3672
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3672, gtest_msg.value.c_str()) = ::testing::Message()
3670 iface.setMac(mac, Iface::MAX_MAC_LEN + 1),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { iface.setMac(mac, Iface::
MAX_MAC_LEN + 1); } else static_assert(true, ""); } catch (OutOfRange
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< OutOfRange>::type>
::type, std::exception>::value, const ::testing::internal::
NeverThrown&, const std::exception&>::type e) { gtest_msg
.value = "Expected: " "iface.setMac(mac, Iface::MAX_MAC_LEN + 1)"
" throws an exception of type " "OutOfRange" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_3672
; } catch (...) { gtest_msg.value = "Expected: " "iface.setMac(mac, Iface::MAX_MAC_LEN + 1)"
" throws an exception of type " "OutOfRange" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3672; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "iface.setMac(mac, Iface::MAX_MAC_LEN + 1)"
" throws an exception of type " "OutOfRange" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3672; } } else gtest_label_testthrow_3672
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3672, gtest_msg.value.c_str()) = ::testing::Message()
3671 OutOfRangeswitch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { iface.setMac(mac, Iface::
MAX_MAC_LEN + 1); } else static_assert(true, ""); } catch (OutOfRange
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< OutOfRange>::type>
::type, std::exception>::value, const ::testing::internal::
NeverThrown&, const std::exception&>::type e) { gtest_msg
.value = "Expected: " "iface.setMac(mac, Iface::MAX_MAC_LEN + 1)"
" throws an exception of type " "OutOfRange" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_3672
; } catch (...) { gtest_msg.value = "Expected: " "iface.setMac(mac, Iface::MAX_MAC_LEN + 1)"
" throws an exception of type " "OutOfRange" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3672; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "iface.setMac(mac, Iface::MAX_MAC_LEN + 1)"
" throws an exception of type " "OutOfRange" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3672; } } else gtest_label_testthrow_3672
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3672, gtest_msg.value.c_str()) = ::testing::Message()
3672 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { iface.setMac(mac, Iface::
MAX_MAC_LEN + 1); } else static_assert(true, ""); } catch (OutOfRange
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< OutOfRange>::type>
::type, std::exception>::value, const ::testing::internal::
NeverThrown&, const std::exception&>::type e) { gtest_msg
.value = "Expected: " "iface.setMac(mac, Iface::MAX_MAC_LEN + 1)"
" throws an exception of type " "OutOfRange" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_3672
; } catch (...) { gtest_msg.value = "Expected: " "iface.setMac(mac, Iface::MAX_MAC_LEN + 1)"
" throws an exception of type " "OutOfRange" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3672; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "iface.setMac(mac, Iface::MAX_MAC_LEN + 1)"
" throws an exception of type " "OutOfRange" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3672; } } else gtest_label_testthrow_3672
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3672, gtest_msg.value.c_str()) = ::testing::Message()
;
3673
3674 // MAC length should stay not set as exception was thrown.
3675 EXPECT_EQ(0U, iface.getMacLen())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "iface.getMacLen()"
, 0U, iface.getMacLen()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3675, gtest_ar.failure_message()) = ::testing::Message()
;
3676
3677 // Setting maximum length MAC should be ok.
3678 iface.setMac(mac, Iface::MAX_MAC_LEN);
3679
3680 // For some reason constants cannot be used directly in EXPECT_EQ
3681 // as this produces linking error.
3682 size_t len = Iface::MAX_MAC_LEN;
3683 EXPECT_EQ(len, iface.getMacLen())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("len", "iface.getMacLen()"
, len, iface.getMacLen()))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3683, gtest_ar.failure_message()) = ::testing::Message()
;
3684 EXPECT_EQ(0, memcmp(mac, iface.getMac(), iface.getMacLen()))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "memcmp(mac, iface.getMac(), iface.getMacLen())"
, 0, memcmp(mac, iface.getMac(), iface.getMacLen())))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3684, gtest_ar.failure_message()) = ::testing::Message()
;
3685}
3686
3687TEST_F(IfaceMgrTest, socketInfo)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("socketInfo") > 1, "test_name must not be empty"
); class IfaceMgrTest_socketInfo_Test : public IfaceMgrTest {
public: IfaceMgrTest_socketInfo_Test() = default; ~IfaceMgrTest_socketInfo_Test
() override = default; IfaceMgrTest_socketInfo_Test (const IfaceMgrTest_socketInfo_Test
&) = delete; IfaceMgrTest_socketInfo_Test & operator
=( const IfaceMgrTest_socketInfo_Test &) = delete; IfaceMgrTest_socketInfo_Test
(IfaceMgrTest_socketInfo_Test &&) noexcept = delete;
IfaceMgrTest_socketInfo_Test & operator=( IfaceMgrTest_socketInfo_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_socketInfo_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "socketInfo", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3687), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3687), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3687), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_socketInfo_Test
>); void IfaceMgrTest_socketInfo_Test::TestBody()
{
3688
3689 // Check that socketinfo for IPv4 socket is functional
3690 SocketInfo sock1(IOAddress("192.0.2.56"), DHCP4_SERVER_PORT + 7, 7);
3691 EXPECT_EQ(7, sock1.sockfd_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("7", "sock1.sockfd_"
, 7, sock1.sockfd_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3691, gtest_ar.failure_message()) = ::testing::Message()
;
3692 EXPECT_EQ(-1, sock1.fallbackfd_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("-1", "sock1.fallbackfd_"
, -1, sock1.fallbackfd_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3692, gtest_ar.failure_message()) = ::testing::Message()
;
3693 EXPECT_EQ("192.0.2.56", sock1.addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.56\""
, "sock1.addr_.toText()", "192.0.2.56", sock1.addr_.toText())
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3693, gtest_ar.failure_message()) = ::testing::Message()
;
3694 EXPECT_EQ(AF_INET, sock1.family_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("2", "sock1.family_"
, 2, sock1.family_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3694, gtest_ar.failure_message()) = ::testing::Message()
;
3695 EXPECT_EQ(DHCP4_SERVER_PORT + 7, sock1.port_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("DHCP4_SERVER_PORT + 7"
, "sock1.port_", DHCP4_SERVER_PORT + 7, sock1.port_))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3695, gtest_ar.failure_message()) = ::testing::Message()
;
3696
3697 // Check that non-default value of the fallback socket descriptor is set
3698 SocketInfo sock2(IOAddress("192.0.2.53"), DHCP4_SERVER_PORT + 8, 8, 10);
3699 EXPECT_EQ(8, sock2.sockfd_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("8", "sock2.sockfd_"
, 8, sock2.sockfd_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3699, gtest_ar.failure_message()) = ::testing::Message()
;
3700 EXPECT_EQ(10, sock2.fallbackfd_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("10", "sock2.fallbackfd_"
, 10, sock2.fallbackfd_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3700, gtest_ar.failure_message()) = ::testing::Message()
;
3701 EXPECT_EQ("192.0.2.53", sock2.addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.53\""
, "sock2.addr_.toText()", "192.0.2.53", sock2.addr_.toText())
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3701, gtest_ar.failure_message()) = ::testing::Message()
;
3702 EXPECT_EQ(AF_INET, sock2.family_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("2", "sock2.family_"
, 2, sock2.family_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3702, gtest_ar.failure_message()) = ::testing::Message()
;
3703 EXPECT_EQ(DHCP4_SERVER_PORT + 8, sock2.port_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("DHCP4_SERVER_PORT + 8"
, "sock2.port_", DHCP4_SERVER_PORT + 8, sock2.port_))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3703, gtest_ar.failure_message()) = ::testing::Message()
;
3704
3705 // Check that socketinfo for IPv6 socket is functional
3706 SocketInfo sock3(IOAddress("2001:db8:1::56"), DHCP4_SERVER_PORT + 9, 9);
3707 EXPECT_EQ(9, sock3.sockfd_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("9", "sock3.sockfd_"
, 9, sock3.sockfd_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3707, gtest_ar.failure_message()) = ::testing::Message()
;
3708 EXPECT_EQ(-1, sock3.fallbackfd_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("-1", "sock3.fallbackfd_"
, -1, sock3.fallbackfd_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3708, gtest_ar.failure_message()) = ::testing::Message()
;
3709 EXPECT_EQ("2001:db8:1::56", sock3.addr_.toText())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("\"2001:db8:1::56\""
, "sock3.addr_.toText()", "2001:db8:1::56", sock3.addr_.toText
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3709, gtest_ar.failure_message()) = ::testing::Message()
;
3710 EXPECT_EQ(AF_INET6, sock3.family_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("10", "sock3.family_"
, 10, sock3.family_))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3710, gtest_ar.failure_message()) = ::testing::Message()
;
3711 EXPECT_EQ(DHCP4_SERVER_PORT + 9, sock3.port_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("DHCP4_SERVER_PORT + 9"
, "sock3.port_", DHCP4_SERVER_PORT + 9, sock3.port_))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3711, gtest_ar.failure_message()) = ::testing::Message()
;
3712
3713 // Now let's test if IfaceMgr handles socket info properly
3714 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
3715 IfacePtr loopback = ifacemgr->getIface(LOOPBACK_NAME);
3716 ASSERT_TRUE(loopback)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(loopback)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3716, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "loopback", "false", "true") .c_str()) = ::testing::Message
()
;
3717 loopback->addSocket(sock1);
3718 loopback->addSocket(sock2);
3719 loopback->addSocket(sock3);
3720
3721 Pkt6Ptr pkt6(new Pkt6(DHCPV6_REPLY, 123456));
3722
3723 // pkt6 does not have interface set yet
3724 EXPECT_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt6
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt6)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3727; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3727; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3727; } } else gtest_label_testthrow_3727
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3727, gtest_msg.value.c_str()) = ::testing::Message()
3725 ifacemgr->getSocket(pkt6),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt6
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt6)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3727; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3727; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3727; } } else gtest_label_testthrow_3727
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3727, gtest_msg.value.c_str()) = ::testing::Message()
3726 IfaceNotFoundswitch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt6
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt6)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3727; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3727; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3727; } } else gtest_label_testthrow_3727
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3727, gtest_msg.value.c_str()) = ::testing::Message()
3727 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt6
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt6)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3727; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3727; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3727; } } else gtest_label_testthrow_3727
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3727, gtest_msg.value.c_str()) = ::testing::Message()
;
3728
3729 // Try to send over non-existing interface
3730 pkt6->setIface("nosuchinterface45");
3731 pkt6->setIndex(12345);
3732 EXPECT_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt6
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt6)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3735; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3735; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3735; } } else gtest_label_testthrow_3735
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3735, gtest_msg.value.c_str()) = ::testing::Message()
3733 ifacemgr->getSocket(pkt6),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt6
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt6)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3735; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3735; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3735; } } else gtest_label_testthrow_3735
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3735, gtest_msg.value.c_str()) = ::testing::Message()
3734 IfaceNotFoundswitch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt6
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt6)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3735; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3735; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3735; } } else gtest_label_testthrow_3735
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3735, gtest_msg.value.c_str()) = ::testing::Message()
3735 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt6
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt6)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3735; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3735; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3735; } } else gtest_label_testthrow_3735
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3735, gtest_msg.value.c_str()) = ::testing::Message()
;
3736
3737 // Index is now checked first
3738 pkt6->setIface(LOOPBACK_NAME);
3739 EXPECT_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt6
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt6)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3742; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3742; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3742; } } else gtest_label_testthrow_3742
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3742, gtest_msg.value.c_str()) = ::testing::Message()
3740 ifacemgr->getSocket(pkt6),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt6
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt6)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3742; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3742; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3742; } } else gtest_label_testthrow_3742
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3742, gtest_msg.value.c_str()) = ::testing::Message()
3741 IfaceNotFoundswitch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt6
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt6)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3742; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3742; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3742; } } else gtest_label_testthrow_3742
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3742, gtest_msg.value.c_str()) = ::testing::Message()
3742 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt6
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt6)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3742; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3742; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3742; } } else gtest_label_testthrow_3742
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3742, gtest_msg.value.c_str()) = ::testing::Message()
;
3743
3744 // This will work
3745 pkt6->setIndex(LOOPBACK_INDEX);
3746 EXPECT_EQ(9U, ifacemgr->getSocket(pkt6))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("9U", "ifacemgr->getSocket(pkt6)"
, 9U, ifacemgr->getSocket(pkt6)))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3746, gtest_ar.failure_message()) = ::testing::Message()
;
3747
3748 bool deleted = false;
3749 EXPECT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
deleted = ifacemgr->getIface(LOOPBACK_NAME)->delSocket
(9);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_3751; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3751
; } } else gtest_label_testnothrow_3751 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3751, ("Expected: " "deleted = ifacemgr->getIface(LOOPBACK_NAME)->delSocket(9);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
3750 deleted = ifacemgr->getIface(LOOPBACK_NAME)->delSocket(9);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
deleted = ifacemgr->getIface(LOOPBACK_NAME)->delSocket
(9);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_3751; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3751
; } } else gtest_label_testnothrow_3751 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3751, ("Expected: " "deleted = ifacemgr->getIface(LOOPBACK_NAME)->delSocket(9);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
3751 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
deleted = ifacemgr->getIface(LOOPBACK_NAME)->delSocket
(9);; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_3751; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3751
; } } else gtest_label_testnothrow_3751 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3751, ("Expected: " "deleted = ifacemgr->getIface(LOOPBACK_NAME)->delSocket(9);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3752 EXPECT_TRUE(deleted)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(deleted)) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3752, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"deleted", "false", "true") .c_str()) = ::testing::Message()
;
3753
3754 // It should throw again, there's no usable socket anymore
3755 EXPECT_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt6
); } else static_assert(true, ""); } catch (SocketNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< SocketNotFound>::type>::type
, std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt6)" " throws an exception of type "
"SocketNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3758; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "SocketNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3758; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "SocketNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3758; } } else gtest_label_testthrow_3758
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3758, gtest_msg.value.c_str()) = ::testing::Message()
3756 ifacemgr->getSocket(pkt6),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt6
); } else static_assert(true, ""); } catch (SocketNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< SocketNotFound>::type>::type
, std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt6)" " throws an exception of type "
"SocketNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3758; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "SocketNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3758; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "SocketNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3758; } } else gtest_label_testthrow_3758
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3758, gtest_msg.value.c_str()) = ::testing::Message()
3757 SocketNotFoundswitch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt6
); } else static_assert(true, ""); } catch (SocketNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< SocketNotFound>::type>::type
, std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt6)" " throws an exception of type "
"SocketNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3758; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "SocketNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3758; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "SocketNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3758; } } else gtest_label_testthrow_3758
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3758, gtest_msg.value.c_str()) = ::testing::Message()
3758 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt6
); } else static_assert(true, ""); } catch (SocketNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< SocketNotFound>::type>::type
, std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt6)" " throws an exception of type "
"SocketNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3758; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "SocketNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3758; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt6)"
" throws an exception of type " "SocketNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3758; } } else gtest_label_testthrow_3758
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3758, gtest_msg.value.c_str()) = ::testing::Message()
;
3759
3760 // Repeat for pkt4
3761 Pkt4Ptr pkt4(new Pkt4(DHCPDISCOVER, 1));
3762
3763 // pkt4 does not have interface set yet.
3764 EXPECT_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt4
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt4)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3767; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3767; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3767; } } else gtest_label_testthrow_3767
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3767, gtest_msg.value.c_str()) = ::testing::Message()
3765 ifacemgr->getSocket(pkt4),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt4
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt4)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3767; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3767; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3767; } } else gtest_label_testthrow_3767
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3767, gtest_msg.value.c_str()) = ::testing::Message()
3766 IfaceNotFoundswitch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt4
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt4)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3767; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3767; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3767; } } else gtest_label_testthrow_3767
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3767, gtest_msg.value.c_str()) = ::testing::Message()
3767 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt4
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt4)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3767; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3767; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3767; } } else gtest_label_testthrow_3767
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3767, gtest_msg.value.c_str()) = ::testing::Message()
;
3768
3769 // Try to send over non-existing interface.
3770 pkt4->setIface("nosuchinterface45");
3771 pkt4->setIndex(12345);
3772 EXPECT_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt4
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt4)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3775; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3775; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3775; } } else gtest_label_testthrow_3775
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3775, gtest_msg.value.c_str()) = ::testing::Message()
3773 ifacemgr->getSocket(pkt4),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt4
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt4)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3775; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3775; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3775; } } else gtest_label_testthrow_3775
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3775, gtest_msg.value.c_str()) = ::testing::Message()
3774 IfaceNotFoundswitch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt4
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt4)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3775; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3775; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3775; } } else gtest_label_testthrow_3775
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3775, gtest_msg.value.c_str()) = ::testing::Message()
3775 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt4
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt4)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3775; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3775; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3775; } } else gtest_label_testthrow_3775
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3775, gtest_msg.value.c_str()) = ::testing::Message()
;
3776
3777 // Index is now checked first.
3778 pkt4->setIface(LOOPBACK_NAME);
3779 EXPECT_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt4
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt4)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3782; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3782; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3782; } } else gtest_label_testthrow_3782
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3782, gtest_msg.value.c_str()) = ::testing::Message()
3780 ifacemgr->getSocket(pkt4),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt4
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt4)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3782; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3782; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3782; } } else gtest_label_testthrow_3782
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3782, gtest_msg.value.c_str()) = ::testing::Message()
3781 IfaceNotFoundswitch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt4
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt4)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3782; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3782; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3782; } } else gtest_label_testthrow_3782
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3782, gtest_msg.value.c_str()) = ::testing::Message()
3782 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt4
); } else static_assert(true, ""); } catch (IfaceNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< IfaceNotFound>::type>::type,
std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt4)" " throws an exception of type "
"IfaceNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3782; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3782; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "IfaceNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3782; } } else gtest_label_testthrow_3782
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3782, gtest_msg.value.c_str()) = ::testing::Message()
;
3783
3784 // Socket info is set, packet has well defined interface. It should work.
3785 pkt4->setIndex(LOOPBACK_INDEX);
3786 EXPECT_EQ(7, ifacemgr->getSocket(pkt4).sockfd_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("7", "ifacemgr->getSocket(pkt4).sockfd_"
, 7, ifacemgr->getSocket(pkt4).sockfd_))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3786, gtest_ar
.failure_message()) = ::testing::Message()
;
3787
3788 // Set the local address to check if the socket for this address will
3789 // be returned.
3790 pkt4->setLocalAddr(IOAddress("192.0.2.56"));
3791 EXPECT_EQ(7, ifacemgr->getSocket(pkt4).sockfd_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("7", "ifacemgr->getSocket(pkt4).sockfd_"
, 7, ifacemgr->getSocket(pkt4).sockfd_))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3791, gtest_ar
.failure_message()) = ::testing::Message()
;
3792
3793 // Modify the local address and expect that the other socket will be
3794 // returned.
3795 pkt4->setLocalAddr(IOAddress("192.0.2.53"));
3796 EXPECT_EQ(8, ifacemgr->getSocket(pkt4).sockfd_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("8", "ifacemgr->getSocket(pkt4).sockfd_"
, 8, ifacemgr->getSocket(pkt4).sockfd_))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3796, gtest_ar
.failure_message()) = ::testing::Message()
;
3797
3798 EXPECT_NO_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->getIface(LOOPBACK_NAME)->delSocket(7); ifacemgr
->getIface(LOOPBACK_NAME)->delSocket(8);; } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3801; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3801; } } else gtest_label_testnothrow_3801
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3801, ("Expected: " "ifacemgr->getIface(LOOPBACK_NAME)->delSocket(7); ifacemgr->getIface(LOOPBACK_NAME)->delSocket(8);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
3799 ifacemgr->getIface(LOOPBACK_NAME)->delSocket(7);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->getIface(LOOPBACK_NAME)->delSocket(7); ifacemgr
->getIface(LOOPBACK_NAME)->delSocket(8);; } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3801; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3801; } } else gtest_label_testnothrow_3801
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3801, ("Expected: " "ifacemgr->getIface(LOOPBACK_NAME)->delSocket(7); ifacemgr->getIface(LOOPBACK_NAME)->delSocket(8);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
3800 ifacemgr->getIface(LOOPBACK_NAME)->delSocket(8);switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->getIface(LOOPBACK_NAME)->delSocket(7); ifacemgr
->getIface(LOOPBACK_NAME)->delSocket(8);; } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3801; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3801; } } else gtest_label_testnothrow_3801
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3801, ("Expected: " "ifacemgr->getIface(LOOPBACK_NAME)->delSocket(7); ifacemgr->getIface(LOOPBACK_NAME)->delSocket(8);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
3801 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->getIface(LOOPBACK_NAME)->delSocket(7); ifacemgr
->getIface(LOOPBACK_NAME)->delSocket(8);; } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_3801; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_3801; } } else gtest_label_testnothrow_3801
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3801, ("Expected: " "ifacemgr->getIface(LOOPBACK_NAME)->delSocket(7); ifacemgr->getIface(LOOPBACK_NAME)->delSocket(8);"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
3802
3803 // It should throw again, there's no usable socket anymore.
3804 EXPECT_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt4
); } else static_assert(true, ""); } catch (SocketNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< SocketNotFound>::type>::type
, std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt4)" " throws an exception of type "
"SocketNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3807; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "SocketNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3807; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "SocketNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3807; } } else gtest_label_testthrow_3807
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3807, gtest_msg.value.c_str()) = ::testing::Message()
3805 ifacemgr->getSocket(pkt4),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt4
); } else static_assert(true, ""); } catch (SocketNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< SocketNotFound>::type>::type
, std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt4)" " throws an exception of type "
"SocketNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3807; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "SocketNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3807; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "SocketNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3807; } } else gtest_label_testthrow_3807
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3807, gtest_msg.value.c_str()) = ::testing::Message()
3806 SocketNotFoundswitch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt4
); } else static_assert(true, ""); } catch (SocketNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< SocketNotFound>::type>::type
, std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt4)" " throws an exception of type "
"SocketNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3807; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "SocketNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3807; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "SocketNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3807; } } else gtest_label_testthrow_3807
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3807, gtest_msg.value.c_str()) = ::testing::Message()
3807 )switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->getSocket(pkt4
); } else static_assert(true, ""); } catch (SocketNotFound const
&) { gtest_caught_expected = true; } catch (typename std::
conditional< std::is_same<typename std::remove_cv<typename
std::remove_reference< SocketNotFound>::type>::type
, std::exception>::value, const ::testing::internal::NeverThrown
&, const std::exception&>::type e) { gtest_msg.value
= "Expected: " "ifacemgr->getSocket(pkt4)" " throws an exception of type "
"SocketNotFound" ".\n Actual: it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_3807; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "SocketNotFound" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_3807; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->getSocket(pkt4)"
" throws an exception of type " "SocketNotFound" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_3807; } } else gtest_label_testthrow_3807
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3807, gtest_msg.value.c_str()) = ::testing::Message()
;
3808}
3809
3810#if defined(OS_BSD)
3811#include <net/if_dl.h>
3812#endif
3813
3814#include <sys/socket.h>
3815#include <net/if.h>
3816#include <ifaddrs.h>
3817
3818/// @brief Checks the index of this interface
3819/// @param iface Kea interface structure to be checked
3820/// @param ifptr original structure returned by getifaddrs
3821/// @return true if index is returned properly
3822bool
3823checkIfIndex(const Iface & iface,
3824 struct ifaddrs *& ifptr) {
3825 return (iface.getIndex() == if_nametoindex(ifptr->ifa_name));
3826}
3827
3828/// @brief Checks if the interface has proper flags set
3829/// @param iface Kea interface structure to be checked
3830/// @param ifptr original structure returned by getifaddrs
3831/// @return true if flags are set properly
3832bool
3833checkIfFlags(const Iface & iface,
3834 struct ifaddrs *& ifptr) {
3835 bool flag_loopback_ = ifptr->ifa_flags & IFF_LOOPBACKIFF_LOOPBACK;
3836 bool flag_up_ = ifptr->ifa_flags & IFF_UPIFF_UP;
3837 bool flag_running_ = ifptr->ifa_flags & IFF_RUNNINGIFF_RUNNING;
3838 bool flag_multicast_ = ifptr->ifa_flags & IFF_MULTICASTIFF_MULTICAST;
3839
3840 return ((iface.flag_loopback_ == flag_loopback_) &&
3841 (iface.flag_up_ == flag_up_) &&
3842 (iface.flag_running_ == flag_running_) &&
3843 (iface.flag_multicast_ == flag_multicast_));
3844}
3845
3846/// @brief Checks if MAC Address/IP Addresses are properly well formed
3847/// @param iface Kea interface structure to be checked
3848/// @param ifptr original structure returned by getifaddrs
3849/// @return true if addresses are returned properly
3850bool
3851checkIfAddrs(const Iface & iface, struct ifaddrs *& ifptr) {
3852 const unsigned char * p = 0;
3853#if defined(OS_LINUX)
3854 // Workaround for Linux ...
3855 if(ifptr->ifa_data != 0) {
3856 // We avoid localhost as it has no MAC Address
3857 if (!strncmp(iface.getName().c_str(), "lo", 2)) {
3858 return (true);
3859 }
3860
3861 struct ifreq ifr;
3862 memset(& ifr.ifr_nameifr_ifrn.ifrn_name, 0, sizeof ifr.ifr_nameifr_ifrn.ifrn_name);
3863 strncpy(ifr.ifr_nameifr_ifrn.ifrn_name, iface.getName().c_str(), sizeof(ifr.ifr_nameifr_ifrn.ifrn_name) - 1);
3864
3865 int s = -1; // Socket descriptor
3866
3867 if ((s = socket(AF_INET2, SOCK_DGRAMSOCK_DGRAM, 0)) < 0) {
3868 isc_throw(Unexpected, "Cannot create AF_INET socket")do { std::ostringstream oss__; oss__ << "Cannot create AF_INET socket"
; throw Unexpected("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3868, oss__.str().c_str()); } while (1)
;
3869 }
3870
3871 if (ioctl(s, SIOCGIFHWADDR0x8927, & ifr) < 0) {
3872 close(s);
3873 isc_throw(Unexpected, "Cannot set SIOCGIFHWADDR flag")do { std::ostringstream oss__; oss__ << "Cannot set SIOCGIFHWADDR flag"
; throw Unexpected("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3873, oss__.str().c_str()); } while (1)
;
3874 }
3875
3876 p = reinterpret_cast<uint8_t *>(ifr.ifr_ifru.ifru_hwaddr.sa_data);
3877
3878 close(s);
3879
3880 /// @todo: Check MAC address length. For some interfaces it is
3881 /// different than 6. Some have 0, while some exotic ones (like
3882 /// infiniband) have 20.
3883 return (!memcmp(p, iface.getMac(), iface.getMacLen()));
3884 }
3885#endif
3886
3887 if(!ifptr->ifa_addr) {
3888 return (false);
3889 }
3890
3891 switch(ifptr->ifa_addr->sa_family) {
3892#if defined(OS_BSD)
3893 case AF_LINK: {
3894 // We avoid localhost as it has no MAC Address
3895 if (!strncmp(iface.getName().c_str(), "lo", 2)) {
3896 return (true);
3897 }
3898
3899 struct sockaddr_dl * hwdata =
3900 reinterpret_cast<struct sockaddr_dl *>(ifptr->ifa_addr);
3901 p = reinterpret_cast<uint8_t *>(LLADDR(hwdata));
3902
3903 // Extract MAC address length
3904 if (hwdata->sdl_alen != iface.getMacLen()) {
3905 return (false);
3906 }
3907
3908 return (!memcmp(p, iface.getMac(), hwdata->sdl_alen));
3909 }
3910#endif
3911 case AF_INET2: {
3912 struct sockaddr_in * v4data =
3913 reinterpret_cast<struct sockaddr_in *>(ifptr->ifa_addr);
3914 p = reinterpret_cast<uint8_t *>(& v4data->sin_addr);
3915
3916 IOAddress addrv4 = IOAddress::fromBytes(AF_INET2, p);
3917
3918 for (auto const& a :iface.getAddresses()) {
3919 if(a.get().isV4() && (a.get()) == addrv4) {
3920 return (true);
3921 }
3922 }
3923
3924 return (false);
3925 }
3926 case AF_INET610: {
3927 struct sockaddr_in6 * v6data =
3928 reinterpret_cast<struct sockaddr_in6 *>(ifptr->ifa_addr);
3929 p = reinterpret_cast<uint8_t *>(& v6data->sin6_addr);
3930
3931 IOAddress addrv6 = IOAddress::fromBytes(AF_INET610, p);
3932
3933 for (auto const& a : iface.getAddresses()) {
3934 if (a.get().isV6() && (a.get() == addrv6)) {
3935 return (true);
3936 }
3937 }
3938
3939 return (false);
3940 }
3941 default:
3942 return (true);
3943 }
3944}
3945
3946/// This test checks that the IfaceMgr detects interfaces correctly and
3947/// that detected interfaces have correct properties.
3948TEST_F(IfaceMgrTest, detectIfaces)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("detectIfaces") > 1, "test_name must not be empty"
); class IfaceMgrTest_detectIfaces_Test : public IfaceMgrTest
{ public: IfaceMgrTest_detectIfaces_Test() = default; ~IfaceMgrTest_detectIfaces_Test
() override = default; IfaceMgrTest_detectIfaces_Test (const IfaceMgrTest_detectIfaces_Test
&) = delete; IfaceMgrTest_detectIfaces_Test & operator
=( const IfaceMgrTest_detectIfaces_Test &) = delete; IfaceMgrTest_detectIfaces_Test
(IfaceMgrTest_detectIfaces_Test &&) noexcept = delete
; IfaceMgrTest_detectIfaces_Test & operator=( IfaceMgrTest_detectIfaces_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_detectIfaces_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "detectIfaces", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3948), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3948), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 3948), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_detectIfaces_Test
>); void IfaceMgrTest_detectIfaces_Test::TestBody()
{
3949 NakedIfaceMgr ifacemgr;
3950
3951 // We are using struct ifaddrs as it is the only good portable one
3952 // ifreq and ioctls are far from portable. For BSD ifreq::ifa_flags field
3953 // is only a short which, nowadays, can be negative
3954 struct ifaddrs *iflist = 0, *ifptr = 0;
3955 ASSERT_EQ(0, getifaddrs(&iflist))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0", "getifaddrs(&iflist)"
, 0, getifaddrs(&iflist)))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3955, gtest_ar.failure_message()) = ::testing::Message()
3956 << "Unit test failed to detect interfaces.";
3957
3958 // Go over all interfaces detected by the unit test and see if they
3959 // match with the interfaces detected by IfaceMgr.
3960 for (ifptr = iflist; ifptr != 0; ifptr = ifptr->ifa_next) {
3961 // When more than one IPv4 address is assigned to the particular
3962 // physical interface, virtual interfaces may be created for each
3963 // additional IPv4 address. For example, when multiple addresses
3964 // are assigned to the eth0 interface, additional virtual interfaces
3965 // will be eth0:0, eth0:1 etc. This is the case on some Linux
3966 // distributions. The getifaddrs will return virtual interfaces,
3967 // with single address each, but the Netlink-based implementation
3968 // (used by IfaceMgr) will rather hold a list of physical interfaces
3969 // with multiple IPv4 addresses assigned. This means that the test
3970 // can't use a name of the interface returned by getifaddrs to match
3971 // with the interface name held by IfaceMgr. Instead, we use the
3972 // index of the interface because the virtual interfaces have the
3973 // same indexes as the physical interfaces.
3974 IfacePtr i = ifacemgr.getIface(if_nametoindex(ifptr->ifa_name));
3975
3976 // If the given interface was also detected by the IfaceMgr,
3977 // check that its properties are correct.
3978 if (i != NULL__null) {
3979 // Check if interface index is reported properly
3980 EXPECT_TRUE(checkIfIndex(*i, ifptr))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(checkIfIndex(*i, ifptr
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3980, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "checkIfIndex(*i, ifptr)", "false", "true") .c_str()) = ::testing
::Message()
3981 << "Non-matching index of the detected interface "
3982 << i->getName();
3983
3984 // Check if flags are reported properly
3985 EXPECT_TRUE(checkIfFlags(*i, ifptr))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(checkIfFlags(*i, ifptr
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3985, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "checkIfFlags(*i, ifptr)", "false", "true") .c_str()) = ::testing
::Message()
3986 << "Non-matching flags of the detected interface "
3987 << i->getName();
3988
3989 // Check if addresses are reported properly
3990 EXPECT_TRUE(checkIfAddrs(*i, ifptr))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(checkIfAddrs(*i, ifptr
))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3990, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "checkIfAddrs(*i, ifptr)", "false", "true") .c_str()) = ::testing
::Message()
3991 << "Non-matching addresses on the detected interface "
3992 << i->getName();
3993
3994 } else {
3995 // The interface detected here seems to be missing in the
3996 // IfaceMgr.
3997 ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 3997, "Failed") = ::testing::Message()
<< "Interface " << ifptr->ifa_name
3998 << " not detected by the Interface Manager";
3999 }
4000 }
4001
4002 freeifaddrs(iflist);
4003 iflist = 0;
4004}
4005
4006// Tests if a single external socket and its callback can be passed and
4007// it is supported properly by receive4() method.
4008void IfaceMgrTest::testSingleExternalSocket4() {
4009 callback_ok = false;
4010
4011 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
4012
4013 // Create pipe and register it as extra socket
4014 int pipefd[2];
4015 EXPECT_TRUE(pipe(pipefd) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(pipefd) == 0)) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4015, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(pipefd) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
4016 EXPECT_NO_THROW(ifacemgr->addExternalSocket(pipefd[0], my_callback))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(pipefd[0], my_callback); } else
static_assert(true, ""); } catch (std::exception const& e
) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4016; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4016; } } else gtest_label_testnothrow_4016
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4016, ("Expected: " "ifacemgr->addExternalSocket(pipefd[0], my_callback)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4017
4018 ASSERT_NO_THROW(ifacemgr->startDHCPReceiver(AF_INET))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->startDHCPReceiver(2); } else static_assert(true
, ""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4018
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4018
; } } else gtest_label_testnothrow_4018 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4018, ("Expected: " "ifacemgr->startDHCPReceiver(2)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4019
4020 Pkt4Ptr pkt4;
4021 ASSERT_NO_THROW(pkt4 = ifacemgr->receive4(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt4 = ifacemgr->receive4(1); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4021
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4021
; } } else gtest_label_testnothrow_4021 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4021, ("Expected: " "pkt4 = ifacemgr->receive4(1)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4022
4023 // Our callback should not be called this time (there was no data)
4024 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4024, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
4025
4026 // IfaceMgr should not process control socket data as incoming packets
4027 EXPECT_FALSE(pkt4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4027, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt4", "true", "false") .c_str()) = ::testing::Message()
;
4028
4029 // Now, send some data over pipe (38 bytes)
4030 EXPECT_EQ(38, write(pipefd[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(pipefd[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(pipefd[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4030, gtest_ar.failure_message()) = ::testing::Message()
;
4031
4032 // ... and repeat
4033 ASSERT_NO_THROW(pkt4 = ifacemgr->receive4(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt4 = ifacemgr->receive4(1); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4033
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4033
; } } else gtest_label_testnothrow_4033 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4033, ("Expected: " "pkt4 = ifacemgr->receive4(1)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4034
4035 // IfaceMgr should not process control socket data as incoming packets
4036 EXPECT_FALSE(pkt4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4036, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt4", "true", "false") .c_str()) = ::testing::Message()
;
4037
4038 // There was some data, so this time callback should be called
4039 EXPECT_TRUE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback_ok)) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4039, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"callback_ok", "false", "true") .c_str()) = ::testing::Message
()
;
4040
4041 // close both pipe ends
4042 close(pipefd[1]);
4043 close(pipefd[0]);
4044
4045 ASSERT_NO_THROW(ifacemgr->stopDHCPReceiver())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->stopDHCPReceiver(); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4045
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4045
; } } else gtest_label_testnothrow_4045 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4045, ("Expected: " "ifacemgr->stopDHCPReceiver()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4046}
4047
4048TEST_F(IfaceMgrTest, SingleExternalSocket4Select)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("SingleExternalSocket4Select") > 1
, "test_name must not be empty"); class IfaceMgrTest_SingleExternalSocket4Select_Test
: public IfaceMgrTest { public: IfaceMgrTest_SingleExternalSocket4Select_Test
() = default; ~IfaceMgrTest_SingleExternalSocket4Select_Test(
) override = default; IfaceMgrTest_SingleExternalSocket4Select_Test
(const IfaceMgrTest_SingleExternalSocket4Select_Test &) =
delete; IfaceMgrTest_SingleExternalSocket4Select_Test & operator
=( const IfaceMgrTest_SingleExternalSocket4Select_Test &)
= delete; IfaceMgrTest_SingleExternalSocket4Select_Test (IfaceMgrTest_SingleExternalSocket4Select_Test
&&) noexcept = delete; IfaceMgrTest_SingleExternalSocket4Select_Test
& operator=( IfaceMgrTest_SingleExternalSocket4Select_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_SingleExternalSocket4Select_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "SingleExternalSocket4Select", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4048), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4048), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4048), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_SingleExternalSocket4Select_Test
>); void IfaceMgrTest_SingleExternalSocket4Select_Test::TestBody
()
{
4049 kea_event_handler_type_.setValue("select");
4050 testSingleExternalSocket4();
4051}
4052
4053TEST_F(IfaceMgrTest, SingleExternalSocket4Poll)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("SingleExternalSocket4Poll") > 1, "test_name must not be empty"
); class IfaceMgrTest_SingleExternalSocket4Poll_Test : public
IfaceMgrTest { public: IfaceMgrTest_SingleExternalSocket4Poll_Test
() = default; ~IfaceMgrTest_SingleExternalSocket4Poll_Test() override
= default; IfaceMgrTest_SingleExternalSocket4Poll_Test (const
IfaceMgrTest_SingleExternalSocket4Poll_Test &) = delete;
IfaceMgrTest_SingleExternalSocket4Poll_Test & operator=(
const IfaceMgrTest_SingleExternalSocket4Poll_Test &) = delete
; IfaceMgrTest_SingleExternalSocket4Poll_Test (IfaceMgrTest_SingleExternalSocket4Poll_Test
&&) noexcept = delete; IfaceMgrTest_SingleExternalSocket4Poll_Test
& operator=( IfaceMgrTest_SingleExternalSocket4Poll_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_SingleExternalSocket4Poll_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "SingleExternalSocket4Poll", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4053), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4053), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4053), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_SingleExternalSocket4Poll_Test
>); void IfaceMgrTest_SingleExternalSocket4Poll_Test::TestBody
()
{
4054 kea_event_handler_type_.setValue("poll");
4055 testSingleExternalSocket4();
4056}
4057
4058// Tests if multiple external sockets and their callbacks can be passed and
4059// it is supported properly by receive4() method.
4060void IfaceMgrTest::testMultipleExternalSockets4() {
4061 callback_ok = false;
4062 callback2_ok = false;
4063
4064 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
4065
4066 // Create first pipe and register it as extra socket
4067 int pipefd[2];
4068 EXPECT_TRUE(pipe(pipefd) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(pipefd) == 0)) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4068, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(pipefd) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
4069 EXPECT_NO_THROW(ifacemgr->addExternalSocket(pipefd[0], my_callback))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(pipefd[0], my_callback); } else
static_assert(true, ""); } catch (std::exception const& e
) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4069; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4069; } } else gtest_label_testnothrow_4069
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4069, ("Expected: " "ifacemgr->addExternalSocket(pipefd[0], my_callback)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4070
4071 // Let's create a second pipe and register it as well
4072 int secondpipe[2];
4073 EXPECT_TRUE(pipe(secondpipe) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(secondpipe) == 0
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4073, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(secondpipe) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
4074 EXPECT_NO_THROW(ifacemgr->addExternalSocket(secondpipe[0], my_callback2))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(secondpipe[0], my_callback2);
} else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4074; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4074
; } } else gtest_label_testnothrow_4074 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4074, ("Expected: " "ifacemgr->addExternalSocket(secondpipe[0], my_callback2)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4075
4076 Pkt4Ptr pkt4;
4077 ASSERT_NO_THROW(pkt4 = ifacemgr->receive4(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt4 = ifacemgr->receive4(1); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4077
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4077
; } } else gtest_label_testnothrow_4077 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4077, ("Expected: " "pkt4 = ifacemgr->receive4(1)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4078
4079 // Our callbacks should not be called this time (there was no data)
4080 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4080, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
4081 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4081, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
4082
4083 // IfaceMgr should not process control socket data as incoming packets
4084 EXPECT_FALSE(pkt4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4084, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt4", "true", "false") .c_str()) = ::testing::Message()
;
4085
4086 // Now, send some data over the first pipe (38 bytes)
4087 EXPECT_EQ(38, write(pipefd[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(pipefd[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(pipefd[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4087, gtest_ar.failure_message()) = ::testing::Message()
;
4088
4089 // ... and repeat
4090 ASSERT_NO_THROW(pkt4 = ifacemgr->receive4(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt4 = ifacemgr->receive4(1); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4090
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4090
; } } else gtest_label_testnothrow_4090 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4090, ("Expected: " "pkt4 = ifacemgr->receive4(1)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4091
4092 // IfaceMgr should not process control socket data as incoming packets
4093 EXPECT_FALSE(pkt4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4093, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt4", "true", "false") .c_str()) = ::testing::Message()
;
4094
4095 // There was some data, so this time callback should be called
4096 EXPECT_TRUE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback_ok)) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4096, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"callback_ok", "false", "true") .c_str()) = ::testing::Message
()
;
4097 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4097, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
4098
4099 // Clear the status...
4100 callback_ok = false;
4101 callback2_ok = false;
4102
4103 // And try again, using the second pipe
4104 EXPECT_EQ(38, write(secondpipe[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(secondpipe[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(secondpipe[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4104, gtest_ar.failure_message()) = ::testing::Message()
;
4105
4106 // ... and repeat
4107 ASSERT_NO_THROW(pkt4 = ifacemgr->receive4(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt4 = ifacemgr->receive4(1); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4107
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4107
; } } else gtest_label_testnothrow_4107 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4107, ("Expected: " "pkt4 = ifacemgr->receive4(1)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4108
4109 // IfaceMgr should not process control socket data as incoming packets
4110 EXPECT_FALSE(pkt4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4110, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt4", "true", "false") .c_str()) = ::testing::Message()
;
4111
4112 // There was some data, so this time second callback should be called
4113 // Without socket rotation this would call the first callback as the first
4114 // pipe data has not been read.
4115 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4115, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
4116 EXPECT_TRUE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback2_ok)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4116, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "false", "true") .c_str()) = ::testing::Message
()
;
4117
4118 // close both pipe ends
4119 close(pipefd[1]);
4120 close(pipefd[0]);
4121
4122 close(secondpipe[1]);
4123 close(secondpipe[0]);
4124}
4125
4126TEST_F(IfaceMgrTest, directMultipleExternalSockets4)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("directMultipleExternalSockets4") >
1, "test_name must not be empty"); class IfaceMgrTest_directMultipleExternalSockets4_Test
: public IfaceMgrTest { public: IfaceMgrTest_directMultipleExternalSockets4_Test
() = default; ~IfaceMgrTest_directMultipleExternalSockets4_Test
() override = default; IfaceMgrTest_directMultipleExternalSockets4_Test
(const IfaceMgrTest_directMultipleExternalSockets4_Test &
) = delete; IfaceMgrTest_directMultipleExternalSockets4_Test &
operator=( const IfaceMgrTest_directMultipleExternalSockets4_Test
&) = delete; IfaceMgrTest_directMultipleExternalSockets4_Test
(IfaceMgrTest_directMultipleExternalSockets4_Test &&
) noexcept = delete; IfaceMgrTest_directMultipleExternalSockets4_Test
& operator=( IfaceMgrTest_directMultipleExternalSockets4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_directMultipleExternalSockets4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "directMultipleExternalSockets4", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4126), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4126), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4126), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_directMultipleExternalSockets4_Test
>); void IfaceMgrTest_directMultipleExternalSockets4_Test::
TestBody()
{
4127 testExternalSockets4Rotation();
4128}
4129
4130// Tests if multiple external sockets and their callbacks can be passed and
4131// it is supported properly by receive4() method.
4132TEST_F(IfaceMgrTest, indirectMultipleExternalSockets4)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("indirectMultipleExternalSockets4") >
1, "test_name must not be empty"); class IfaceMgrTest_indirectMultipleExternalSockets4_Test
: public IfaceMgrTest { public: IfaceMgrTest_indirectMultipleExternalSockets4_Test
() = default; ~IfaceMgrTest_indirectMultipleExternalSockets4_Test
() override = default; IfaceMgrTest_indirectMultipleExternalSockets4_Test
(const IfaceMgrTest_indirectMultipleExternalSockets4_Test &
) = delete; IfaceMgrTest_indirectMultipleExternalSockets4_Test
& operator=( const IfaceMgrTest_indirectMultipleExternalSockets4_Test
&) = delete; IfaceMgrTest_indirectMultipleExternalSockets4_Test
(IfaceMgrTest_indirectMultipleExternalSockets4_Test &&
) noexcept = delete; IfaceMgrTest_indirectMultipleExternalSockets4_Test
& operator=( IfaceMgrTest_indirectMultipleExternalSockets4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_indirectMultipleExternalSockets4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "indirectMultipleExternalSockets4", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4132), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4132), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4132), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_indirectMultipleExternalSockets4_Test
>); void IfaceMgrTest_indirectMultipleExternalSockets4_Test
::TestBody()
{
4133 testExternalSockets4Rotation(false);
4134}
4135
4136TEST_F(IfaceMgrTest, MultipleExternalSockets4Select)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("MultipleExternalSockets4Select") >
1, "test_name must not be empty"); class IfaceMgrTest_MultipleExternalSockets4Select_Test
: public IfaceMgrTest { public: IfaceMgrTest_MultipleExternalSockets4Select_Test
() = default; ~IfaceMgrTest_MultipleExternalSockets4Select_Test
() override = default; IfaceMgrTest_MultipleExternalSockets4Select_Test
(const IfaceMgrTest_MultipleExternalSockets4Select_Test &
) = delete; IfaceMgrTest_MultipleExternalSockets4Select_Test &
operator=( const IfaceMgrTest_MultipleExternalSockets4Select_Test
&) = delete; IfaceMgrTest_MultipleExternalSockets4Select_Test
(IfaceMgrTest_MultipleExternalSockets4Select_Test &&
) noexcept = delete; IfaceMgrTest_MultipleExternalSockets4Select_Test
& operator=( IfaceMgrTest_MultipleExternalSockets4Select_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_MultipleExternalSockets4Select_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "MultipleExternalSockets4Select", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4136), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4136), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4136), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_MultipleExternalSockets4Select_Test
>); void IfaceMgrTest_MultipleExternalSockets4Select_Test::
TestBody()
{
4137 kea_event_handler_type_.setValue("select");
4138 testMultipleExternalSockets4();
4139}
4140
4141TEST_F(IfaceMgrTest, MultipleExternalSockets4Poll)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("MultipleExternalSockets4Poll") > 1
, "test_name must not be empty"); class IfaceMgrTest_MultipleExternalSockets4Poll_Test
: public IfaceMgrTest { public: IfaceMgrTest_MultipleExternalSockets4Poll_Test
() = default; ~IfaceMgrTest_MultipleExternalSockets4Poll_Test
() override = default; IfaceMgrTest_MultipleExternalSockets4Poll_Test
(const IfaceMgrTest_MultipleExternalSockets4Poll_Test &)
= delete; IfaceMgrTest_MultipleExternalSockets4Poll_Test &
operator=( const IfaceMgrTest_MultipleExternalSockets4Poll_Test
&) = delete; IfaceMgrTest_MultipleExternalSockets4Poll_Test
(IfaceMgrTest_MultipleExternalSockets4Poll_Test &&) noexcept
= delete; IfaceMgrTest_MultipleExternalSockets4Poll_Test &
operator=( IfaceMgrTest_MultipleExternalSockets4Poll_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_MultipleExternalSockets4Poll_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "MultipleExternalSockets4Poll", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4141), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4141), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4141), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_MultipleExternalSockets4Poll_Test
>); void IfaceMgrTest_MultipleExternalSockets4Poll_Test::TestBody
()
{
4142 kea_event_handler_type_.setValue("poll");
4143 testMultipleExternalSockets4();
4144}
4145
4146// Tests if existing external socket can be deleted and that such deletion does
4147// not affect any other existing sockets. Tests uses receive4()
4148void IfaceMgrTest::testDeleteExternalSockets4() {
4149 callback_ok = false;
4150 callback2_ok = false;
4151
4152 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
4153
4154 // Create first pipe and register it as extra socket
4155 int pipefd[2];
4156 EXPECT_TRUE(pipe(pipefd) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(pipefd) == 0)) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4156, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(pipefd) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
4157 EXPECT_NO_THROW(ifacemgr->addExternalSocket(pipefd[0], my_callback))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(pipefd[0], my_callback); } else
static_assert(true, ""); } catch (std::exception const& e
) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4157; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4157; } } else gtest_label_testnothrow_4157
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4157, ("Expected: " "ifacemgr->addExternalSocket(pipefd[0], my_callback)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4158
4159 // Let's create a second pipe and register it as well
4160 int secondpipe[2];
4161 EXPECT_TRUE(pipe(secondpipe) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(secondpipe) == 0
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4161, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(secondpipe) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
4162 EXPECT_NO_THROW(ifacemgr->addExternalSocket(secondpipe[0], my_callback2))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(secondpipe[0], my_callback2);
} else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4162; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4162
; } } else gtest_label_testnothrow_4162 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4162, ("Expected: " "ifacemgr->addExternalSocket(secondpipe[0], my_callback2)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4163
4164 // Now delete the first session socket
4165 EXPECT_NO_THROW(ifacemgr->deleteExternalSocket(pipefd[0]))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->deleteExternalSocket(pipefd[0]); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4165; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4165; } } else gtest_label_testnothrow_4165
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4165, ("Expected: " "ifacemgr->deleteExternalSocket(pipefd[0])"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4166
4167 // Now check whether the second callback is still functional
4168 EXPECT_EQ(38, write(secondpipe[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(secondpipe[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(secondpipe[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4168, gtest_ar.failure_message()) = ::testing::Message()
;
4169
4170 // ... and repeat
4171 Pkt4Ptr pkt4;
4172 ASSERT_NO_THROW(pkt4 = ifacemgr->receive4(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt4 = ifacemgr->receive4(1); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4172
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4172
; } } else gtest_label_testnothrow_4172 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4172, ("Expected: " "pkt4 = ifacemgr->receive4(1)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4173
4174 // IfaceMgr should not process control socket data as incoming packets
4175 EXPECT_FALSE(pkt4)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt4))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4175, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt4", "true", "false") .c_str()) = ::testing::Message()
;
4176
4177 // There was some data, so this time callback should be called
4178 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4178, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
4179 EXPECT_TRUE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback2_ok)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4179, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "false", "true") .c_str()) = ::testing::Message
()
;
4180
4181 // Let's reset the status
4182 callback_ok = false;
4183 callback2_ok = false;
4184
4185 // Now let's send something over the first callback that was unregistered.
4186 // We should NOT receive any callback.
4187 EXPECT_EQ(38, write(pipefd[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(pipefd[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(pipefd[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4187, gtest_ar.failure_message()) = ::testing::Message()
;
4188
4189 // Now check that the first callback is NOT called.
4190 ASSERT_NO_THROW(pkt4 = ifacemgr->receive4(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt4 = ifacemgr->receive4(1); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4190
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4190
; } } else gtest_label_testnothrow_4190 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4190, ("Expected: " "pkt4 = ifacemgr->receive4(1)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4191 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4191, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
4192
4193 // close both pipe ends
4194 close(pipefd[1]);
4195 close(pipefd[0]);
4196
4197 close(secondpipe[1]);
4198 close(secondpipe[0]);
4199}
4200
4201TEST_F(IfaceMgrTest, DeleteExternalSockets4Select)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("DeleteExternalSockets4Select") > 1
, "test_name must not be empty"); class IfaceMgrTest_DeleteExternalSockets4Select_Test
: public IfaceMgrTest { public: IfaceMgrTest_DeleteExternalSockets4Select_Test
() = default; ~IfaceMgrTest_DeleteExternalSockets4Select_Test
() override = default; IfaceMgrTest_DeleteExternalSockets4Select_Test
(const IfaceMgrTest_DeleteExternalSockets4Select_Test &)
= delete; IfaceMgrTest_DeleteExternalSockets4Select_Test &
operator=( const IfaceMgrTest_DeleteExternalSockets4Select_Test
&) = delete; IfaceMgrTest_DeleteExternalSockets4Select_Test
(IfaceMgrTest_DeleteExternalSockets4Select_Test &&) noexcept
= delete; IfaceMgrTest_DeleteExternalSockets4Select_Test &
operator=( IfaceMgrTest_DeleteExternalSockets4Select_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_DeleteExternalSockets4Select_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "DeleteExternalSockets4Select", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4201), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4201), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4201), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_DeleteExternalSockets4Select_Test
>); void IfaceMgrTest_DeleteExternalSockets4Select_Test::TestBody
()
{
4202 kea_event_handler_type_.setValue("select");
4203 testDeleteExternalSockets4();
4204}
4205
4206TEST_F(IfaceMgrTest, DeleteExternalSockets4Poll)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("DeleteExternalSockets4Poll") > 1,
"test_name must not be empty"); class IfaceMgrTest_DeleteExternalSockets4Poll_Test
: public IfaceMgrTest { public: IfaceMgrTest_DeleteExternalSockets4Poll_Test
() = default; ~IfaceMgrTest_DeleteExternalSockets4Poll_Test()
override = default; IfaceMgrTest_DeleteExternalSockets4Poll_Test
(const IfaceMgrTest_DeleteExternalSockets4Poll_Test &) =
delete; IfaceMgrTest_DeleteExternalSockets4Poll_Test & operator
=( const IfaceMgrTest_DeleteExternalSockets4Poll_Test &) =
delete; IfaceMgrTest_DeleteExternalSockets4Poll_Test (IfaceMgrTest_DeleteExternalSockets4Poll_Test
&&) noexcept = delete; IfaceMgrTest_DeleteExternalSockets4Poll_Test
& operator=( IfaceMgrTest_DeleteExternalSockets4Poll_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_DeleteExternalSockets4Poll_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "DeleteExternalSockets4Poll", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4206), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4206), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4206), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_DeleteExternalSockets4Poll_Test
>); void IfaceMgrTest_DeleteExternalSockets4Poll_Test::TestBody
()
{
4207 kea_event_handler_type_.setValue("poll");
4208 testDeleteExternalSockets4();
4209}
4210
4211TEST_F(IfaceMgrTest, unusableExternalSockets4DirectSelect)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("unusableExternalSockets4DirectSelect"
) > 1, "test_name must not be empty"); class IfaceMgrTest_unusableExternalSockets4DirectSelect_Test
: public IfaceMgrTest { public: IfaceMgrTest_unusableExternalSockets4DirectSelect_Test
() = default; ~IfaceMgrTest_unusableExternalSockets4DirectSelect_Test
() override = default; IfaceMgrTest_unusableExternalSockets4DirectSelect_Test
(const IfaceMgrTest_unusableExternalSockets4DirectSelect_Test
&) = delete; IfaceMgrTest_unusableExternalSockets4DirectSelect_Test
& operator=( const IfaceMgrTest_unusableExternalSockets4DirectSelect_Test
&) = delete; IfaceMgrTest_unusableExternalSockets4DirectSelect_Test
(IfaceMgrTest_unusableExternalSockets4DirectSelect_Test &&
) noexcept = delete; IfaceMgrTest_unusableExternalSockets4DirectSelect_Test
& operator=( IfaceMgrTest_unusableExternalSockets4DirectSelect_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_unusableExternalSockets4DirectSelect_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "unusableExternalSockets4DirectSelect", nullptr, nullptr, ::
testing::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4211), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4211), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4211), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_unusableExternalSockets4DirectSelect_Test
>); void IfaceMgrTest_unusableExternalSockets4DirectSelect_Test
::TestBody()
{
4212 kea_event_handler_type_.setValue("select");
4213 unusableExternalSockets4Test();
4214}
4215
4216TEST_F(IfaceMgrTest, unusableExternalSockets4DirectPoll)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("unusableExternalSockets4DirectPoll")
> 1, "test_name must not be empty"); class IfaceMgrTest_unusableExternalSockets4DirectPoll_Test
: public IfaceMgrTest { public: IfaceMgrTest_unusableExternalSockets4DirectPoll_Test
() = default; ~IfaceMgrTest_unusableExternalSockets4DirectPoll_Test
() override = default; IfaceMgrTest_unusableExternalSockets4DirectPoll_Test
(const IfaceMgrTest_unusableExternalSockets4DirectPoll_Test &
) = delete; IfaceMgrTest_unusableExternalSockets4DirectPoll_Test
& operator=( const IfaceMgrTest_unusableExternalSockets4DirectPoll_Test
&) = delete; IfaceMgrTest_unusableExternalSockets4DirectPoll_Test
(IfaceMgrTest_unusableExternalSockets4DirectPoll_Test &&
) noexcept = delete; IfaceMgrTest_unusableExternalSockets4DirectPoll_Test
& operator=( IfaceMgrTest_unusableExternalSockets4DirectPoll_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_unusableExternalSockets4DirectPoll_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "unusableExternalSockets4DirectPoll", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4216), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4216), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4216), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_unusableExternalSockets4DirectPoll_Test
>); void IfaceMgrTest_unusableExternalSockets4DirectPoll_Test
::TestBody()
{
4217 kea_event_handler_type_.setValue("poll");
4218 unusableExternalSockets4Test();
4219}
4220
4221TEST_F(IfaceMgrTest, unusableExternalSockets4IndirectSelect)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("unusableExternalSockets4IndirectSelect"
) > 1, "test_name must not be empty"); class IfaceMgrTest_unusableExternalSockets4IndirectSelect_Test
: public IfaceMgrTest { public: IfaceMgrTest_unusableExternalSockets4IndirectSelect_Test
() = default; ~IfaceMgrTest_unusableExternalSockets4IndirectSelect_Test
() override = default; IfaceMgrTest_unusableExternalSockets4IndirectSelect_Test
(const IfaceMgrTest_unusableExternalSockets4IndirectSelect_Test
&) = delete; IfaceMgrTest_unusableExternalSockets4IndirectSelect_Test
& operator=( const IfaceMgrTest_unusableExternalSockets4IndirectSelect_Test
&) = delete; IfaceMgrTest_unusableExternalSockets4IndirectSelect_Test
(IfaceMgrTest_unusableExternalSockets4IndirectSelect_Test &&
) noexcept = delete; IfaceMgrTest_unusableExternalSockets4IndirectSelect_Test
& operator=( IfaceMgrTest_unusableExternalSockets4IndirectSelect_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_unusableExternalSockets4IndirectSelect_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "unusableExternalSockets4IndirectSelect", nullptr, nullptr,
::testing::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4221), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4221), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4221), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_unusableExternalSockets4IndirectSelect_Test
>); void IfaceMgrTest_unusableExternalSockets4IndirectSelect_Test
::TestBody()
{
4222 kea_event_handler_type_.setValue("select");
4223 unusableExternalSockets4Test(true);
4224}
4225
4226TEST_F(IfaceMgrTest, unusableExternalSockets4IndirectPoll)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("unusableExternalSockets4IndirectPoll"
) > 1, "test_name must not be empty"); class IfaceMgrTest_unusableExternalSockets4IndirectPoll_Test
: public IfaceMgrTest { public: IfaceMgrTest_unusableExternalSockets4IndirectPoll_Test
() = default; ~IfaceMgrTest_unusableExternalSockets4IndirectPoll_Test
() override = default; IfaceMgrTest_unusableExternalSockets4IndirectPoll_Test
(const IfaceMgrTest_unusableExternalSockets4IndirectPoll_Test
&) = delete; IfaceMgrTest_unusableExternalSockets4IndirectPoll_Test
& operator=( const IfaceMgrTest_unusableExternalSockets4IndirectPoll_Test
&) = delete; IfaceMgrTest_unusableExternalSockets4IndirectPoll_Test
(IfaceMgrTest_unusableExternalSockets4IndirectPoll_Test &&
) noexcept = delete; IfaceMgrTest_unusableExternalSockets4IndirectPoll_Test
& operator=( IfaceMgrTest_unusableExternalSockets4IndirectPoll_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_unusableExternalSockets4IndirectPoll_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "unusableExternalSockets4IndirectPoll", nullptr, nullptr, ::
testing::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4226), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4226), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4226), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_unusableExternalSockets4IndirectPoll_Test
>); void IfaceMgrTest_unusableExternalSockets4IndirectPoll_Test
::TestBody()
{
4227 kea_event_handler_type_.setValue("poll");
4228 unusableExternalSockets4Test(true);
4229}
4230
4231/// @brief Verifies that IfaceMgr DHCPv4 receive calls follow a LRU order.
4232TEST_F(IfaceMgrTest, lruExternalSockets4)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("lruExternalSockets4") > 1, "test_name must not be empty"
); class IfaceMgrTest_lruExternalSockets4_Test : public IfaceMgrTest
{ public: IfaceMgrTest_lruExternalSockets4_Test() = default;
~IfaceMgrTest_lruExternalSockets4_Test() override = default;
IfaceMgrTest_lruExternalSockets4_Test (const IfaceMgrTest_lruExternalSockets4_Test
&) = delete; IfaceMgrTest_lruExternalSockets4_Test &
operator=( const IfaceMgrTest_lruExternalSockets4_Test &
) = delete; IfaceMgrTest_lruExternalSockets4_Test (IfaceMgrTest_lruExternalSockets4_Test
&&) noexcept = delete; IfaceMgrTest_lruExternalSockets4_Test
& operator=( IfaceMgrTest_lruExternalSockets4_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_lruExternalSockets4_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "lruExternalSockets4", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4232), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4232), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4232), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_lruExternalSockets4_Test
>); void IfaceMgrTest_lruExternalSockets4_Test::TestBody()
{
4233 lruExternalSockets4Test();
4234}
4235
4236/// @brief Verifies that IfaceMgr DHCPv6 receive calls follow a LRU order.
4237TEST_F(IfaceMgrTest, lruExternalSockets6)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("lruExternalSockets6") > 1, "test_name must not be empty"
); class IfaceMgrTest_lruExternalSockets6_Test : public IfaceMgrTest
{ public: IfaceMgrTest_lruExternalSockets6_Test() = default;
~IfaceMgrTest_lruExternalSockets6_Test() override = default;
IfaceMgrTest_lruExternalSockets6_Test (const IfaceMgrTest_lruExternalSockets6_Test
&) = delete; IfaceMgrTest_lruExternalSockets6_Test &
operator=( const IfaceMgrTest_lruExternalSockets6_Test &
) = delete; IfaceMgrTest_lruExternalSockets6_Test (IfaceMgrTest_lruExternalSockets6_Test
&&) noexcept = delete; IfaceMgrTest_lruExternalSockets6_Test
& operator=( IfaceMgrTest_lruExternalSockets6_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_lruExternalSockets6_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "lruExternalSockets6", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4237), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4237), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4237), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_lruExternalSockets6_Test
>); void IfaceMgrTest_lruExternalSockets6_Test::TestBody()
{
4238 lruExternalSockets6Test();
4239}
4240
4241// Tests if a single external socket and its callback can be passed and
4242// it is supported properly by receive6() method.
4243void IfaceMgrTest::testSingleExternalSocket6() {
4244 callback_ok = false;
4245
4246 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
4247
4248 // Create pipe and register it as extra socket
4249 int pipefd[2];
4250 EXPECT_TRUE(pipe(pipefd) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(pipefd) == 0)) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4250, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(pipefd) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
4251 EXPECT_NO_THROW(ifacemgr->addExternalSocket(pipefd[0], my_callback))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(pipefd[0], my_callback); } else
static_assert(true, ""); } catch (std::exception const& e
) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4251; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4251; } } else gtest_label_testnothrow_4251
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4251, ("Expected: " "ifacemgr->addExternalSocket(pipefd[0], my_callback)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4252
4253 Pkt6Ptr pkt6;
4254 ASSERT_NO_THROW(pkt6 = ifacemgr->receive6(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt6 = ifacemgr->receive6(1); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4254
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4254
; } } else gtest_label_testnothrow_4254 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4254, ("Expected: " "pkt6 = ifacemgr->receive6(1)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4255
4256 // Our callback should not be called this time (there was no data)
4257 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4257, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
4258
4259 // IfaceMgr should not process control socket data as incoming packets
4260 EXPECT_FALSE(pkt6)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4260, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt6", "true", "false") .c_str()) = ::testing::Message()
;
4261
4262 // Now, send some data over pipe (38 bytes)
4263 EXPECT_EQ(38, write(pipefd[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(pipefd[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(pipefd[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4263, gtest_ar.failure_message()) = ::testing::Message()
;
4264
4265 // ... and repeat
4266 ASSERT_NO_THROW(pkt6 = ifacemgr->receive6(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt6 = ifacemgr->receive6(1); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4266
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4266
; } } else gtest_label_testnothrow_4266 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4266, ("Expected: " "pkt6 = ifacemgr->receive6(1)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4267
4268 // IfaceMgr should not process control socket data as incoming packets
4269 EXPECT_FALSE(pkt6)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4269, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt6", "true", "false") .c_str()) = ::testing::Message()
;
4270
4271 // There was some data, so this time callback should be called
4272 EXPECT_TRUE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback_ok)) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4272, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"callback_ok", "false", "true") .c_str()) = ::testing::Message
()
;
4273
4274 // close both pipe ends
4275 close(pipefd[1]);
4276 close(pipefd[0]);
4277}
4278
4279TEST_F(IfaceMgrTest, SingleExternalSocket6Select)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("SingleExternalSocket6Select") > 1
, "test_name must not be empty"); class IfaceMgrTest_SingleExternalSocket6Select_Test
: public IfaceMgrTest { public: IfaceMgrTest_SingleExternalSocket6Select_Test
() = default; ~IfaceMgrTest_SingleExternalSocket6Select_Test(
) override = default; IfaceMgrTest_SingleExternalSocket6Select_Test
(const IfaceMgrTest_SingleExternalSocket6Select_Test &) =
delete; IfaceMgrTest_SingleExternalSocket6Select_Test & operator
=( const IfaceMgrTest_SingleExternalSocket6Select_Test &)
= delete; IfaceMgrTest_SingleExternalSocket6Select_Test (IfaceMgrTest_SingleExternalSocket6Select_Test
&&) noexcept = delete; IfaceMgrTest_SingleExternalSocket6Select_Test
& operator=( IfaceMgrTest_SingleExternalSocket6Select_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_SingleExternalSocket6Select_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "SingleExternalSocket6Select", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4279), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4279), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4279), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_SingleExternalSocket6Select_Test
>); void IfaceMgrTest_SingleExternalSocket6Select_Test::TestBody
()
{
4280 kea_event_handler_type_.setValue("select");
4281 testSingleExternalSocket6();
4282}
4283
4284TEST_F(IfaceMgrTest, SingleExternalSocket6Poll)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("SingleExternalSocket6Poll") > 1, "test_name must not be empty"
); class IfaceMgrTest_SingleExternalSocket6Poll_Test : public
IfaceMgrTest { public: IfaceMgrTest_SingleExternalSocket6Poll_Test
() = default; ~IfaceMgrTest_SingleExternalSocket6Poll_Test() override
= default; IfaceMgrTest_SingleExternalSocket6Poll_Test (const
IfaceMgrTest_SingleExternalSocket6Poll_Test &) = delete;
IfaceMgrTest_SingleExternalSocket6Poll_Test & operator=(
const IfaceMgrTest_SingleExternalSocket6Poll_Test &) = delete
; IfaceMgrTest_SingleExternalSocket6Poll_Test (IfaceMgrTest_SingleExternalSocket6Poll_Test
&&) noexcept = delete; IfaceMgrTest_SingleExternalSocket6Poll_Test
& operator=( IfaceMgrTest_SingleExternalSocket6Poll_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_SingleExternalSocket6Poll_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "SingleExternalSocket6Poll", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4284), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4284), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4284), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_SingleExternalSocket6Poll_Test
>); void IfaceMgrTest_SingleExternalSocket6Poll_Test::TestBody
()
{
4285 kea_event_handler_type_.setValue("poll");
4286 testSingleExternalSocket6();
4287}
4288
4289// Tests if multiple external sockets and their callbacks can be passed and
4290// it is supported properly by receive6() method.
4291void IfaceMgrTest::testMultipleExternalSockets6() {
4292 callback_ok = false;
4293 callback2_ok = false;
4294
4295 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
4296
4297 // Create first pipe and register it as extra socket
4298 int pipefd[2];
4299 EXPECT_TRUE(pipe(pipefd) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(pipefd) == 0)) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4299, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(pipefd) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
4300 EXPECT_NO_THROW(ifacemgr->addExternalSocket(pipefd[0], my_callback))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(pipefd[0], my_callback); } else
static_assert(true, ""); } catch (std::exception const& e
) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4300; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4300; } } else gtest_label_testnothrow_4300
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4300, ("Expected: " "ifacemgr->addExternalSocket(pipefd[0], my_callback)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4301
4302 // Let's create a second pipe and register it as well
4303 int secondpipe[2];
4304 EXPECT_TRUE(pipe(secondpipe) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(secondpipe) == 0
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4304, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(secondpipe) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
4305 EXPECT_NO_THROW(ifacemgr->addExternalSocket(secondpipe[0], my_callback2))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(secondpipe[0], my_callback2);
} else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4305; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4305
; } } else gtest_label_testnothrow_4305 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4305, ("Expected: " "ifacemgr->addExternalSocket(secondpipe[0], my_callback2)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4306
4307 Pkt6Ptr pkt6;
4308 ASSERT_NO_THROW(pkt6 = ifacemgr->receive6(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt6 = ifacemgr->receive6(1); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4308
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4308
; } } else gtest_label_testnothrow_4308 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4308, ("Expected: " "pkt6 = ifacemgr->receive6(1)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4309
4310 // Our callbacks should not be called this time (there was no data)
4311 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4311, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
4312 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4312, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
4313
4314 // IfaceMgr should not process control socket data as incoming packets
4315 EXPECT_FALSE(pkt6)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4315, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt6", "true", "false") .c_str()) = ::testing::Message()
;
4316
4317 // Now, send some data over the first pipe (38 bytes)
4318 EXPECT_EQ(38, write(pipefd[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(pipefd[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(pipefd[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4318, gtest_ar.failure_message()) = ::testing::Message()
;
4319
4320 // ... and repeat
4321 ASSERT_NO_THROW(pkt6 = ifacemgr->receive6(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt6 = ifacemgr->receive6(1); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4321
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4321
; } } else gtest_label_testnothrow_4321 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4321, ("Expected: " "pkt6 = ifacemgr->receive6(1)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4322
4323 // IfaceMgr should not process control socket data as incoming packets
4324 EXPECT_FALSE(pkt6)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4324, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt6", "true", "false") .c_str()) = ::testing::Message()
;
4325
4326 // There was some data, so this time callback should be called
4327 EXPECT_TRUE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback_ok)) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4327, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"callback_ok", "false", "true") .c_str()) = ::testing::Message
()
;
4328 EXPECT_FALSE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback2_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4328, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "true", "false") .c_str()) = ::testing::Message
()
;
4329
4330 // Clear the status...
4331 callback_ok = false;
4332 callback2_ok = false;
4333
4334 // And try again, using the second pipe
4335 EXPECT_EQ(38, write(secondpipe[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(secondpipe[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(secondpipe[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4335, gtest_ar.failure_message()) = ::testing::Message()
;
4336
4337 // ... and repeat
4338 ASSERT_NO_THROW(pkt6 = ifacemgr->receive6(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt6 = ifacemgr->receive6(1); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4338
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4338
; } } else gtest_label_testnothrow_4338 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4338, ("Expected: " "pkt6 = ifacemgr->receive6(1)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4339
4340 // IfaceMgr should not process control socket data as incoming packets
4341 EXPECT_FALSE(pkt6)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4341, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt6", "true", "false") .c_str()) = ::testing::Message()
;
4342
4343 // There was some data, so this time second callback should be called
4344 // Without socket rotation this would call the first callback as the first
4345 // pipe data has not been read.
4346 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4346, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
4347 EXPECT_TRUE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback2_ok)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4347, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "false", "true") .c_str()) = ::testing::Message
()
;
4348
4349 // close both pipe ends
4350 close(pipefd[1]);
4351 close(pipefd[0]);
4352
4353 close(secondpipe[1]);
4354 close(secondpipe[0]);
4355}
4356
4357TEST_F(IfaceMgrTest, directMultipleExternalSockets6)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("directMultipleExternalSockets6") >
1, "test_name must not be empty"); class IfaceMgrTest_directMultipleExternalSockets6_Test
: public IfaceMgrTest { public: IfaceMgrTest_directMultipleExternalSockets6_Test
() = default; ~IfaceMgrTest_directMultipleExternalSockets6_Test
() override = default; IfaceMgrTest_directMultipleExternalSockets6_Test
(const IfaceMgrTest_directMultipleExternalSockets6_Test &
) = delete; IfaceMgrTest_directMultipleExternalSockets6_Test &
operator=( const IfaceMgrTest_directMultipleExternalSockets6_Test
&) = delete; IfaceMgrTest_directMultipleExternalSockets6_Test
(IfaceMgrTest_directMultipleExternalSockets6_Test &&
) noexcept = delete; IfaceMgrTest_directMultipleExternalSockets6_Test
& operator=( IfaceMgrTest_directMultipleExternalSockets6_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_directMultipleExternalSockets6_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "directMultipleExternalSockets6", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4357), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4357), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4357), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_directMultipleExternalSockets6_Test
>); void IfaceMgrTest_directMultipleExternalSockets6_Test::
TestBody()
{
4358 testExternalSockets6Rotation();
4359}
4360
4361// Tests if multiple external sockets and their callbacks can be passed and
4362// it is supported properly by receive6() method.
4363TEST_F(IfaceMgrTest, indirectMultipleExternalSockets6)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("indirectMultipleExternalSockets6") >
1, "test_name must not be empty"); class IfaceMgrTest_indirectMultipleExternalSockets6_Test
: public IfaceMgrTest { public: IfaceMgrTest_indirectMultipleExternalSockets6_Test
() = default; ~IfaceMgrTest_indirectMultipleExternalSockets6_Test
() override = default; IfaceMgrTest_indirectMultipleExternalSockets6_Test
(const IfaceMgrTest_indirectMultipleExternalSockets6_Test &
) = delete; IfaceMgrTest_indirectMultipleExternalSockets6_Test
& operator=( const IfaceMgrTest_indirectMultipleExternalSockets6_Test
&) = delete; IfaceMgrTest_indirectMultipleExternalSockets6_Test
(IfaceMgrTest_indirectMultipleExternalSockets6_Test &&
) noexcept = delete; IfaceMgrTest_indirectMultipleExternalSockets6_Test
& operator=( IfaceMgrTest_indirectMultipleExternalSockets6_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_indirectMultipleExternalSockets6_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "indirectMultipleExternalSockets6", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4363), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4363), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4363), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_indirectMultipleExternalSockets6_Test
>); void IfaceMgrTest_indirectMultipleExternalSockets6_Test
::TestBody()
{
4364 testExternalSockets6Rotation(false);
4365}
4366
4367TEST_F(IfaceMgrTest, MultipleExternalSockets6Select)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("MultipleExternalSockets6Select") >
1, "test_name must not be empty"); class IfaceMgrTest_MultipleExternalSockets6Select_Test
: public IfaceMgrTest { public: IfaceMgrTest_MultipleExternalSockets6Select_Test
() = default; ~IfaceMgrTest_MultipleExternalSockets6Select_Test
() override = default; IfaceMgrTest_MultipleExternalSockets6Select_Test
(const IfaceMgrTest_MultipleExternalSockets6Select_Test &
) = delete; IfaceMgrTest_MultipleExternalSockets6Select_Test &
operator=( const IfaceMgrTest_MultipleExternalSockets6Select_Test
&) = delete; IfaceMgrTest_MultipleExternalSockets6Select_Test
(IfaceMgrTest_MultipleExternalSockets6Select_Test &&
) noexcept = delete; IfaceMgrTest_MultipleExternalSockets6Select_Test
& operator=( IfaceMgrTest_MultipleExternalSockets6Select_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_MultipleExternalSockets6Select_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "MultipleExternalSockets6Select", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4367), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4367), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4367), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_MultipleExternalSockets6Select_Test
>); void IfaceMgrTest_MultipleExternalSockets6Select_Test::
TestBody()
{
4368 kea_event_handler_type_.setValue("select");
4369 testMultipleExternalSockets6();
4370}
4371
4372TEST_F(IfaceMgrTest, MultipleExternalSockets6Poll)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("MultipleExternalSockets6Poll") > 1
, "test_name must not be empty"); class IfaceMgrTest_MultipleExternalSockets6Poll_Test
: public IfaceMgrTest { public: IfaceMgrTest_MultipleExternalSockets6Poll_Test
() = default; ~IfaceMgrTest_MultipleExternalSockets6Poll_Test
() override = default; IfaceMgrTest_MultipleExternalSockets6Poll_Test
(const IfaceMgrTest_MultipleExternalSockets6Poll_Test &)
= delete; IfaceMgrTest_MultipleExternalSockets6Poll_Test &
operator=( const IfaceMgrTest_MultipleExternalSockets6Poll_Test
&) = delete; IfaceMgrTest_MultipleExternalSockets6Poll_Test
(IfaceMgrTest_MultipleExternalSockets6Poll_Test &&) noexcept
= delete; IfaceMgrTest_MultipleExternalSockets6Poll_Test &
operator=( IfaceMgrTest_MultipleExternalSockets6Poll_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_MultipleExternalSockets6Poll_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "MultipleExternalSockets6Poll", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4372), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4372), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4372), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_MultipleExternalSockets6Poll_Test
>); void IfaceMgrTest_MultipleExternalSockets6Poll_Test::TestBody
()
{
4373 kea_event_handler_type_.setValue("poll");
4374 testMultipleExternalSockets6();
4375}
4376
4377// Tests if existing external socket can be deleted and that such deletion does
4378// not affect any other existing sockets. Tests uses receive6()
4379void IfaceMgrTest::testDeleteExternalSockets6() {
4380 callback_ok = false;
4381 callback2_ok = false;
4382
4383 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
4384
4385 // Create first pipe and register it as extra socket
4386 int pipefd[2];
4387 EXPECT_TRUE(pipe(pipefd) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(pipefd) == 0)) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4387, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(pipefd) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
4388 EXPECT_NO_THROW(ifacemgr->addExternalSocket(pipefd[0], my_callback))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(pipefd[0], my_callback); } else
static_assert(true, ""); } catch (std::exception const& e
) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing
::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4388; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4388; } } else gtest_label_testnothrow_4388
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4388, ("Expected: " "ifacemgr->addExternalSocket(pipefd[0], my_callback)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4389
4390 // Let's create a second pipe and register it as well
4391 int secondpipe[2];
4392 EXPECT_TRUE(pipe(secondpipe) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(secondpipe) == 0
)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4392, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(secondpipe) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
4393 EXPECT_NO_THROW(ifacemgr->addExternalSocket(secondpipe[0], my_callback2))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->addExternalSocket(secondpipe[0], my_callback2);
} else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4393; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4393
; } } else gtest_label_testnothrow_4393 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4393, ("Expected: " "ifacemgr->addExternalSocket(secondpipe[0], my_callback2)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4394
4395 // Now delete the first session socket
4396 EXPECT_NO_THROW(ifacemgr->deleteExternalSocket(pipefd[0]))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->deleteExternalSocket(pipefd[0]); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4396; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4396; } } else gtest_label_testnothrow_4396
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4396, ("Expected: " "ifacemgr->deleteExternalSocket(pipefd[0])"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4397
4398 // Now check whether the second callback is still functional
4399 EXPECT_EQ(38, write(secondpipe[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(secondpipe[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(secondpipe[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4399, gtest_ar.failure_message()) = ::testing::Message()
;
4400
4401 // ... and repeat
4402 Pkt6Ptr pkt6;
4403 ASSERT_NO_THROW(pkt6 = ifacemgr->receive6(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt6 = ifacemgr->receive6(1); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4403
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4403
; } } else gtest_label_testnothrow_4403 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4403, ("Expected: " "pkt6 = ifacemgr->receive6(1)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4404
4405 // IfaceMgr should not process control socket data as incoming packets
4406 EXPECT_FALSE(pkt6)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(pkt6))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4406, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"pkt6", "true", "false") .c_str()) = ::testing::Message()
;
4407
4408 // There was some data, so this time callback should be called
4409 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4409, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
4410 EXPECT_TRUE(callback2_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(callback2_ok)) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4410, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback2_ok", "false", "true") .c_str()) = ::testing::Message
()
;
4411
4412 // Let's reset the status
4413 callback_ok = false;
4414 callback2_ok = false;
4415
4416 // Now let's send something over the first callback that was unregistered.
4417 // We should NOT receive any callback.
4418 EXPECT_EQ(38, write(pipefd[1], "Hi, this is a message sent over a pipe", 38))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("38", "write(pipefd[1], \"Hi, this is a message sent over a pipe\", 38)"
, 38, write(pipefd[1], "Hi, this is a message sent over a pipe"
, 38)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4418, gtest_ar.failure_message()) = ::testing::Message()
;
4419
4420 // Now check that the first callback is NOT called.
4421 ASSERT_NO_THROW(pkt6 = ifacemgr->receive6(1))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
pkt6 = ifacemgr->receive6(1); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4421
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4421
; } } else gtest_label_testnothrow_4421 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4421, ("Expected: " "pkt6 = ifacemgr->receive6(1)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4422 EXPECT_FALSE(callback_ok)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(callback_ok))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4422, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "callback_ok", "true", "false") .c_str()) = ::testing::Message
()
;
4423
4424 // close both pipe ends
4425 close(pipefd[1]);
4426 close(pipefd[0]);
4427
4428 close(secondpipe[1]);
4429 close(secondpipe[0]);
4430}
4431
4432TEST_F(IfaceMgrTest, DeleteExternalSockets6Select)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("DeleteExternalSockets6Select") > 1
, "test_name must not be empty"); class IfaceMgrTest_DeleteExternalSockets6Select_Test
: public IfaceMgrTest { public: IfaceMgrTest_DeleteExternalSockets6Select_Test
() = default; ~IfaceMgrTest_DeleteExternalSockets6Select_Test
() override = default; IfaceMgrTest_DeleteExternalSockets6Select_Test
(const IfaceMgrTest_DeleteExternalSockets6Select_Test &)
= delete; IfaceMgrTest_DeleteExternalSockets6Select_Test &
operator=( const IfaceMgrTest_DeleteExternalSockets6Select_Test
&) = delete; IfaceMgrTest_DeleteExternalSockets6Select_Test
(IfaceMgrTest_DeleteExternalSockets6Select_Test &&) noexcept
= delete; IfaceMgrTest_DeleteExternalSockets6Select_Test &
operator=( IfaceMgrTest_DeleteExternalSockets6Select_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_DeleteExternalSockets6Select_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "DeleteExternalSockets6Select", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4432), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4432), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4432), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_DeleteExternalSockets6Select_Test
>); void IfaceMgrTest_DeleteExternalSockets6Select_Test::TestBody
()
{
4433 kea_event_handler_type_.setValue("select");
4434 testDeleteExternalSockets6();
4435}
4436
4437TEST_F(IfaceMgrTest, DeleteExternalSockets6Poll)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("DeleteExternalSockets6Poll") > 1,
"test_name must not be empty"); class IfaceMgrTest_DeleteExternalSockets6Poll_Test
: public IfaceMgrTest { public: IfaceMgrTest_DeleteExternalSockets6Poll_Test
() = default; ~IfaceMgrTest_DeleteExternalSockets6Poll_Test()
override = default; IfaceMgrTest_DeleteExternalSockets6Poll_Test
(const IfaceMgrTest_DeleteExternalSockets6Poll_Test &) =
delete; IfaceMgrTest_DeleteExternalSockets6Poll_Test & operator
=( const IfaceMgrTest_DeleteExternalSockets6Poll_Test &) =
delete; IfaceMgrTest_DeleteExternalSockets6Poll_Test (IfaceMgrTest_DeleteExternalSockets6Poll_Test
&&) noexcept = delete; IfaceMgrTest_DeleteExternalSockets6Poll_Test
& operator=( IfaceMgrTest_DeleteExternalSockets6Poll_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_DeleteExternalSockets6Poll_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "DeleteExternalSockets6Poll", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4437), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4437), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4437), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_DeleteExternalSockets6Poll_Test
>); void IfaceMgrTest_DeleteExternalSockets6Poll_Test::TestBody
()
{
4438 kea_event_handler_type_.setValue("poll");
4439 testDeleteExternalSockets6();
4440}
4441
4442// Tests that an existing external socket that becomes invalid
4443// is detected and ignored, without affecting other sockets.
4444// Tests uses receive6() without queuing.
4445TEST_F(IfaceMgrTest, unusableExternalSockets6DirectSelect)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("unusableExternalSockets6DirectSelect"
) > 1, "test_name must not be empty"); class IfaceMgrTest_unusableExternalSockets6DirectSelect_Test
: public IfaceMgrTest { public: IfaceMgrTest_unusableExternalSockets6DirectSelect_Test
() = default; ~IfaceMgrTest_unusableExternalSockets6DirectSelect_Test
() override = default; IfaceMgrTest_unusableExternalSockets6DirectSelect_Test
(const IfaceMgrTest_unusableExternalSockets6DirectSelect_Test
&) = delete; IfaceMgrTest_unusableExternalSockets6DirectSelect_Test
& operator=( const IfaceMgrTest_unusableExternalSockets6DirectSelect_Test
&) = delete; IfaceMgrTest_unusableExternalSockets6DirectSelect_Test
(IfaceMgrTest_unusableExternalSockets6DirectSelect_Test &&
) noexcept = delete; IfaceMgrTest_unusableExternalSockets6DirectSelect_Test
& operator=( IfaceMgrTest_unusableExternalSockets6DirectSelect_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_unusableExternalSockets6DirectSelect_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "unusableExternalSockets6DirectSelect", nullptr, nullptr, ::
testing::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4445), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4445), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4445), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_unusableExternalSockets6DirectSelect_Test
>); void IfaceMgrTest_unusableExternalSockets6DirectSelect_Test
::TestBody()
{
4446 kea_event_handler_type_.setValue("select");
4447 unusableExternalSockets6Test();
4448}
4449
4450TEST_F(IfaceMgrTest, unusableExternalSockets6DirectPoll)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("unusableExternalSockets6DirectPoll")
> 1, "test_name must not be empty"); class IfaceMgrTest_unusableExternalSockets6DirectPoll_Test
: public IfaceMgrTest { public: IfaceMgrTest_unusableExternalSockets6DirectPoll_Test
() = default; ~IfaceMgrTest_unusableExternalSockets6DirectPoll_Test
() override = default; IfaceMgrTest_unusableExternalSockets6DirectPoll_Test
(const IfaceMgrTest_unusableExternalSockets6DirectPoll_Test &
) = delete; IfaceMgrTest_unusableExternalSockets6DirectPoll_Test
& operator=( const IfaceMgrTest_unusableExternalSockets6DirectPoll_Test
&) = delete; IfaceMgrTest_unusableExternalSockets6DirectPoll_Test
(IfaceMgrTest_unusableExternalSockets6DirectPoll_Test &&
) noexcept = delete; IfaceMgrTest_unusableExternalSockets6DirectPoll_Test
& operator=( IfaceMgrTest_unusableExternalSockets6DirectPoll_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_unusableExternalSockets6DirectPoll_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "unusableExternalSockets6DirectPoll", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4450), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4450), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4450), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_unusableExternalSockets6DirectPoll_Test
>); void IfaceMgrTest_unusableExternalSockets6DirectPoll_Test
::TestBody()
{
4451 kea_event_handler_type_.setValue("poll");
4452 unusableExternalSockets6Test();
4453}
4454
4455// Tests that an existing external socket that becomes invalid
4456// is detected and ignored, without affecting other sockets.
4457// Tests uses receive6() with queuing.
4458TEST_F(IfaceMgrTest, unusableExternalSockets6IndirectSelect)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("unusableExternalSockets6IndirectSelect"
) > 1, "test_name must not be empty"); class IfaceMgrTest_unusableExternalSockets6IndirectSelect_Test
: public IfaceMgrTest { public: IfaceMgrTest_unusableExternalSockets6IndirectSelect_Test
() = default; ~IfaceMgrTest_unusableExternalSockets6IndirectSelect_Test
() override = default; IfaceMgrTest_unusableExternalSockets6IndirectSelect_Test
(const IfaceMgrTest_unusableExternalSockets6IndirectSelect_Test
&) = delete; IfaceMgrTest_unusableExternalSockets6IndirectSelect_Test
& operator=( const IfaceMgrTest_unusableExternalSockets6IndirectSelect_Test
&) = delete; IfaceMgrTest_unusableExternalSockets6IndirectSelect_Test
(IfaceMgrTest_unusableExternalSockets6IndirectSelect_Test &&
) noexcept = delete; IfaceMgrTest_unusableExternalSockets6IndirectSelect_Test
& operator=( IfaceMgrTest_unusableExternalSockets6IndirectSelect_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_unusableExternalSockets6IndirectSelect_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "unusableExternalSockets6IndirectSelect", nullptr, nullptr,
::testing::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4458), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4458), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4458), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_unusableExternalSockets6IndirectSelect_Test
>); void IfaceMgrTest_unusableExternalSockets6IndirectSelect_Test
::TestBody()
{
4459 kea_event_handler_type_.setValue("select");
4460 unusableExternalSockets6Test(true);
4461}
4462
4463TEST_F(IfaceMgrTest, unusableExternalSockets6IndirectPoll)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("unusableExternalSockets6IndirectPoll"
) > 1, "test_name must not be empty"); class IfaceMgrTest_unusableExternalSockets6IndirectPoll_Test
: public IfaceMgrTest { public: IfaceMgrTest_unusableExternalSockets6IndirectPoll_Test
() = default; ~IfaceMgrTest_unusableExternalSockets6IndirectPoll_Test
() override = default; IfaceMgrTest_unusableExternalSockets6IndirectPoll_Test
(const IfaceMgrTest_unusableExternalSockets6IndirectPoll_Test
&) = delete; IfaceMgrTest_unusableExternalSockets6IndirectPoll_Test
& operator=( const IfaceMgrTest_unusableExternalSockets6IndirectPoll_Test
&) = delete; IfaceMgrTest_unusableExternalSockets6IndirectPoll_Test
(IfaceMgrTest_unusableExternalSockets6IndirectPoll_Test &&
) noexcept = delete; IfaceMgrTest_unusableExternalSockets6IndirectPoll_Test
& operator=( IfaceMgrTest_unusableExternalSockets6IndirectPoll_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_unusableExternalSockets6IndirectPoll_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "unusableExternalSockets6IndirectPoll", nullptr, nullptr, ::
testing::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4463), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4463), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4463), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_unusableExternalSockets6IndirectPoll_Test
>); void IfaceMgrTest_unusableExternalSockets6IndirectPoll_Test
::TestBody()
{
4464 kea_event_handler_type_.setValue("poll");
4465 unusableExternalSockets6Test(true);
4466}
4467
4468/// @brief Test fixture for logs.
4469class IfaceMgrLogTest : public LogContentTest {
4470public:
4471 /// @brief Create the interface manager.
4472 IfaceMgrLogTest() {
4473 ifacemgr_.reset(new NakedIfaceMgr());
4474 }
4475
4476 /// @brief Destroy the interface manager.
4477 ~IfaceMgrLogTest() {
4478 ifacemgr_.reset();
4479 }
4480
4481 /// @brief Perform external socket operations in another thread.
4482 void testThread() {
4483 thread th([this]() {
4484 // Create pipe mainly to use a not fake fd.
4485 int pipefd[2];
4486 ASSERT_TRUE(pipe(pipefd) == 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(pipe(pipefd) == 0)) ;
else return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4486, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "pipe(pipefd) == 0", "false", "true") .c_str()) = ::testing
::Message()
;
4487 EXPECT_NO_THROW(ifacemgr_->addExternalSocket(pipefd[0], 0))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr_->addExternalSocket(pipefd[0], 0); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4487; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4487; } } else gtest_label_testnothrow_4487
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4487, ("Expected: " "ifacemgr_->addExternalSocket(pipefd[0], 0)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4488 EXPECT_TRUE(ifacemgr_->isExternalSocket(pipefd[0]))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr_->isExternalSocket
(pipefd[0]))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4488, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr_->isExternalSocket(pipefd[0])", "false", "true"
) .c_str()) = ::testing::Message()
;
4489 EXPECT_NO_THROW(ifacemgr_->deleteExternalSocket(pipefd[0]))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr_->deleteExternalSocket(pipefd[0]); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4489; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4489; } } else gtest_label_testnothrow_4489
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4489, ("Expected: " "ifacemgr_->deleteExternalSocket(pipefd[0])"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4490 EXPECT_NO_THROW(ifacemgr_->deleteAllExternalSockets())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr_->deleteAllExternalSockets(); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4490; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4490; } } else gtest_label_testnothrow_4490
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4490, ("Expected: " "ifacemgr_->deleteAllExternalSockets()"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4491 close(pipefd[1]);
4492 close(pipefd[0]);
4493 });
4494 th.join();
4495 }
4496
4497 /// @brief The interface manager.
4498 boost::shared_ptr<NakedIfaceMgr> ifacemgr_;
4499};
4500
4501// Tests that external socket operations log errors when not in the main thread.
4502TEST_F(IfaceMgrLogTest, externalSocketOtherThread)static_assert(sizeof("IfaceMgrLogTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("externalSocketOtherThread") > 1, "test_name must not be empty"
); class IfaceMgrLogTest_externalSocketOtherThread_Test : public
IfaceMgrLogTest { public: IfaceMgrLogTest_externalSocketOtherThread_Test
() = default; ~IfaceMgrLogTest_externalSocketOtherThread_Test
() override = default; IfaceMgrLogTest_externalSocketOtherThread_Test
(const IfaceMgrLogTest_externalSocketOtherThread_Test &)
= delete; IfaceMgrLogTest_externalSocketOtherThread_Test &
operator=( const IfaceMgrLogTest_externalSocketOtherThread_Test
&) = delete; IfaceMgrLogTest_externalSocketOtherThread_Test
(IfaceMgrLogTest_externalSocketOtherThread_Test &&) noexcept
= delete; IfaceMgrLogTest_externalSocketOtherThread_Test &
operator=( IfaceMgrLogTest_externalSocketOtherThread_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrLogTest_externalSocketOtherThread_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrLogTest"
, "externalSocketOtherThread", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4502), (::testing::internal::GetTypeId<IfaceMgrLogTest>
()), ::testing::internal::SuiteApiResolver< IfaceMgrLogTest
>::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4502), ::testing::internal::SuiteApiResolver< IfaceMgrLogTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4502), new ::testing::internal::TestFactoryImpl<IfaceMgrLogTest_externalSocketOtherThread_Test
>); void IfaceMgrLogTest_externalSocketOtherThread_Test::TestBody
()
{
4503 ASSERT_TRUE(ifacemgr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr_)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4503, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr_", "false", "true") .c_str()) = ::testing::Message
()
;
4504 ASSERT_TRUE(ifacemgr_->getCheckThreadId())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr_->getCheckThreadId
())) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4504, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr_->getCheckThreadId()", "false", "true") .c_str
()) = ::testing::Message()
;
4505
4506 testThread();
4507 EXPECT_EQ(1U, countFile("DHCP_ADD_EXTERNAL_SOCKET_BAD_THREAD"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "countFile(\"DHCP_ADD_EXTERNAL_SOCKET_BAD_THREAD\")"
, 1U, countFile("DHCP_ADD_EXTERNAL_SOCKET_BAD_THREAD")))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4507, gtest_ar.failure_message()) = ::testing::Message()
;
4508 EXPECT_EQ(1U, countFile("DHCP_DELETE_EXTERNAL_SOCKET_BAD_THREAD"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "countFile(\"DHCP_DELETE_EXTERNAL_SOCKET_BAD_THREAD\")"
, 1U, countFile("DHCP_DELETE_EXTERNAL_SOCKET_BAD_THREAD")))) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4508, gtest_ar.failure_message()) = ::testing::Message()
;
4509 EXPECT_EQ(1U, countFile("DHCP_DELETE_ALL_EXTERNAL_SOCKETS_BAD_THREAD"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "countFile(\"DHCP_DELETE_ALL_EXTERNAL_SOCKETS_BAD_THREAD\")"
, 1U, countFile("DHCP_DELETE_ALL_EXTERNAL_SOCKETS_BAD_THREAD"
)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4509, gtest_ar.failure_message()) = ::testing::Message()
;
4510}
4511
4512// Tests that errors are logged only when enabled.
4513TEST_F(IfaceMgrLogTest, externalSocketOtherThreadNoLog)static_assert(sizeof("IfaceMgrLogTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("externalSocketOtherThreadNoLog") >
1, "test_name must not be empty"); class IfaceMgrLogTest_externalSocketOtherThreadNoLog_Test
: public IfaceMgrLogTest { public: IfaceMgrLogTest_externalSocketOtherThreadNoLog_Test
() = default; ~IfaceMgrLogTest_externalSocketOtherThreadNoLog_Test
() override = default; IfaceMgrLogTest_externalSocketOtherThreadNoLog_Test
(const IfaceMgrLogTest_externalSocketOtherThreadNoLog_Test &
) = delete; IfaceMgrLogTest_externalSocketOtherThreadNoLog_Test
& operator=( const IfaceMgrLogTest_externalSocketOtherThreadNoLog_Test
&) = delete; IfaceMgrLogTest_externalSocketOtherThreadNoLog_Test
(IfaceMgrLogTest_externalSocketOtherThreadNoLog_Test &&
) noexcept = delete; IfaceMgrLogTest_externalSocketOtherThreadNoLog_Test
& operator=( IfaceMgrLogTest_externalSocketOtherThreadNoLog_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrLogTest_externalSocketOtherThreadNoLog_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrLogTest"
, "externalSocketOtherThreadNoLog", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4513), (::testing::internal::GetTypeId<IfaceMgrLogTest>
()), ::testing::internal::SuiteApiResolver< IfaceMgrLogTest
>::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4513), ::testing::internal::SuiteApiResolver< IfaceMgrLogTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4513), new ::testing::internal::TestFactoryImpl<IfaceMgrLogTest_externalSocketOtherThreadNoLog_Test
>); void IfaceMgrLogTest_externalSocketOtherThreadNoLog_Test
::TestBody()
{
4514 ASSERT_TRUE(ifacemgr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr_)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4514, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr_", "false", "true") .c_str()) = ::testing::Message
()
;
4515 ifacemgr_->setCheckThreadId(false);
4516 ASSERT_FALSE(ifacemgr_->getCheckThreadId())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr_->getCheckThreadId
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4516, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr_->getCheckThreadId()", "true", "false") .c_str
()) = ::testing::Message()
;
4517
4518 testThread();
4519 EXPECT_EQ(0U, countFile("DHCP"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "countFile(\"DHCP\")"
, 0U, countFile("DHCP")))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4519, gtest_ar.failure_message()) = ::testing::Message()
;
4520}
4521
4522// Tests that calling twice addExternalSocket on the same value warns.
4523TEST_F(IfaceMgrLogTest, addExternalSocketAlreadyExists)static_assert(sizeof("IfaceMgrLogTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("addExternalSocketAlreadyExists") >
1, "test_name must not be empty"); class IfaceMgrLogTest_addExternalSocketAlreadyExists_Test
: public IfaceMgrLogTest { public: IfaceMgrLogTest_addExternalSocketAlreadyExists_Test
() = default; ~IfaceMgrLogTest_addExternalSocketAlreadyExists_Test
() override = default; IfaceMgrLogTest_addExternalSocketAlreadyExists_Test
(const IfaceMgrLogTest_addExternalSocketAlreadyExists_Test &
) = delete; IfaceMgrLogTest_addExternalSocketAlreadyExists_Test
& operator=( const IfaceMgrLogTest_addExternalSocketAlreadyExists_Test
&) = delete; IfaceMgrLogTest_addExternalSocketAlreadyExists_Test
(IfaceMgrLogTest_addExternalSocketAlreadyExists_Test &&
) noexcept = delete; IfaceMgrLogTest_addExternalSocketAlreadyExists_Test
& operator=( IfaceMgrLogTest_addExternalSocketAlreadyExists_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrLogTest_addExternalSocketAlreadyExists_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrLogTest"
, "addExternalSocketAlreadyExists", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4523), (::testing::internal::GetTypeId<IfaceMgrLogTest>
()), ::testing::internal::SuiteApiResolver< IfaceMgrLogTest
>::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4523), ::testing::internal::SuiteApiResolver< IfaceMgrLogTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4523), new ::testing::internal::TestFactoryImpl<IfaceMgrLogTest_addExternalSocketAlreadyExists_Test
>); void IfaceMgrLogTest_addExternalSocketAlreadyExists_Test
::TestBody()
{
4524 ASSERT_TRUE(ifacemgr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr_)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4524, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr_", "false", "true") .c_str()) = ::testing::Message
()
;
4525 ASSERT_NO_THROW(ifacemgr_->addExternalSocket(100, 0))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr_->addExternalSocket(100, 0); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4525; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4525; } } else gtest_label_testnothrow_4525
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4525, ("Expected: " "ifacemgr_->addExternalSocket(100, 0)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4526 EXPECT_EQ(0U, countFile("DHCP_ADD_EXTERNAL_SOCKET_ALREADY_EXISTS"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "countFile(\"DHCP_ADD_EXTERNAL_SOCKET_ALREADY_EXISTS\")"
, 0U, countFile("DHCP_ADD_EXTERNAL_SOCKET_ALREADY_EXISTS"))))
; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4526, gtest_ar.failure_message()) = ::testing::Message()
;
4527 ASSERT_NO_THROW(ifacemgr_->addExternalSocket(100, 0))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr_->addExternalSocket(100, 0); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4527; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4527; } } else gtest_label_testnothrow_4527
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4527, ("Expected: " "ifacemgr_->addExternalSocket(100, 0)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4528 EXPECT_EQ(1U, countFile("DHCP_ADD_EXTERNAL_SOCKET_ALREADY_EXISTS"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "countFile(\"DHCP_ADD_EXTERNAL_SOCKET_ALREADY_EXISTS\")"
, 1U, countFile("DHCP_ADD_EXTERNAL_SOCKET_ALREADY_EXISTS"))))
; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4528, gtest_ar.failure_message()) = ::testing::Message()
;
4529}
4530
4531// Tests that calling twice deleteExternalSocket on the same value warns.
4532TEST_F(IfaceMgrLogTest, deleteExternalSocketNotFound)static_assert(sizeof("IfaceMgrLogTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("deleteExternalSocketNotFound") > 1
, "test_name must not be empty"); class IfaceMgrLogTest_deleteExternalSocketNotFound_Test
: public IfaceMgrLogTest { public: IfaceMgrLogTest_deleteExternalSocketNotFound_Test
() = default; ~IfaceMgrLogTest_deleteExternalSocketNotFound_Test
() override = default; IfaceMgrLogTest_deleteExternalSocketNotFound_Test
(const IfaceMgrLogTest_deleteExternalSocketNotFound_Test &
) = delete; IfaceMgrLogTest_deleteExternalSocketNotFound_Test
& operator=( const IfaceMgrLogTest_deleteExternalSocketNotFound_Test
&) = delete; IfaceMgrLogTest_deleteExternalSocketNotFound_Test
(IfaceMgrLogTest_deleteExternalSocketNotFound_Test &&
) noexcept = delete; IfaceMgrLogTest_deleteExternalSocketNotFound_Test
& operator=( IfaceMgrLogTest_deleteExternalSocketNotFound_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrLogTest_deleteExternalSocketNotFound_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrLogTest"
, "deleteExternalSocketNotFound", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4532), (::testing::internal::GetTypeId<IfaceMgrLogTest>
()), ::testing::internal::SuiteApiResolver< IfaceMgrLogTest
>::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4532), ::testing::internal::SuiteApiResolver< IfaceMgrLogTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4532), new ::testing::internal::TestFactoryImpl<IfaceMgrLogTest_deleteExternalSocketNotFound_Test
>); void IfaceMgrLogTest_deleteExternalSocketNotFound_Test
::TestBody()
{
4533 ASSERT_TRUE(ifacemgr_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr_)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4533, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr_", "false", "true") .c_str()) = ::testing::Message
()
;
4534 ASSERT_NO_THROW(ifacemgr_->addExternalSocket(100, 0))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr_->addExternalSocket(100, 0); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4534; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4534; } } else gtest_label_testnothrow_4534
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4534, ("Expected: " "ifacemgr_->addExternalSocket(100, 0)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4535 EXPECT_TRUE(ifacemgr_->isExternalSocket(100))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr_->isExternalSocket
(100))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4535, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr_->isExternalSocket(100)", "false", "true") .c_str
()) = ::testing::Message()
;
4536 ASSERT_NO_THROW(ifacemgr_->deleteExternalSocket(100))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr_->deleteExternalSocket(100); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4536; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4536; } } else gtest_label_testnothrow_4536
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4536, ("Expected: " "ifacemgr_->deleteExternalSocket(100)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4537 EXPECT_EQ(0U, countFile("DHCP_DELETE_EXTERNAL_SOCKET_NOT_FOUND"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("0U", "countFile(\"DHCP_DELETE_EXTERNAL_SOCKET_NOT_FOUND\")"
, 0U, countFile("DHCP_DELETE_EXTERNAL_SOCKET_NOT_FOUND")))) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4537, gtest_ar.failure_message()) = ::testing::Message()
;
4538 EXPECT_FALSE(ifacemgr_->isExternalSocket(100))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr_->isExternalSocket
(100)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4538, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr_->isExternalSocket(100)", "true", "false") .c_str
()) = ::testing::Message()
;
4539 ASSERT_NO_THROW(ifacemgr_->deleteExternalSocket(100))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr_->deleteExternalSocket(100); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4539; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4539; } } else gtest_label_testnothrow_4539
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4539, ("Expected: " "ifacemgr_->deleteExternalSocket(100)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4540 EXPECT_EQ(1U, countFile("DHCP_DELETE_EXTERNAL_SOCKET_NOT_FOUND"))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("1U", "countFile(\"DHCP_DELETE_EXTERNAL_SOCKET_NOT_FOUND\")"
, 1U, countFile("DHCP_DELETE_EXTERNAL_SOCKET_NOT_FOUND")))) ;
else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4540, gtest_ar.failure_message()) = ::testing::Message()
;
4541}
4542
4543// Test checks if the unicast sockets can be opened.
4544// This test is now disabled, because there is no reliable way to test it. We
4545// can't even use loopback, because openSockets() skips loopback interface
4546// (as it should be, because DHCP server is not supposed to listen on loopback).
4547TEST_F(IfaceMgrTest, DISABLED_openUnicastSockets)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("DISABLED_openUnicastSockets") > 1
, "test_name must not be empty"); class IfaceMgrTest_DISABLED_openUnicastSockets_Test
: public IfaceMgrTest { public: IfaceMgrTest_DISABLED_openUnicastSockets_Test
() = default; ~IfaceMgrTest_DISABLED_openUnicastSockets_Test(
) override = default; IfaceMgrTest_DISABLED_openUnicastSockets_Test
(const IfaceMgrTest_DISABLED_openUnicastSockets_Test &) =
delete; IfaceMgrTest_DISABLED_openUnicastSockets_Test & operator
=( const IfaceMgrTest_DISABLED_openUnicastSockets_Test &)
= delete; IfaceMgrTest_DISABLED_openUnicastSockets_Test (IfaceMgrTest_DISABLED_openUnicastSockets_Test
&&) noexcept = delete; IfaceMgrTest_DISABLED_openUnicastSockets_Test
& operator=( IfaceMgrTest_DISABLED_openUnicastSockets_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_DISABLED_openUnicastSockets_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "DISABLED_openUnicastSockets", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4547), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4547), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4547), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_DISABLED_openUnicastSockets_Test
>); void IfaceMgrTest_DISABLED_openUnicastSockets_Test::TestBody
()
{
4548 /// @todo Need to implement a test that is able to check whether we can open
4549 /// unicast sockets. There are 2 problems with it:
4550 /// 1. We need to have a non-link-local address on an interface that is
4551 /// up, running, IPv6 and multicast capable
4552 /// 2. We need that information on every OS that we run tests on. So far
4553 /// we are only supporting interface detection in Linux.
4554 ///
4555 /// To achieve this, we will probably need a pre-test setup, similar to what
4556 /// BIND9 is doing (i.e. configuring well known addresses on loopback).
4557
4558 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
4559
4560 // Get the interface (todo: which interface)
4561 IfacePtr iface = ifacemgr->getIface("eth0");
4562 ASSERT_TRUE(iface)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(iface)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4562, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "iface", "false", "true") .c_str()) = ::testing::Message()
;
4563 iface->inactive6_ = false;
4564
4565 // Tell the interface that it should bind to this global interface
4566 EXPECT_NO_THROW(iface->addUnicast(IOAddress("2001:db8::1")))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface->addUnicast(IOAddress("2001:db8::1")); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4566; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4566; } } else gtest_label_testnothrow_4566
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4566, ("Expected: " "iface->addUnicast(IOAddress(\"2001:db8::1\"))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4567
4568 // Tell IfaceMgr to open sockets. This should trigger at least 2 sockets
4569 // to open on eth0: link-local and global. On some systems (Linux), an
4570 // additional socket for multicast may be opened.
4571 EXPECT_TRUE(ifacemgr->openSockets6(PORT1))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->openSockets6
(PORT1))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4571, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->openSockets6(PORT1)", "false", "true") .c_str
()) = ::testing::Message()
;
4572
4573 const Iface::SocketCollection& sockets = iface->getSockets();
4574 ASSERT_GE(2U, sockets.size())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("2U", "sockets.size()"
, 2U, sockets.size()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4574, gtest_ar.failure_message()) = ::testing::Message()
;
4575
4576 // Global unicast should be first
4577 EXPECT_TRUE(getSocketByAddr(sockets, IOAddress("2001:db8::1")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(getSocketByAddr(sockets
, IOAddress("2001:db8::1")))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4577, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "getSocketByAddr(sockets, IOAddress(\"2001:db8::1\"))", "false"
, "true") .c_str()) = ::testing::Message()
;
4578 EXPECT_TRUE(getSocketByAddr(sockets, IOAddress("figure-out-link-local-addr")))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(getSocketByAddr(sockets
, IOAddress("figure-out-link-local-addr")))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4578, ::
testing::internal::GetBoolAssertionFailureMessage( gtest_ar_,
"getSocketByAddr(sockets, IOAddress(\"figure-out-link-local-addr\"))"
, "false", "true") .c_str()) = ::testing::Message()
;
4579}
4580
4581// Checks if there is a protection against unicast duplicates.
4582TEST_F(IfaceMgrTest, unicastDuplicates)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("unicastDuplicates") > 1, "test_name must not be empty"
); class IfaceMgrTest_unicastDuplicates_Test : public IfaceMgrTest
{ public: IfaceMgrTest_unicastDuplicates_Test() = default; ~
IfaceMgrTest_unicastDuplicates_Test() override = default; IfaceMgrTest_unicastDuplicates_Test
(const IfaceMgrTest_unicastDuplicates_Test &) = delete; IfaceMgrTest_unicastDuplicates_Test
& operator=( const IfaceMgrTest_unicastDuplicates_Test &
) = delete; IfaceMgrTest_unicastDuplicates_Test (IfaceMgrTest_unicastDuplicates_Test
&&) noexcept = delete; IfaceMgrTest_unicastDuplicates_Test
& operator=( IfaceMgrTest_unicastDuplicates_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_unicastDuplicates_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "unicastDuplicates", nullptr, nullptr, ::testing::internal::
CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4582), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4582), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4582), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_unicastDuplicates_Test
>); void IfaceMgrTest_unicastDuplicates_Test::TestBody()
{
4583 NakedIfaceMgr ifacemgr;
4584
4585 IfacePtr iface = ifacemgr.getIface(LOOPBACK_NAME);
4586 if (!iface) {
4587 cout << "Local loopback interface not found. Skipping test. " << endl;
4588 return;
4589 }
4590
4591 // Tell the interface that it should bind to this global interface
4592 // It is the first attempt so it should succeed
4593 EXPECT_NO_THROW(iface->addUnicast(IOAddress("2001:db8::1")))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
iface->addUnicast(IOAddress("2001:db8::1")); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4593; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4593; } } else gtest_label_testnothrow_4593
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4593, ("Expected: " "iface->addUnicast(IOAddress(\"2001:db8::1\"))"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4594
4595 // Tell the interface that it should bind to this global interface
4596 // It is the second attempt so it should fail
4597 EXPECT_THROW(iface->addUnicast(IOAddress("2001:db8::1")), BadValue)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { iface->addUnicast(IOAddress
("2001:db8::1")); } else static_assert(true, ""); } catch (BadValue
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< BadValue>::type>
::type, std::exception>::value, const ::testing::internal::
NeverThrown&, const std::exception&>::type e) { gtest_msg
.value = "Expected: " "iface->addUnicast(IOAddress(\"2001:db8::1\"))"
" throws an exception of type " "BadValue" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_4597
; } catch (...) { gtest_msg.value = "Expected: " "iface->addUnicast(IOAddress(\"2001:db8::1\"))"
" throws an exception of type " "BadValue" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_4597; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "iface->addUnicast(IOAddress(\"2001:db8::1\"))"
" throws an exception of type " "BadValue" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_4597; } } else gtest_label_testthrow_4597
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4597, gtest_msg.value.c_str()) = ::testing::Message()
;
4598}
4599
4600// This test requires addresses 2001:db8:15c::1/128 and fe80::1/64 to be
4601// configured on loopback interface
4602//
4603// Useful commands:
4604// ip a a 2001:db8:15c::1/128 dev lo
4605// ip a a fe80::1/64 dev lo
4606//
4607// If you do not issue those commands before running this test, it will fail.
4608TEST_F(IfaceMgrTest, DISABLED_getSocket)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("DISABLED_getSocket") > 1, "test_name must not be empty"
); class IfaceMgrTest_DISABLED_getSocket_Test : public IfaceMgrTest
{ public: IfaceMgrTest_DISABLED_getSocket_Test() = default; ~
IfaceMgrTest_DISABLED_getSocket_Test() override = default; IfaceMgrTest_DISABLED_getSocket_Test
(const IfaceMgrTest_DISABLED_getSocket_Test &) = delete;
IfaceMgrTest_DISABLED_getSocket_Test & operator=( const IfaceMgrTest_DISABLED_getSocket_Test
&) = delete; IfaceMgrTest_DISABLED_getSocket_Test (IfaceMgrTest_DISABLED_getSocket_Test
&&) noexcept = delete; IfaceMgrTest_DISABLED_getSocket_Test
& operator=( IfaceMgrTest_DISABLED_getSocket_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_DISABLED_getSocket_Test::test_info_
= ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "DISABLED_getSocket", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4608), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4608), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4608), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_DISABLED_getSocket_Test
>); void IfaceMgrTest_DISABLED_getSocket_Test::TestBody()
{
4609 // Testing socket operation in a portable way is tricky
4610 // without interface detection implemented.
4611
4612 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
4613
4614 IOAddress lo_addr("::1");
4615 IOAddress link_local("fe80::1");
4616 IOAddress global("2001:db8:15c::1");
4617
4618 IOAddress dst_link_local("fe80::dead:beef");
4619 IOAddress dst_global("2001:db8:15c::dead:beef");
4620
4621 // Bind loopback address
4622 int socket1 = ifacemgr->openSocket(LOOPBACK_NAME, lo_addr, 10547);
4623 EXPECT_GE(socket1, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket1", "0",
socket1, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4623, gtest_ar.failure_message()) = ::testing::Message()
; // socket >= 0
4624
4625 // Bind link-local address
4626 int socket2 = ifacemgr->openSocket(LOOPBACK_NAME, link_local, 10547);
4627 EXPECT_GE(socket2, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket2", "0",
socket2, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4627, gtest_ar.failure_message()) = ::testing::Message()
;
4628
4629 int socket3 = ifacemgr->openSocket(LOOPBACK_NAME, global, 10547);
4630 EXPECT_GE(socket3, 0)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("socket3", "0",
socket3, 0))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4630, gtest_ar.failure_message()) = ::testing::Message()
;
4631
4632 // Let's make sure those sockets are unique
4633 EXPECT_NE(socket1, socket2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("socket1", "socket2"
, socket1, socket2))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4633, gtest_ar.failure_message()) = ::testing::Message()
;
4634 EXPECT_NE(socket2, socket3)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("socket2", "socket3"
, socket2, socket3))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4634, gtest_ar.failure_message()) = ::testing::Message()
;
4635 EXPECT_NE(socket3, socket1)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("socket3", "socket1"
, socket3, socket1))) ; else ::testing::internal::AssertHelper
(::testing::TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4635, gtest_ar.failure_message()) = ::testing::Message()
;
4636
4637 // Create a packet
4638 Pkt6Ptr pkt6(new Pkt6(DHCPV6_SOLICIT, 123));
4639 pkt6->setIface(LOOPBACK_NAME);
4640 pkt6->setIndex(LOOPBACK_INDEX);
4641
4642 // Check that packets sent to link-local will get socket bound to link local
4643 pkt6->setLocalAddr(global);
4644 pkt6->setRemoteAddr(dst_global);
4645 EXPECT_EQ(socket3, ifacemgr->getSocket(pkt6))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("socket3"
, "ifacemgr->getSocket(pkt6)", socket3, ifacemgr->getSocket
(pkt6)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4645, gtest_ar.failure_message()) = ::testing::Message()
;
4646
4647 // Check that packets sent to link-local will get socket bound to link local
4648 pkt6->setLocalAddr(link_local);
4649 pkt6->setRemoteAddr(dst_link_local);
4650 EXPECT_EQ(socket2, ifacemgr->getSocket(pkt6))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("socket2"
, "ifacemgr->getSocket(pkt6)", socket2, ifacemgr->getSocket
(pkt6)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4650, gtest_ar.failure_message()) = ::testing::Message()
;
4651
4652 // Close sockets here because the following tests will want to
4653 // open sockets on the same ports.
4654 ifacemgr->closeSockets();
4655}
4656
4657// Verifies DHCPv4 behavior of configureDHCPPacketQueue()
4658TEST_F(IfaceMgrTest, configureDHCPPacketQueueTest4)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("configureDHCPPacketQueueTest4") >
1, "test_name must not be empty"); class IfaceMgrTest_configureDHCPPacketQueueTest4_Test
: public IfaceMgrTest { public: IfaceMgrTest_configureDHCPPacketQueueTest4_Test
() = default; ~IfaceMgrTest_configureDHCPPacketQueueTest4_Test
() override = default; IfaceMgrTest_configureDHCPPacketQueueTest4_Test
(const IfaceMgrTest_configureDHCPPacketQueueTest4_Test &
) = delete; IfaceMgrTest_configureDHCPPacketQueueTest4_Test &
operator=( const IfaceMgrTest_configureDHCPPacketQueueTest4_Test
&) = delete; IfaceMgrTest_configureDHCPPacketQueueTest4_Test
(IfaceMgrTest_configureDHCPPacketQueueTest4_Test &&)
noexcept = delete; IfaceMgrTest_configureDHCPPacketQueueTest4_Test
& operator=( IfaceMgrTest_configureDHCPPacketQueueTest4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_configureDHCPPacketQueueTest4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "configureDHCPPacketQueueTest4", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4658), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4658), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4658), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_configureDHCPPacketQueueTest4_Test
>); void IfaceMgrTest_configureDHCPPacketQueueTest4_Test::
TestBody()
{
4659 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
4660
4661 // First let's make sure there is no queue and no thread.
4662 ASSERT_FALSE(ifacemgr->getPacketQueue4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->getPacketQueue4
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4662, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->getPacketQueue4()", "true", "false") .c_str()
) = ::testing::Message()
;
4663 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4663, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
4664
4665 bool queue_enabled = false;
4666 // Given an empty pointer, we should default to no queue.
4667 data::ConstElementPtr queue_control;
4668 ASSERT_NO_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET, queue_control))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
queue_enabled = ifacemgr->configureDHCPPacketQueue(2, queue_control
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4668; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4668
; } } else gtest_label_testnothrow_4668 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4668, ("Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(2, queue_control)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4669 EXPECT_FALSE(queue_enabled)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(queue_enabled))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4669, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "queue_enabled", "true", "false") .c_str()) = ::testing::Message
()
;
4670 EXPECT_FALSE(ifacemgr->getPacketQueue4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->getPacketQueue4
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4670, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->getPacketQueue4()", "true", "false") .c_str()
) = ::testing::Message()
;
4671 // configureDHCPPacketQueue() should never start the thread.
4672 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4672, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
4673
4674 // Verify that calling startDHCPReceiver with no queue, does NOT start the thread.
4675 ASSERT_NO_THROW(ifacemgr->startDHCPReceiver(AF_INET))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->startDHCPReceiver(2); } else static_assert(true
, ""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4675
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4675
; } } else gtest_label_testnothrow_4675 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4675, ("Expected: " "ifacemgr->startDHCPReceiver(2)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4676 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4676, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
4677
4678 // Now let's try with a populated queue control, but with enable-queue = false.
4679 queue_control = makeQueueConfig(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4, 500, false);
4680 ASSERT_NO_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET, queue_control))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
queue_enabled = ifacemgr->configureDHCPPacketQueue(2, queue_control
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4680; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4680
; } } else gtest_label_testnothrow_4680 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4680, ("Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(2, queue_control)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4681 EXPECT_FALSE(queue_enabled)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(queue_enabled))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4681, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "queue_enabled", "true", "false") .c_str()) = ::testing::Message
()
;
4682 EXPECT_FALSE(ifacemgr->getPacketQueue4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->getPacketQueue4
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4682, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->getPacketQueue4()", "true", "false") .c_str()
) = ::testing::Message()
;
4683 // configureDHCPPacketQueue() should never start the thread.
4684 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4684, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
4685
4686 // Now let's enable the queue.
4687 queue_control = makeQueueConfig(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4, 500, true);
4688 ASSERT_NO_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET, queue_control))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
queue_enabled = ifacemgr->configureDHCPPacketQueue(2, queue_control
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4688; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4688
; } } else gtest_label_testnothrow_4688 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4688, ("Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(2, queue_control)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4689 ASSERT_TRUE(queue_enabled)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(queue_enabled)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4689, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "queue_enabled", "false", "true") .c_str()) = ::testing::Message
()
;
4690 // Verify we have correctly created the queue.
4691 CHECK_QUEUE_INFO(ifacemgr->getPacketQueue4(), "{ \"capacity\": 500, \"queue-type\": \""{ std::ostringstream oss__; oss__ << "{ \"capacity\": 500, \"queue-type\": \""
<< PacketQueueMgr4::DEFAULT_QUEUE_TYPE4 << "\", \"size\": 0 }"
; checkInfo(ifacemgr->getPacketQueue4(), oss__.str().c_str
()); }
4692 << PacketQueueMgr4::DEFAULT_QUEUE_TYPE4 << "\", \"size\": 0 }"){ std::ostringstream oss__; oss__ << "{ \"capacity\": 500, \"queue-type\": \""
<< PacketQueueMgr4::DEFAULT_QUEUE_TYPE4 << "\", \"size\": 0 }"
; checkInfo(ifacemgr->getPacketQueue4(), oss__.str().c_str
()); }
;
4693 // configureDHCPPacketQueue() should never start the thread.
4694 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4694, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
4695
4696 // Calling startDHCPReceiver with a queue, should start the thread.
4697 ASSERT_NO_THROW(ifacemgr->startDHCPReceiver(AF_INET))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->startDHCPReceiver(2); } else static_assert(true
, ""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4697
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4697
; } } else gtest_label_testnothrow_4697 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4697, ("Expected: " "ifacemgr->startDHCPReceiver(2)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4698 ASSERT_TRUE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->isDHCPReceiverRunning
())) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4698, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "false", "true") .c_str
()) = ::testing::Message()
;
4699
4700 // Verify that calling startDHCPReceiver when the thread is running, throws.
4701 ASSERT_THROW(ifacemgr->startDHCPReceiver(AF_INET), InvalidOperation)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->startDHCPReceiver
(2); } else static_assert(true, ""); } catch (InvalidOperation
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< InvalidOperation>::
type>::type, std::exception>::value, const ::testing::internal
::NeverThrown&, const std::exception&>::type e) { gtest_msg
.value = "Expected: " "ifacemgr->startDHCPReceiver(2)" " throws an exception of type "
"InvalidOperation" ".\n Actual: it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_4701; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->startDHCPReceiver(2)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_4701; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->startDHCPReceiver(2)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_4701; } } else gtest_label_testthrow_4701
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4701, gtest_msg.value.c_str()) = ::testing::Message()
;
4702
4703 // Create a disabled config.
4704 queue_control = makeQueueConfig(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4, 500, false);
4705
4706 // Trying to reconfigure with a running thread should throw.
4707 ASSERT_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET, queue_control),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { queue_enabled = ifacemgr
->configureDHCPPacketQueue(2, queue_control); } else static_assert
(true, ""); } catch (InvalidOperation const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
InvalidOperation>::type>::type, std::exception>::value
, const ::testing::internal::NeverThrown&, const std::exception
&>::type e) { gtest_msg.value = "Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(2, queue_control)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_4708
; } catch (...) { gtest_msg.value = "Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(2, queue_control)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_4708; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(2, queue_control)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_4708; } } else gtest_label_testthrow_4708
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4708, gtest_msg.value.c_str()) = ::testing::Message()
4708 InvalidOperation)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { queue_enabled = ifacemgr
->configureDHCPPacketQueue(2, queue_control); } else static_assert
(true, ""); } catch (InvalidOperation const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
InvalidOperation>::type>::type, std::exception>::value
, const ::testing::internal::NeverThrown&, const std::exception
&>::type e) { gtest_msg.value = "Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(2, queue_control)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_4708
; } catch (...) { gtest_msg.value = "Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(2, queue_control)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_4708; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(2, queue_control)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_4708; } } else gtest_label_testthrow_4708
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4708, gtest_msg.value.c_str()) = ::testing::Message()
;
4709
4710 // We should still have our queue and the thread should still be running.
4711 EXPECT_TRUE(ifacemgr->getPacketQueue4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->getPacketQueue4
())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4711, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->getPacketQueue4()", "false", "true") .c_str()
) = ::testing::Message()
;
4712 ASSERT_TRUE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->isDHCPReceiverRunning
())) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4712, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "false", "true") .c_str
()) = ::testing::Message()
;
4713
4714 const isc::asiolink::IOAddress addr("::");
4715 const uint16_t port = 0;
4716 Pkt4Ptr pkt;
4717 SocketInfo si(addr, port, 0);
4718 ifacemgr->getPacketQueue4()->enqueuePacket(pkt, si);
4719 ASSERT_FALSE(ifacemgr->getPacketQueue4()->empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->getPacketQueue4
()->empty()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4719, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->getPacketQueue4()->empty()", "true", "false"
) .c_str()) = ::testing::Message()
;
4720
4721 // Now let's stop stop the thread.
4722 ASSERT_NO_THROW(ifacemgr->stopDHCPReceiver())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->stopDHCPReceiver(); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4722
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4722
; } } else gtest_label_testnothrow_4722 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4722, ("Expected: " "ifacemgr->stopDHCPReceiver()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4723 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4723, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
4724 // Stopping the thread should not destroy the queue.
4725 ASSERT_TRUE(ifacemgr->getPacketQueue4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->getPacketQueue4
())) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4725, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->getPacketQueue4()", "false", "true") .c_str()
) = ::testing::Message()
;
4726 ASSERT_TRUE(ifacemgr->getPacketQueue4()->empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->getPacketQueue4
()->empty())) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4726, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->getPacketQueue4()->empty()", "false", "true"
) .c_str()) = ::testing::Message()
;
4727
4728 // Reconfigure with the queue turned off. We should have neither queue nor thread.
4729 ASSERT_NO_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET, queue_control))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
queue_enabled = ifacemgr->configureDHCPPacketQueue(2, queue_control
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4729; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4729
; } } else gtest_label_testnothrow_4729 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4729, ("Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(2, queue_control)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4730 EXPECT_FALSE(ifacemgr->getPacketQueue4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->getPacketQueue4
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4730, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->getPacketQueue4()", "true", "false") .c_str()
) = ::testing::Message()
;
4731 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4731, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
4732}
4733
4734// Verifies DHCPv6 behavior of configureDHCPPacketQueue()
4735TEST_F(IfaceMgrTest, configureDHCPPacketQueueTest6)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("configureDHCPPacketQueueTest6") >
1, "test_name must not be empty"); class IfaceMgrTest_configureDHCPPacketQueueTest6_Test
: public IfaceMgrTest { public: IfaceMgrTest_configureDHCPPacketQueueTest6_Test
() = default; ~IfaceMgrTest_configureDHCPPacketQueueTest6_Test
() override = default; IfaceMgrTest_configureDHCPPacketQueueTest6_Test
(const IfaceMgrTest_configureDHCPPacketQueueTest6_Test &
) = delete; IfaceMgrTest_configureDHCPPacketQueueTest6_Test &
operator=( const IfaceMgrTest_configureDHCPPacketQueueTest6_Test
&) = delete; IfaceMgrTest_configureDHCPPacketQueueTest6_Test
(IfaceMgrTest_configureDHCPPacketQueueTest6_Test &&)
noexcept = delete; IfaceMgrTest_configureDHCPPacketQueueTest6_Test
& operator=( IfaceMgrTest_configureDHCPPacketQueueTest6_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_configureDHCPPacketQueueTest6_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "configureDHCPPacketQueueTest6", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4735), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4735), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4735), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_configureDHCPPacketQueueTest6_Test
>); void IfaceMgrTest_configureDHCPPacketQueueTest6_Test::
TestBody()
{
4736 scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
4737
4738 // First let's make sure there is no queue and no thread.
4739 ASSERT_FALSE(ifacemgr->getPacketQueue6())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->getPacketQueue6
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4739, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->getPacketQueue6()", "true", "false") .c_str()
) = ::testing::Message()
;
4740 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4740, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
4741
4742 bool queue_enabled = false;
4743 // Given an empty pointer, we should default to no queue.
4744 data::ConstElementPtr queue_control;
4745 ASSERT_NO_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET, queue_control))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
queue_enabled = ifacemgr->configureDHCPPacketQueue(2, queue_control
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4745; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4745
; } } else gtest_label_testnothrow_4745 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4745, ("Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(2, queue_control)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4746 EXPECT_FALSE(queue_enabled)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(queue_enabled))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4746, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "queue_enabled", "true", "false") .c_str()) = ::testing::Message
()
;
4747 EXPECT_FALSE(ifacemgr->getPacketQueue6())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->getPacketQueue6
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4747, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->getPacketQueue6()", "true", "false") .c_str()
) = ::testing::Message()
;
4748 // configureDHCPPacketQueue() should never start the thread.
4749 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4749, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
4750
4751 // Verify that calling startDHCPReceiver with no queue, does NOT start the thread.
4752 ASSERT_NO_THROW(ifacemgr->startDHCPReceiver(AF_INET))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->startDHCPReceiver(2); } else static_assert(true
, ""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4752
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4752
; } } else gtest_label_testnothrow_4752 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4752, ("Expected: " "ifacemgr->startDHCPReceiver(2)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4753 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4753, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
4754
4755 // Now let's try with a populated queue control, but with enable-queue = false.
4756 queue_control = makeQueueConfig(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6, 500, false);
4757 ASSERT_NO_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET6, queue_control))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
queue_enabled = ifacemgr->configureDHCPPacketQueue(10, queue_control
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4757; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4757
; } } else gtest_label_testnothrow_4757 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4757, ("Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(10, queue_control)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4758 EXPECT_FALSE(queue_enabled)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(queue_enabled))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4758, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "queue_enabled", "true", "false") .c_str()) = ::testing::Message
()
;
4759 EXPECT_FALSE(ifacemgr->getPacketQueue6())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->getPacketQueue6
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4759, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->getPacketQueue6()", "true", "false") .c_str()
) = ::testing::Message()
;
4760 // configureDHCPPacketQueue() should never start the thread.
4761 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4761, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
4762
4763 // Now let's enable the queue.
4764 queue_control = makeQueueConfig(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6, 500, true);
4765 ASSERT_NO_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET6, queue_control))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
queue_enabled = ifacemgr->configureDHCPPacketQueue(10, queue_control
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4765; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4765
; } } else gtest_label_testnothrow_4765 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4765, ("Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(10, queue_control)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4766 ASSERT_TRUE(queue_enabled)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(queue_enabled)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4766, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "queue_enabled", "false", "true") .c_str()) = ::testing::Message
()
;
4767 // Verify we have correctly created the queue.
4768 CHECK_QUEUE_INFO(ifacemgr->getPacketQueue6(), "{ \"capacity\": 500, \"queue-type\": \""{ std::ostringstream oss__; oss__ << "{ \"capacity\": 500, \"queue-type\": \""
<< PacketQueueMgr6::DEFAULT_QUEUE_TYPE6 << "\", \"size\": 0 }"
; checkInfo(ifacemgr->getPacketQueue6(), oss__.str().c_str
()); }
4769 << PacketQueueMgr6::DEFAULT_QUEUE_TYPE6 << "\", \"size\": 0 }"){ std::ostringstream oss__; oss__ << "{ \"capacity\": 500, \"queue-type\": \""
<< PacketQueueMgr6::DEFAULT_QUEUE_TYPE6 << "\", \"size\": 0 }"
; checkInfo(ifacemgr->getPacketQueue6(), oss__.str().c_str
()); }
;
4770 // configureDHCPPacketQueue() should never start the thread.
4771 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4771, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
4772
4773 // Calling startDHCPReceiver with a queue, should start the thread.
4774 ASSERT_NO_THROW(ifacemgr->startDHCPReceiver(AF_INET6))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->startDHCPReceiver(10); } else static_assert(true
, ""); } catch (std::exception const& e) { gtest_msg.value
= "it throws "; gtest_msg.value += ::testing::internal::GetTypeName
(typeid(e)); gtest_msg.value += " with description \""; gtest_msg
.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4774
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4774
; } } else gtest_label_testnothrow_4774 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4774, ("Expected: " "ifacemgr->startDHCPReceiver(10)" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4775 ASSERT_TRUE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->isDHCPReceiverRunning
())) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4775, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "false", "true") .c_str
()) = ::testing::Message()
;
4776
4777 // Verify that calling startDHCPReceiver when the thread is running, throws.
4778 ASSERT_THROW(ifacemgr->startDHCPReceiver(AF_INET6), InvalidOperation)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { ifacemgr->startDHCPReceiver
(10); } else static_assert(true, ""); } catch (InvalidOperation
const&) { gtest_caught_expected = true; } catch (typename
std::conditional< std::is_same<typename std::remove_cv
<typename std::remove_reference< InvalidOperation>::
type>::type, std::exception>::value, const ::testing::internal
::NeverThrown&, const std::exception&>::type e) { gtest_msg
.value = "Expected: " "ifacemgr->startDHCPReceiver(10)" " throws an exception of type "
"InvalidOperation" ".\n Actual: it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testthrow_4778; } catch (...
) { gtest_msg.value = "Expected: " "ifacemgr->startDHCPReceiver(10)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_4778; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "ifacemgr->startDHCPReceiver(10)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_4778; } } else gtest_label_testthrow_4778
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4778, gtest_msg.value.c_str()) = ::testing::Message()
;
4779
4780 // Create a disabled config.
4781 queue_control = makeQueueConfig(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6, 500, false);
4782
4783 // Trying to reconfigure with a running thread should throw.
4784 ASSERT_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET6, queue_control),switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { queue_enabled = ifacemgr
->configureDHCPPacketQueue(10, queue_control); } else static_assert
(true, ""); } catch (InvalidOperation const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
InvalidOperation>::type>::type, std::exception>::value
, const ::testing::internal::NeverThrown&, const std::exception
&>::type e) { gtest_msg.value = "Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(10, queue_control)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_4785
; } catch (...) { gtest_msg.value = "Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(10, queue_control)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_4785; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(10, queue_control)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_4785; } } else gtest_label_testthrow_4785
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4785, gtest_msg.value.c_str()) = ::testing::Message()
4785 InvalidOperation)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { queue_enabled = ifacemgr
->configureDHCPPacketQueue(10, queue_control); } else static_assert
(true, ""); } catch (InvalidOperation const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
InvalidOperation>::type>::type, std::exception>::value
, const ::testing::internal::NeverThrown&, const std::exception
&>::type e) { gtest_msg.value = "Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(10, queue_control)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_4785
; } catch (...) { gtest_msg.value = "Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(10, queue_control)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws a different type."
; goto gtest_label_testthrow_4785; } if (!gtest_caught_expected
) { gtest_msg.value = "Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(10, queue_control)"
" throws an exception of type " "InvalidOperation" ".\n Actual: it throws nothing."
; goto gtest_label_testthrow_4785; } } else gtest_label_testthrow_4785
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4785, gtest_msg.value.c_str()) = ::testing::Message()
;
4786
4787 // We should still have our queue and the thread should still be running.
4788 EXPECT_TRUE(ifacemgr->getPacketQueue6())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->getPacketQueue6
())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4788, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->getPacketQueue6()", "false", "true") .c_str()
) = ::testing::Message()
;
4789 ASSERT_TRUE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->isDHCPReceiverRunning
())) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4789, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "false", "true") .c_str
()) = ::testing::Message()
;
4790
4791 const isc::asiolink::IOAddress addr("::");
4792 const uint16_t port = 0;
4793 Pkt6Ptr pkt;
4794 SocketInfo si(addr, port, 0);
4795 ifacemgr->getPacketQueue6()->enqueuePacket(pkt, si);
4796 ASSERT_FALSE(ifacemgr->getPacketQueue6()->empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->getPacketQueue6
()->empty()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4796, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->getPacketQueue6()->empty()", "true", "false"
) .c_str()) = ::testing::Message()
;
4797
4798 // Now let's stop stop the thread.
4799 ASSERT_NO_THROW(ifacemgr->stopDHCPReceiver())switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
ifacemgr->stopDHCPReceiver(); } else static_assert(true, ""
); } catch (std::exception const& e) { gtest_msg.value = "it throws "
; gtest_msg.value += ::testing::internal::GetTypeName(typeid(
e)); gtest_msg.value += " with description \""; gtest_msg.value
+= e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4799
; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4799
; } } else gtest_label_testnothrow_4799 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4799, ("Expected: " "ifacemgr->stopDHCPReceiver()" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
;
4800 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4800, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
4801 // Stopping the thread should not destroy the queue.
4802 ASSERT_TRUE(ifacemgr->getPacketQueue6())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->getPacketQueue6
())) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4802, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->getPacketQueue6()", "false", "true") .c_str()
) = ::testing::Message()
;
4803 ASSERT_TRUE(ifacemgr->getPacketQueue6()->empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(ifacemgr->getPacketQueue6
()->empty())) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4803, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->getPacketQueue6()->empty()", "false", "true"
) .c_str()) = ::testing::Message()
;
4804
4805 // Reconfigure with the queue turned off. We should have neither queue nor thread.
4806 ASSERT_NO_THROW(queue_enabled = ifacemgr->configureDHCPPacketQueue(AF_INET6, queue_control))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
queue_enabled = ifacemgr->configureDHCPPacketQueue(10, queue_control
); } else static_assert(true, ""); } catch (std::exception const
& e) { gtest_msg.value = "it throws "; gtest_msg.value +=
::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4806; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4806
; } } else gtest_label_testnothrow_4806 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4806, ("Expected: " "queue_enabled = ifacemgr->configureDHCPPacketQueue(10, queue_control)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4807 EXPECT_FALSE(ifacemgr->getPacketQueue6())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->getPacketQueue6
()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4807, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->getPacketQueue6()", "true", "false") .c_str()
) = ::testing::Message()
;
4808 ASSERT_FALSE(ifacemgr->isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(ifacemgr->isDHCPReceiverRunning
()))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4808, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "ifacemgr->isDHCPReceiverRunning()", "true", "false") .c_str
()) = ::testing::Message()
;
4809}
4810
4811TEST_F(IfaceMgrTest, directReceive4RotateAll)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("directReceive4RotateAll") > 1, "test_name must not be empty"
); class IfaceMgrTest_directReceive4RotateAll_Test : public IfaceMgrTest
{ public: IfaceMgrTest_directReceive4RotateAll_Test() = default
; ~IfaceMgrTest_directReceive4RotateAll_Test() override = default
; IfaceMgrTest_directReceive4RotateAll_Test (const IfaceMgrTest_directReceive4RotateAll_Test
&) = delete; IfaceMgrTest_directReceive4RotateAll_Test &
operator=( const IfaceMgrTest_directReceive4RotateAll_Test &
) = delete; IfaceMgrTest_directReceive4RotateAll_Test (IfaceMgrTest_directReceive4RotateAll_Test
&&) noexcept = delete; IfaceMgrTest_directReceive4RotateAll_Test
& operator=( IfaceMgrTest_directReceive4RotateAll_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_directReceive4RotateAll_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "directReceive4RotateAll", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4811), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4811), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4811), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_directReceive4RotateAll_Test
>); void IfaceMgrTest_directReceive4RotateAll_Test::TestBody
()
{
4812 testReceive4RotateAll();
4813}
4814
4815TEST_F(IfaceMgrTest, indirectReceive4RotateAll)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("indirectReceive4RotateAll") > 1, "test_name must not be empty"
); class IfaceMgrTest_indirectReceive4RotateAll_Test : public
IfaceMgrTest { public: IfaceMgrTest_indirectReceive4RotateAll_Test
() = default; ~IfaceMgrTest_indirectReceive4RotateAll_Test() override
= default; IfaceMgrTest_indirectReceive4RotateAll_Test (const
IfaceMgrTest_indirectReceive4RotateAll_Test &) = delete;
IfaceMgrTest_indirectReceive4RotateAll_Test & operator=(
const IfaceMgrTest_indirectReceive4RotateAll_Test &) = delete
; IfaceMgrTest_indirectReceive4RotateAll_Test (IfaceMgrTest_indirectReceive4RotateAll_Test
&&) noexcept = delete; IfaceMgrTest_indirectReceive4RotateAll_Test
& operator=( IfaceMgrTest_indirectReceive4RotateAll_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_indirectReceive4RotateAll_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "indirectReceive4RotateAll", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4815), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4815), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4815), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_indirectReceive4RotateAll_Test
>); void IfaceMgrTest_indirectReceive4RotateAll_Test::TestBody
()
{
4816 testReceive4RotateAll(false);
4817}
4818
4819TEST_F(IfaceMgrTest, directReceive6RotateAll)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("directReceive6RotateAll") > 1, "test_name must not be empty"
); class IfaceMgrTest_directReceive6RotateAll_Test : public IfaceMgrTest
{ public: IfaceMgrTest_directReceive6RotateAll_Test() = default
; ~IfaceMgrTest_directReceive6RotateAll_Test() override = default
; IfaceMgrTest_directReceive6RotateAll_Test (const IfaceMgrTest_directReceive6RotateAll_Test
&) = delete; IfaceMgrTest_directReceive6RotateAll_Test &
operator=( const IfaceMgrTest_directReceive6RotateAll_Test &
) = delete; IfaceMgrTest_directReceive6RotateAll_Test (IfaceMgrTest_directReceive6RotateAll_Test
&&) noexcept = delete; IfaceMgrTest_directReceive6RotateAll_Test
& operator=( IfaceMgrTest_directReceive6RotateAll_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_directReceive6RotateAll_Test::
test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "directReceive6RotateAll", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4819), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4819), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4819), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_directReceive6RotateAll_Test
>); void IfaceMgrTest_directReceive6RotateAll_Test::TestBody
()
{
4820 testReceive6RotateAll();
4821}
4822
4823TEST_F(IfaceMgrTest, indirectReceive6RotateAll)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("indirectReceive6RotateAll") > 1, "test_name must not be empty"
); class IfaceMgrTest_indirectReceive6RotateAll_Test : public
IfaceMgrTest { public: IfaceMgrTest_indirectReceive6RotateAll_Test
() = default; ~IfaceMgrTest_indirectReceive6RotateAll_Test() override
= default; IfaceMgrTest_indirectReceive6RotateAll_Test (const
IfaceMgrTest_indirectReceive6RotateAll_Test &) = delete;
IfaceMgrTest_indirectReceive6RotateAll_Test & operator=(
const IfaceMgrTest_indirectReceive6RotateAll_Test &) = delete
; IfaceMgrTest_indirectReceive6RotateAll_Test (IfaceMgrTest_indirectReceive6RotateAll_Test
&&) noexcept = delete; IfaceMgrTest_indirectReceive6RotateAll_Test
& operator=( IfaceMgrTest_indirectReceive6RotateAll_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_indirectReceive6RotateAll_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "indirectReceive6RotateAll", nullptr, nullptr, ::testing::internal
::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4823), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4823), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4823), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_indirectReceive6RotateAll_Test
>); void IfaceMgrTest_indirectReceive6RotateAll_Test::TestBody
()
{
4824 testReceive6RotateAll(false);
4825}
4826
4827TEST_F(IfaceMgrTest, directReceive4RotateIfaces)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("directReceive4RotateIfaces") > 1,
"test_name must not be empty"); class IfaceMgrTest_directReceive4RotateIfaces_Test
: public IfaceMgrTest { public: IfaceMgrTest_directReceive4RotateIfaces_Test
() = default; ~IfaceMgrTest_directReceive4RotateIfaces_Test()
override = default; IfaceMgrTest_directReceive4RotateIfaces_Test
(const IfaceMgrTest_directReceive4RotateIfaces_Test &) =
delete; IfaceMgrTest_directReceive4RotateIfaces_Test & operator
=( const IfaceMgrTest_directReceive4RotateIfaces_Test &) =
delete; IfaceMgrTest_directReceive4RotateIfaces_Test (IfaceMgrTest_directReceive4RotateIfaces_Test
&&) noexcept = delete; IfaceMgrTest_directReceive4RotateIfaces_Test
& operator=( IfaceMgrTest_directReceive4RotateIfaces_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_directReceive4RotateIfaces_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "directReceive4RotateIfaces", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4827), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4827), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4827), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_directReceive4RotateIfaces_Test
>); void IfaceMgrTest_directReceive4RotateIfaces_Test::TestBody
()
{
4828 testReceive4RotateIfaces();
4829}
4830
4831TEST_F(IfaceMgrTest, indirectReceive4RotateIfaces)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("indirectReceive4RotateIfaces") > 1
, "test_name must not be empty"); class IfaceMgrTest_indirectReceive4RotateIfaces_Test
: public IfaceMgrTest { public: IfaceMgrTest_indirectReceive4RotateIfaces_Test
() = default; ~IfaceMgrTest_indirectReceive4RotateIfaces_Test
() override = default; IfaceMgrTest_indirectReceive4RotateIfaces_Test
(const IfaceMgrTest_indirectReceive4RotateIfaces_Test &)
= delete; IfaceMgrTest_indirectReceive4RotateIfaces_Test &
operator=( const IfaceMgrTest_indirectReceive4RotateIfaces_Test
&) = delete; IfaceMgrTest_indirectReceive4RotateIfaces_Test
(IfaceMgrTest_indirectReceive4RotateIfaces_Test &&) noexcept
= delete; IfaceMgrTest_indirectReceive4RotateIfaces_Test &
operator=( IfaceMgrTest_indirectReceive4RotateIfaces_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_indirectReceive4RotateIfaces_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "indirectReceive4RotateIfaces", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4831), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4831), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4831), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_indirectReceive4RotateIfaces_Test
>); void IfaceMgrTest_indirectReceive4RotateIfaces_Test::TestBody
()
{
4832 testReceive4RotateIfaces(false);
4833}
4834
4835TEST_F(IfaceMgrTest, directReceive6RotateIfaces)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("directReceive6RotateIfaces") > 1,
"test_name must not be empty"); class IfaceMgrTest_directReceive6RotateIfaces_Test
: public IfaceMgrTest { public: IfaceMgrTest_directReceive6RotateIfaces_Test
() = default; ~IfaceMgrTest_directReceive6RotateIfaces_Test()
override = default; IfaceMgrTest_directReceive6RotateIfaces_Test
(const IfaceMgrTest_directReceive6RotateIfaces_Test &) =
delete; IfaceMgrTest_directReceive6RotateIfaces_Test & operator
=( const IfaceMgrTest_directReceive6RotateIfaces_Test &) =
delete; IfaceMgrTest_directReceive6RotateIfaces_Test (IfaceMgrTest_directReceive6RotateIfaces_Test
&&) noexcept = delete; IfaceMgrTest_directReceive6RotateIfaces_Test
& operator=( IfaceMgrTest_directReceive6RotateIfaces_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_directReceive6RotateIfaces_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "directReceive6RotateIfaces", nullptr, nullptr, ::testing::
internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4835), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4835), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4835), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_directReceive6RotateIfaces_Test
>); void IfaceMgrTest_directReceive6RotateIfaces_Test::TestBody
()
{
4836 testReceive6RotateIfaces();
4837}
4838
4839TEST_F(IfaceMgrTest, indirectReceive6RotateIfaces)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("indirectReceive6RotateIfaces") > 1
, "test_name must not be empty"); class IfaceMgrTest_indirectReceive6RotateIfaces_Test
: public IfaceMgrTest { public: IfaceMgrTest_indirectReceive6RotateIfaces_Test
() = default; ~IfaceMgrTest_indirectReceive6RotateIfaces_Test
() override = default; IfaceMgrTest_indirectReceive6RotateIfaces_Test
(const IfaceMgrTest_indirectReceive6RotateIfaces_Test &)
= delete; IfaceMgrTest_indirectReceive6RotateIfaces_Test &
operator=( const IfaceMgrTest_indirectReceive6RotateIfaces_Test
&) = delete; IfaceMgrTest_indirectReceive6RotateIfaces_Test
(IfaceMgrTest_indirectReceive6RotateIfaces_Test &&) noexcept
= delete; IfaceMgrTest_indirectReceive6RotateIfaces_Test &
operator=( IfaceMgrTest_indirectReceive6RotateIfaces_Test &&
) noexcept = delete; private: void TestBody() override; [[maybe_unused
]] static ::testing::TestInfo* const test_info_; }; ::testing
::TestInfo* const IfaceMgrTest_indirectReceive6RotateIfaces_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "indirectReceive6RotateIfaces", nullptr, nullptr, ::testing
::internal::CodeLocation("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4839), (::testing::internal::GetTypeId<IfaceMgrTest>(
)), ::testing::internal::SuiteApiResolver< IfaceMgrTest>
::GetSetUpCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4839), ::testing::internal::SuiteApiResolver< IfaceMgrTest
>::GetTearDownCaseOrSuite("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4839), new ::testing::internal::TestFactoryImpl<IfaceMgrTest_indirectReceive6RotateIfaces_Test
>); void IfaceMgrTest_indirectReceive6RotateIfaces_Test::TestBody
()
{
4840 testReceive6RotateIfaces(false);
4841}
4842
4843TEST_F(IfaceMgrTest, receiverCS4)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("receiverCS4") > 1, "test_name must not be empty"
); class IfaceMgrTest_receiverCS4_Test : public IfaceMgrTest {
public: IfaceMgrTest_receiverCS4_Test() = default; ~IfaceMgrTest_receiverCS4_Test
() override = default; IfaceMgrTest_receiverCS4_Test (const IfaceMgrTest_receiverCS4_Test
&) = delete; IfaceMgrTest_receiverCS4_Test & operator
=( const IfaceMgrTest_receiverCS4_Test &) = delete; IfaceMgrTest_receiverCS4_Test
(IfaceMgrTest_receiverCS4_Test &&) noexcept = delete
; IfaceMgrTest_receiverCS4_Test & operator=( IfaceMgrTest_receiverCS4_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_receiverCS4_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "receiverCS4", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4843), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4843), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4843), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_receiverCS4_Test
>); void IfaceMgrTest_receiverCS4_Test::TestBody()
{
4844 const isc::asiolink::IOAddress addr("::");
4845 const uint16_t port = 0;
4846 Pkt4Ptr pkt;
4847 SocketInfo si(addr, port, 0);
4848 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue4()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4848, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue4()", "true", "false") .
c_str()) = ::testing::Message()
;
4849 ASSERT_FALSE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).isDHCPReceiverRunning()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4849, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "true", "false"
) .c_str()) = ::testing::Message()
;
4850 {
4851 ReceiverCriticalSection rcs;
4852 ASSERT_FALSE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).isDHCPReceiverRunning()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4852, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "true", "false"
) .c_str()) = ::testing::Message()
;
4853 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue4()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4853, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue4()", "true", "false") .
c_str()) = ::testing::Message()
;
4854 {
4855 ReceiverCriticalSection rcs_deep;
4856 ASSERT_FALSE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).isDHCPReceiverRunning()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4856, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "true", "false"
) .c_str()) = ::testing::Message()
;
4857 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue4()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4857, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue4()", "true", "false") .
c_str()) = ::testing::Message()
;
4858 }
4859 ASSERT_FALSE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).isDHCPReceiverRunning()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4859, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "true", "false"
) .c_str()) = ::testing::Message()
;
4860 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue4()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4860, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue4()", "true", "false") .
c_str()) = ::testing::Message()
;
4861 }
4862 ASSERT_FALSE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).isDHCPReceiverRunning()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4862, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "true", "false"
) .c_str()) = ::testing::Message()
;
4863 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue4())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue4()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4863, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue4()", "true", "false") .
c_str()) = ::testing::Message()
;
4864 bool queue_enabled = false;
4865 data::ConstElementPtr config = makeQueueConfig(PacketQueueMgr4::DEFAULT_QUEUE_TYPE4, 500);
4866 ASSERT_NO_THROW(queue_enabled = IfaceMgr::instance().configureDHCPPacketQueue(AF_INET, config))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
queue_enabled = IfaceMgr::instance().configureDHCPPacketQueue
(2, config); } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4866; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4866
; } } else gtest_label_testnothrow_4866 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4866, ("Expected: " "queue_enabled = IfaceMgr::instance().configureDHCPPacketQueue(2, config)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4867 ASSERT_TRUE(queue_enabled)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(queue_enabled)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4867, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "queue_enabled", "false", "true") .c_str()) = ::testing::Message
()
;
4868 IfaceMgr::instance().getPacketQueue4()->enqueuePacket(pkt, si);
4869
4870 // Thread should only start when there is a packet queue.
4871 ASSERT_NO_THROW(IfaceMgr::instance().startDHCPReceiver(AF_INET))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().startDHCPReceiver(2); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4871; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4871; } } else gtest_label_testnothrow_4871
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4871, ("Expected: " "IfaceMgr::instance().startDHCPReceiver(2)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4872 ASSERT_TRUE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(IfaceMgr::instance().
isDHCPReceiverRunning())) ; else return ::testing::internal::
AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4872, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "false", "true"
) .c_str()) = ::testing::Message()
;
4873 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue4()->empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue4()->empty()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4873, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue4()->empty()", "true"
, "false") .c_str()) = ::testing::Message()
;
4874 {
4875 ReceiverCriticalSection rcs;
4876 ASSERT_FALSE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).isDHCPReceiverRunning()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4876, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "true", "false"
) .c_str()) = ::testing::Message()
;
4877 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue4()->empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue4()->empty()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4877, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue4()->empty()", "true"
, "false") .c_str()) = ::testing::Message()
;
4878 {
4879 ReceiverCriticalSection rcs_deep;
4880 ASSERT_FALSE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).isDHCPReceiverRunning()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4880, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "true", "false"
) .c_str()) = ::testing::Message()
;
4881 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue4()->empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue4()->empty()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4881, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue4()->empty()", "true"
, "false") .c_str()) = ::testing::Message()
;
4882 }
4883 ASSERT_FALSE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).isDHCPReceiverRunning()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4883, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "true", "false"
) .c_str()) = ::testing::Message()
;
4884 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue4()->empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue4()->empty()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4884, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue4()->empty()", "true"
, "false") .c_str()) = ::testing::Message()
;
4885 }
4886 ASSERT_TRUE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(IfaceMgr::instance().
isDHCPReceiverRunning())) ; else return ::testing::internal::
AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4886, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "false", "true"
) .c_str()) = ::testing::Message()
;
4887 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue4()->empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue4()->empty()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4887, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue4()->empty()", "true"
, "false") .c_str()) = ::testing::Message()
;
4888}
4889
4890TEST_F(IfaceMgrTest, receiverCS6)static_assert(sizeof("IfaceMgrTest") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("receiverCS6") > 1, "test_name must not be empty"
); class IfaceMgrTest_receiverCS6_Test : public IfaceMgrTest {
public: IfaceMgrTest_receiverCS6_Test() = default; ~IfaceMgrTest_receiverCS6_Test
() override = default; IfaceMgrTest_receiverCS6_Test (const IfaceMgrTest_receiverCS6_Test
&) = delete; IfaceMgrTest_receiverCS6_Test & operator
=( const IfaceMgrTest_receiverCS6_Test &) = delete; IfaceMgrTest_receiverCS6_Test
(IfaceMgrTest_receiverCS6_Test &&) noexcept = delete
; IfaceMgrTest_receiverCS6_Test & operator=( IfaceMgrTest_receiverCS6_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const IfaceMgrTest_receiverCS6_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "IfaceMgrTest"
, "receiverCS6", nullptr, nullptr, ::testing::internal::CodeLocation
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4890), (
::testing::internal::GetTypeId<IfaceMgrTest>()), ::testing
::internal::SuiteApiResolver< IfaceMgrTest>::GetSetUpCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4890), ::
testing::internal::SuiteApiResolver< IfaceMgrTest>::GetTearDownCaseOrSuite
("../../../src/lib/dhcp/tests/iface_mgr_unittest.cc", 4890), new
::testing::internal::TestFactoryImpl<IfaceMgrTest_receiverCS6_Test
>); void IfaceMgrTest_receiverCS6_Test::TestBody()
{
4891 IfaceMgr::instance().setFamily(AF_INET610);
4892 const isc::asiolink::IOAddress addr("::");
4893 const uint16_t port = 0;
4894 Pkt6Ptr pkt;
4895 SocketInfo si(addr, port, 0);
4896 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue6())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue6()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4896, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue6()", "true", "false") .
c_str()) = ::testing::Message()
;
4897 ASSERT_FALSE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).isDHCPReceiverRunning()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4897, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "true", "false"
) .c_str()) = ::testing::Message()
;
4898 {
4899 ReceiverCriticalSection rcs;
4900 ASSERT_FALSE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).isDHCPReceiverRunning()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4900, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "true", "false"
) .c_str()) = ::testing::Message()
;
4901 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue6())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue6()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4901, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue6()", "true", "false") .
c_str()) = ::testing::Message()
;
4902 {
4903 ReceiverCriticalSection rcs_deep;
4904 ASSERT_FALSE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).isDHCPReceiverRunning()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4904, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "true", "false"
) .c_str()) = ::testing::Message()
;
4905 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue6())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue6()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4905, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue6()", "true", "false") .
c_str()) = ::testing::Message()
;
4906 }
4907 ASSERT_FALSE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).isDHCPReceiverRunning()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4907, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "true", "false"
) .c_str()) = ::testing::Message()
;
4908 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue6())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue6()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4908, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue6()", "true", "false") .
c_str()) = ::testing::Message()
;
4909 }
4910 ASSERT_FALSE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).isDHCPReceiverRunning()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4910, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "true", "false"
) .c_str()) = ::testing::Message()
;
4911 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue6())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue6()))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4911, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue6()", "true", "false") .
c_str()) = ::testing::Message()
;
4912 bool queue_enabled = false;
4913 data::ConstElementPtr config = makeQueueConfig(PacketQueueMgr6::DEFAULT_QUEUE_TYPE6, 500);
4914 ASSERT_NO_THROW(queue_enabled = IfaceMgr::instance().configureDHCPPacketQueue(AF_INET6, config))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
queue_enabled = IfaceMgr::instance().configureDHCPPacketQueue
(10, config); } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_4914; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4914
; } } else gtest_label_testnothrow_4914 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4914, ("Expected: " "queue_enabled = IfaceMgr::instance().configureDHCPPacketQueue(10, config)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4915 ASSERT_TRUE(queue_enabled)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(queue_enabled)) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4915, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "queue_enabled", "false", "true") .c_str()) = ::testing::Message
()
;
4916 IfaceMgr::instance().getPacketQueue6()->enqueuePacket(pkt, si);
4917
4918 // Thread should only start when there is a packet queue.
4919 ASSERT_NO_THROW(IfaceMgr::instance().startDHCPReceiver(AF_INET6))switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
IfaceMgr::instance().startDHCPReceiver(10); } else static_assert
(true, ""); } catch (std::exception const& e) { gtest_msg
.value = "it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testnothrow_4919; } catch (...) { gtest_msg.value
= "it throws."; goto gtest_label_testnothrow_4919; } } else gtest_label_testnothrow_4919
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4919, ("Expected: " "IfaceMgr::instance().startDHCPReceiver(10)"
" doesn't throw an exception.\n" " Actual: " + gtest_msg.value
) .c_str()) = ::testing::Message()
;
4920 ASSERT_TRUE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(IfaceMgr::instance().
isDHCPReceiverRunning())) ; else return ::testing::internal::
AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4920, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "false", "true"
) .c_str()) = ::testing::Message()
;
4921 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue6()->empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue6()->empty()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4921, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue6()->empty()", "true"
, "false") .c_str()) = ::testing::Message()
;
4922 {
4923 ReceiverCriticalSection rcs;
4924 ASSERT_FALSE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).isDHCPReceiverRunning()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4924, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "true", "false"
) .c_str()) = ::testing::Message()
;
4925 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue6()->empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue6()->empty()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4925, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue6()->empty()", "true"
, "false") .c_str()) = ::testing::Message()
;
4926 {
4927 ReceiverCriticalSection rcs_deep;
4928 ASSERT_FALSE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).isDHCPReceiverRunning()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4928, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "true", "false"
) .c_str()) = ::testing::Message()
;
4929 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue6()->empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue6()->empty()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4929, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue6()->empty()", "true"
, "false") .c_str()) = ::testing::Message()
;
4930 }
4931 ASSERT_FALSE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).isDHCPReceiverRunning()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4931, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "true", "false"
) .c_str()) = ::testing::Message()
;
4932 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue6()->empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue6()->empty()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4932, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue6()->empty()", "true"
, "false") .c_str()) = ::testing::Message()
;
4933 }
4934 ASSERT_TRUE(IfaceMgr::instance().isDHCPReceiverRunning())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(IfaceMgr::instance().
isDHCPReceiverRunning())) ; else return ::testing::internal::
AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4934, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().isDHCPReceiverRunning()", "false", "true"
) .c_str()) = ::testing::Message()
;
4935 ASSERT_FALSE(IfaceMgr::instance().getPacketQueue6()->empty())switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(IfaceMgr::instance(
).getPacketQueue6()->empty()))) ; else return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/lib/dhcp/tests/iface_mgr_unittest.cc"
, 4935, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "IfaceMgr::instance().getPacketQueue6()->empty()", "true"
, "false") .c_str()) = ::testing::Message()
;
4936}
4937
4938}

/usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16/bits/basic_string.h

1// Components for manipulating sequences of characters -*- C++ -*-
2
3// Copyright (C) 1997-2026 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 3, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
24
25/** @file bits/basic_string.h
26 * This is an internal header file, included by other library headers.
27 * Do not attempt to use it directly. @headername{string}
28 */
29
30//
31// ISO C++ 14882: 21 Strings library
32//
33
34#ifndef _BASIC_STRING_H1
35#define _BASIC_STRING_H1 1
36
37#ifdef _GLIBCXX_SYSHDR
38#pragma GCC system_header
39#endif
40
41#include <ext/alloc_traits.h>
42#include <debug/debug.h>
43
44#if __cplusplus201703L >= 201103L
45#include <initializer_list>
46#endif
47
48#include <bits/version.h>
49
50#ifdef __glibcxx_string_view201803L // >= C++17
51# include <string_view>
52#endif
53
54#if __glibcxx_containers_ranges // C++ >= 23
55# include <bits/ranges_algobase.h> // ranges::copy
56# include <bits/ranges_util.h> // ranges::subrange
57#endif
58
59#if __glibcxx_to_string >= 202306L // C++ >= 26
60# include <charconv>
61#endif
62
63#if ! _GLIBCXX_USE_CXX11_ABI1
64# include "cow_string.h"
65#else
66
67namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default")))
68{
69_GLIBCXX_BEGIN_NAMESPACE_VERSION
70_GLIBCXX_BEGIN_NAMESPACE_CXX11namespace __cxx11 {
71
72 /**
73 * @class basic_string basic_string.h <string>
74 * @brief Managing sequences of characters and character-like objects.
75 *
76 * @ingroup strings
77 * @ingroup sequences
78 * @headerfile string
79 * @since C++98
80 *
81 * @tparam _CharT Type of character
82 * @tparam _Traits Traits for character type, defaults to
83 * char_traits<_CharT>.
84 * @tparam _Alloc Allocator type, defaults to allocator<_CharT>.
85 *
86 * Meets the requirements of a <a href="tables.html#65">container</a>, a
87 * <a href="tables.html#66">reversible container</a>, and a
88 * <a href="tables.html#67">sequence</a>. Of the
89 * <a href="tables.html#68">optional sequence requirements</a>, only
90 * @c push_back, @c at, and @c %array access are supported.
91 */
92 template<typename _CharT, typename _Traits, typename _Alloc>
93 class basic_string
94 {
95#if __cplusplus201703L >= 202002L
96 static_assert(is_trivially_copyable_v<_CharT>
97 && is_trivially_default_constructible_v<_CharT>
98 && is_standard_layout_v<_CharT>);
99 static_assert(is_same_v<_CharT, typename _Traits::char_type>);
100 static_assert(is_same_v<_CharT, typename _Alloc::value_type>);
101 using _Char_alloc_type = _Alloc;
102#else
103 typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template
104 rebind<_CharT>::other _Char_alloc_type;
105#endif
106
107 typedef __gnu_cxx::__alloc_traits<_Char_alloc_type> _Alloc_traits;
108
109 // Types:
110 public:
111 typedef _Traits traits_type;
112 typedef typename _Traits::char_type value_type;
113 typedef _Char_alloc_type allocator_type;
114 typedef typename _Alloc_traits::size_type size_type;
115 typedef typename _Alloc_traits::difference_type difference_type;
116 typedef typename _Alloc_traits::reference reference;
117 typedef typename _Alloc_traits::const_reference const_reference;
118 typedef typename _Alloc_traits::pointer pointer;
119 typedef typename _Alloc_traits::const_pointer const_pointer;
120 typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator;
121 typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string>
122 const_iterator;
123 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
124 typedef std::reverse_iterator<iterator> reverse_iterator;
125
126 /// Value returned by various member functions when they fail.
127 static const size_type npos = static_cast<size_type>(-1);
128
129 protected:
130 // type used for positions in insert, erase etc.
131#if __cplusplus201703L < 201103L
132 typedef iterator __const_iterator;
133#else
134 typedef const_iterator __const_iterator;
135#endif
136
137 private:
138 static _GLIBCXX20_CONSTEXPR pointer
139 _S_allocate(_Char_alloc_type& __a, size_type __n)
140 {
141 pointer __p = _Alloc_traits::allocate(__a, __n);
142#if __glibcxx_constexpr_string201611L >= 201907L
143 // std::char_traits begins the lifetime of characters,
144 // but custom traits might not, so do it here.
145 if constexpr (!is_same_v<_Traits, char_traits<_CharT>>)
146 if (std::__is_constant_evaluated())
147 // Begin the lifetime of characters in allocated storage.
148 for (size_type __i = 0; __i < __n; ++__i)
149 std::construct_at(__builtin_addressof(__p[__i]));
150#endif
151 return __p;
152 }
153
154#ifdef __glibcxx_string_view201803L // >= C++17
155 // A helper type for avoiding boiler-plate.
156 typedef basic_string_view<_CharT, _Traits> __sv_type;
157
158 template<typename _Tp, typename _Res>
159 using _If_sv = enable_if_t<
160 __and_<is_convertible<const _Tp&, __sv_type>,
161 __not_<is_convertible<const _Tp*, const basic_string*>>,
162 __not_<is_convertible<const _Tp&, const _CharT*>>>::value,
163 _Res>;
164
165 // Allows an implicit conversion to __sv_type.
166 _GLIBCXX20_CONSTEXPR
167 static __sv_type
168 _S_to_string_view(__sv_type __svt) noexcept
169 { return __svt; }
170
171 // Wraps a string_view by explicit conversion and thus
172 // allows to add an internal constructor that does not
173 // participate in overload resolution when a string_view
174 // is provided.
175 struct __sv_wrapper
176 {
177 _GLIBCXX20_CONSTEXPR explicit
178 __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { }
179
180 __sv_type _M_sv;
181 };
182
183 /**
184 * @brief Only internally used: Construct string from a string view
185 * wrapper.
186 * @param __svw string view wrapper.
187 * @param __a Allocator to use.
188 */
189 _GLIBCXX20_CONSTEXPR
190 explicit
191 basic_string(__sv_wrapper __svw, const _Alloc& __a)
192 : basic_string(__svw._M_sv.data(), __svw._M_sv.size(), __a) { }
193#endif
194
195 // Use empty-base optimization: http://www.cantrip.org/emptyopt.html
196 struct _Alloc_hider : allocator_type // TODO check __is_final
197 {
198#if __cplusplus201703L < 201103L
199 _Alloc_hider(pointer __dat, const _Alloc& __a = _Alloc())
200 : allocator_type(__a), _M_p(__dat) { }
201#else
202 _GLIBCXX20_CONSTEXPR
203 _Alloc_hider(pointer __dat, const _Alloc& __a)
204 : allocator_type(__a), _M_p(__dat) { }
205
206 _GLIBCXX20_CONSTEXPR
207 _Alloc_hider(pointer __dat, _Alloc&& __a = _Alloc())
208 : allocator_type(std::move(__a)), _M_p(__dat) { }
209#endif
210
211 pointer _M_p; // The actual data.
212 };
213
214 _Alloc_hider _M_dataplus;
215 size_type _M_string_length;
216
217 enum { _S_local_capacity = 15 / sizeof(_CharT) };
218
219 union
220 {
221 _CharT _M_local_buf[_S_local_capacity + 1];
222 size_type _M_allocated_capacity;
223 };
224
225 _GLIBCXX20_CONSTEXPR
226 void
227 _M_data(pointer __p)
228 { _M_dataplus._M_p = __p; }
229
230 _GLIBCXX20_CONSTEXPR
231 void
232 _M_length(size_type __length)
233 { _M_string_length = __length; }
234
235 _GLIBCXX20_CONSTEXPR
236 pointer
237 _M_data() const
238 { return _M_dataplus._M_p; }
239
240 _GLIBCXX20_CONSTEXPR
241 pointer
242 _M_local_data()
243 {
244#if __cplusplus201703L >= 201103L
245 return std::pointer_traits<pointer>::pointer_to(*_M_local_buf);
246#else
247 return pointer(_M_local_buf);
248#endif
249 }
250
251 _GLIBCXX20_CONSTEXPR
252 const_pointer
253 _M_local_data() const
254 {
255#if __cplusplus201703L >= 201103L
256 return std::pointer_traits<const_pointer>::pointer_to(*_M_local_buf);
257#else
258 return const_pointer(_M_local_buf);
259#endif
260 }
261
262 _GLIBCXX20_CONSTEXPR
263 void
264 _M_capacity(size_type __capacity)
265 { _M_allocated_capacity = __capacity; }
266
267 _GLIBCXX20_CONSTEXPR
268 void
269 _M_set_length(size_type __n)
270 {
271 traits_type::assign(_M_data()[__n], _CharT());
272 _M_length(__n);
273 }
274
275 _GLIBCXX20_CONSTEXPR
276 bool
277 _M_is_local() const
278 {
279 if (_M_data() == _M_local_data())
280 {
281 if (_M_string_length > _S_local_capacity)
282 __builtin_unreachable();
283 return true;
284 }
285 return false;
286 }
287
288 // Create & Destroy
289 _GLIBCXX20_CONSTEXPR
290 pointer
291 _M_create(size_type&, size_type);
292
293 _GLIBCXX20_CONSTEXPR
294 void
295 _M_dispose()
296 {
297 if (!_M_is_local())
298 _M_destroy(_M_allocated_capacity);
299 }
300
301 _GLIBCXX20_CONSTEXPR
302 void
303 _M_destroy(size_type __size) throw()
304 { _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size + 1); }
305
306#if __cplusplus201703L < 201103L || defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
307 // _M_construct_aux is used to implement the 21.3.1 para 15 which
308 // requires special behaviour if _InIterator is an integral type
309 template<typename _InIterator>
310 void
311 _M_construct_aux(_InIterator __beg, _InIterator __end,
312 std::__false_type)
313 {
314 typedef typename iterator_traits<_InIterator>::iterator_category _Tag;
315 _M_construct(__beg, __end, _Tag());
316 }
317
318 // _GLIBCXX_RESOLVE_LIB_DEFECTS
319 // 438. Ambiguity in the "do the right thing" clause
320 template<typename _Integer>
321 void
322 _M_construct_aux(_Integer __beg, _Integer __end, std::__true_type)
323 { _M_construct_aux_2(static_cast<size_type>(__beg), __end); }
324
325 void
326 _M_construct_aux_2(size_type __req, _CharT __c)
327 { _M_construct(__req, __c); }
328#endif
329
330 // For Input Iterators, used in istreambuf_iterators, etc.
331 template<typename _InIterator>
332 _GLIBCXX20_CONSTEXPR
333 void
334 _M_construct(_InIterator __beg, _InIterator __end,
335 std::input_iterator_tag);
336
337 // For forward_iterators up to random_access_iterators, used for
338 // string::iterator, _CharT*, etc.
339 template<typename _FwdIterator>
340 _GLIBCXX20_CONSTEXPR
341 void
342 _M_construct(_FwdIterator __beg, _FwdIterator __end,
343 std::forward_iterator_tag);
344
345 _GLIBCXX20_CONSTEXPR
346 void
347 _M_construct(size_type __req, _CharT __c);
348
349 // Construct using block of memory of known size.
350 // If _Terminated is true assume that source is already 0 terminated.
351 template<bool _Terminated>
352 _GLIBCXX20_CONSTEXPR
353 void
354 _M_construct(const _CharT *__c, size_type __n);
355
356#if __cplusplus201703L >= 202302L
357 constexpr void
358 _M_construct(basic_string&& __str, size_type __pos, size_type __n);
359#endif
360
361 _GLIBCXX20_CONSTEXPR
362 allocator_type&
363 _M_get_allocator()
364 { return _M_dataplus; }
365
366 _GLIBCXX20_CONSTEXPR
367 const allocator_type&
368 _M_get_allocator() const
369 { return _M_dataplus; }
370
371 // Ensure that _M_local_buf is the active member of the union.
372 __attribute__((__always_inline__))
373 _GLIBCXX14_CONSTEXPRconstexpr
374 void
375 _M_init_local_buf() _GLIBCXX_NOEXCEPTnoexcept
376 {
377#if __glibcxx_is_constant_evaluated
378 if (std::is_constant_evaluated())
379 for (size_type __i = 0; __i <= _S_local_capacity; ++__i)
380 _M_local_buf[__i] = _CharT();
381#endif
382 }
383
384 __attribute__((__always_inline__))
385 _GLIBCXX14_CONSTEXPRconstexpr
386 pointer
387 _M_use_local_data() _GLIBCXX_NOEXCEPTnoexcept
388 {
389#if __cpp_lib_is_constant_evaluated
390 _M_init_local_buf();
391#endif
392 return _M_local_data();
393 }
394
395 private:
396
397#ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
398 // The explicit instantiations in misc-inst.cc require this due to
399 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64063
400 template<typename _Tp, bool _Requires =
401 !__are_same<_Tp, _CharT*>::__value
402 && !__are_same<_Tp, const _CharT*>::__value
403 && !__are_same<_Tp, iterator>::__value
404 && !__are_same<_Tp, const_iterator>::__value>
405 struct __enable_if_not_native_iterator
406 { typedef basic_string& __type; };
407 template<typename _Tp>
408 struct __enable_if_not_native_iterator<_Tp, false> { };
409#endif
410
411 _GLIBCXX20_CONSTEXPR
412 size_type
413 _M_check(size_type __pos, const char* __s) const
414 {
415 if (__pos > this->size())
416 __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "("%s: __pos (which is %zu) > " "this->size() (which is %zu)"
)
417 "this->size() (which is %zu)")("%s: __pos (which is %zu) > " "this->size() (which is %zu)"
)
,
418 __s, (size_t)__pos, (size_t)this->size());
419 return __pos;
420 }
421
422 _GLIBCXX20_CONSTEXPR
423 void
424 _M_check_length(size_type __n1, size_type __n2, const char* __s) const
425 {
426 if (this->max_size() - (this->size() - __n1) < __n2)
427 __throw_length_error(__N(__s)(__s));
428 }
429
430
431 // NB: _M_limit doesn't check for a bad __pos value.
432 _GLIBCXX20_CONSTEXPR
433 size_type
434 _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPTnoexcept
435 {
436 const bool __testoff = __off < this->size() - __pos;
437 return __testoff ? __off : this->size() - __pos;
438 }
439
440 // True if _Rep and source do not overlap.
441 bool
442 _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPTnoexcept
443 {
444 return (less<const _CharT*>()(__s, _M_data())
445 || less<const _CharT*>()(_M_data() + this->size(), __s));
446 }
447
448 // When __n = 1 way faster than the general multichar
449 // traits_type::copy/move/assign.
450 _GLIBCXX20_CONSTEXPR
451 static void
452 _S_copy(_CharT* __d, const _CharT* __s, size_type __n)
453 {
454 if (__n == 1)
455 traits_type::assign(*__d, *__s);
456 else
457 traits_type::copy(__d, __s, __n);
458 }
459
460 _GLIBCXX20_CONSTEXPR
461 static void
462 _S_move(_CharT* __d, const _CharT* __s, size_type __n)
463 {
464 if (__n == 1)
465 traits_type::assign(*__d, *__s);
466 else
467 traits_type::move(__d, __s, __n);
468 }
469
470 _GLIBCXX20_CONSTEXPR
471 static void
472 _S_assign(_CharT* __d, size_type __n, _CharT __c)
473 {
474 if (__n == 1)
475 traits_type::assign(*__d, __c);
476 else
477 traits_type::assign(__d, __n, __c);
478 }
479
480#pragma GCC diagnostic push
481#pragma GCC diagnostic ignored "-Wc++17-extensions"
482 // _S_copy_chars is a separate template to permit specialization
483 // to optimize for the common case of pointers as iterators.
484 template<class _Iterator>
485 _GLIBCXX20_CONSTEXPR
486 static void
487 _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
488 {
489#if __cplusplus201703L >= 201103L
490 using _IterBase = decltype(std::__niter_base(__k1));
491 if constexpr (__or_<is_same<_IterBase, _CharT*>,
492 is_same<_IterBase, const _CharT*>>::value)
493 _S_copy(__p, std::__niter_base(__k1), __k2 - __k1);
494#if __cpp_lib_concepts
495 else if constexpr (requires {
496 requires contiguous_iterator<_Iterator>;
497 { std::to_address(__k1) }
498 -> convertible_to<const _CharT*>;
499 })
500 {
501 const auto __d = __k2 - __k1;
502 (void) (__k1 + __d); // See P3349R1
503 _S_copy(__p, std::to_address(__k1), static_cast<size_type>(__d));
504 }
505#endif
506 else
507#endif
508 for (; __k1 != __k2; ++__k1, (void)++__p)
509 traits_type::assign(*__p, static_cast<_CharT>(*__k1));
510 }
511#pragma GCC diagnostic pop
512
513#if __cplusplus201703L < 201103L || defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
514 static void
515 _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2)
516 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
517
518 static void
519 _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
520 { _S_copy_chars(__p, __k1.base(), __k2.base()); }
521
522 static void
523 _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2)
524 { _S_copy(__p, __k1, __k2 - __k1); }
525
526 static void
527 _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
528 { _S_copy(__p, __k1, __k2 - __k1); }
529#endif
530
531#if __glibcxx_containers_ranges // C++ >= 23
532 // pre: __n == ranges::distance(__rg). __p+[0,__n) is a valid range.
533 template<typename _Rg>
534 static constexpr void
535 _S_copy_range(pointer __p, _Rg&& __rg, size_type __n)
536 {
537 if constexpr (requires {
538 requires ranges::contiguous_range<_Rg>;
539 { ranges::data(std::forward<_Rg>(__rg)) }
540 -> convertible_to<const _CharT*>;
541 })
542 _S_copy(__p, ranges::data(std::forward<_Rg>(__rg)), __n);
543 else
544 {
545 auto __first = ranges::begin(__rg);
546 const auto __last = ranges::end(__rg);
547 for (; __first != __last; ++__first)
548 traits_type::assign(*__p++, static_cast<_CharT>(*__first));
549 }
550 }
551#endif
552
553 _GLIBCXX20_CONSTEXPR
554 static int
555 _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPTnoexcept
556 {
557 const difference_type __d = difference_type(__n1 - __n2);
558
559 if (__d > __gnu_cxx::__numeric_traits<int>::__max)
560 return __gnu_cxx::__numeric_traits<int>::__max;
561 else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
562 return __gnu_cxx::__numeric_traits<int>::__min;
563 else
564 return int(__d);
565 }
566
567 _GLIBCXX20_CONSTEXPR
568 void
569 _M_assign(const basic_string&);
570
571 _GLIBCXX20_CONSTEXPR
572 void
573 _M_mutate(size_type __pos, size_type __len1, const _CharT* __s,
574 size_type __len2);
575
576 _GLIBCXX20_CONSTEXPR
577 void
578 _M_erase(size_type __pos, size_type __n);
579
580 public:
581 // Construct/copy/destroy:
582 // NB: We overload ctors in some cases instead of using default
583 // arguments, per 17.4.4.4 para. 2 item 2.
584
585 /**
586 * @brief Default constructor creates an empty string.
587 */
588 _GLIBCXX20_CONSTEXPR
589 basic_string()
590 _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible<_Alloc>::value)noexcept(is_nothrow_default_constructible<_Alloc>::value
)
591#if __cpp_concepts && __glibcxx_type_trait_variable_templates201510L
592 requires is_default_constructible_v<_Alloc>
593#endif
594 : _M_dataplus(_M_local_data())
595 {
596 _M_init_local_buf();
597 _M_set_length(0);
598 }
599
600 /**
601 * @brief Construct an empty string using allocator @a a.
602 */
603 _GLIBCXX20_CONSTEXPR
604 explicit
605 basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPTnoexcept
606 : _M_dataplus(_M_local_data(), __a)
607 {
608 _M_init_local_buf();
609 _M_set_length(0);
610 }
611
612 /**
613 * @brief Construct string with copy of value of @a __str.
614 * @param __str Source string.
615 */
616 _GLIBCXX20_CONSTEXPR
617 basic_string(const basic_string& __str)
618 : _M_dataplus(_M_local_data(),
619 _Alloc_traits::_S_select_on_copy(__str._M_get_allocator()))
620 {
621 _M_construct<true>(__str._M_data(), __str.length());
622 }
623
624 // _GLIBCXX_RESOLVE_LIB_DEFECTS
625 // 2583. no way to supply an allocator for basic_string(str, pos)
626 /**
627 * @brief Construct string as copy of a substring.
628 * @param __str Source string.
629 * @param __pos Index of first character to copy from.
630 * @param __a Allocator to use.
631 */
632 _GLIBCXX20_CONSTEXPR
633 basic_string(const basic_string& __str, size_type __pos,
634 const _Alloc& __a = _Alloc())
635 : _M_dataplus(_M_local_data(), __a)
636 {
637 const _CharT* __start = __str._M_data()
638 + __str._M_check(__pos, "basic_string::basic_string");
639 _M_construct(__start, __start + __str._M_limit(__pos, npos),
640 std::forward_iterator_tag());
641 }
642
643 /**
644 * @brief Construct string as copy of a substring.
645 * @param __str Source string.
646 * @param __pos Index of first character to copy from.
647 * @param __n Number of characters to copy.
648 */
649 _GLIBCXX20_CONSTEXPR
650 basic_string(const basic_string& __str, size_type __pos,
651 size_type __n)
652 : _M_dataplus(_M_local_data())
653 {
654 const _CharT* __start = __str._M_data()
655 + __str._M_check(__pos, "basic_string::basic_string");
656 _M_construct(__start, __start + __str._M_limit(__pos, __n),
657 std::forward_iterator_tag());
658 }
659
660 /**
661 * @brief Construct string as copy of a substring.
662 * @param __str Source string.
663 * @param __pos Index of first character to copy from.
664 * @param __n Number of characters to copy.
665 * @param __a Allocator to use.
666 */
667 _GLIBCXX20_CONSTEXPR
668 basic_string(const basic_string& __str, size_type __pos,
669 size_type __n, const _Alloc& __a)
670 : _M_dataplus(_M_local_data(), __a)
671 {
672 const _CharT* __start
673 = __str._M_data() + __str._M_check(__pos, "string::string");
674 _M_construct(__start, __start + __str._M_limit(__pos, __n),
675 std::forward_iterator_tag());
676 }
677
678#if __cplusplus201703L >= 202302L
679 _GLIBCXX20_CONSTEXPR
680 basic_string(basic_string&& __str, size_type __pos,
681 const _Alloc& __a = _Alloc())
682 : _M_dataplus(_M_local_data(), __a)
683 {
684 __pos = __str._M_check(__pos, "string::string");
685 _M_construct(std::move(__str), __pos, __str.length() - __pos);
686 }
687
688 _GLIBCXX20_CONSTEXPR
689 basic_string(basic_string&& __str, size_type __pos, size_type __n,
690 const _Alloc& __a = _Alloc())
691 : _M_dataplus(_M_local_data(), __a)
692 {
693 __pos = __str._M_check(__pos, "string::string");
694 _M_construct(std::move(__str), __pos, __str._M_limit(__pos, __n));
695 }
696#endif // C++23
697
698 /**
699 * @brief Construct string initialized by a character %array.
700 * @param __s Source character %array.
701 * @param __n Number of characters to copy.
702 * @param __a Allocator to use (default is default allocator).
703 *
704 * NB: @a __s must have at least @a __n characters, &apos;\\0&apos;
705 * has no special meaning.
706 */
707 _GLIBCXX20_CONSTEXPR
708 basic_string(const _CharT* __s, size_type __n,
709 const _Alloc& __a = _Alloc())
710 : _M_dataplus(_M_local_data(), __a)
711 {
712 // NB: Not required, but considered best practice.
713 if (__s == 0 && __n > 0)
714 std::__throw_logic_error(__N("basic_string: "("basic_string: " "construction from null is not valid")
715 "construction from null is not valid")("basic_string: " "construction from null is not valid"));
716 _M_construct(__s, __s + __n, std::forward_iterator_tag());
717 }
718
719 /**
720 * @brief Construct string as copy of a C string.
721 * @param __s Source C string.
722 * @param __a Allocator to use (default is default allocator).
723 */
724#if __cpp_deduction_guides201703L && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
725 // _GLIBCXX_RESOLVE_LIB_DEFECTS
726 // 3076. basic_string CTAD ambiguity
727 template<typename = _RequireAllocator<_Alloc>>
728#endif
729 _GLIBCXX20_CONSTEXPR
730 basic_string(const _CharT* __s, const _Alloc& __a = _Alloc())
731 : _M_dataplus(_M_local_data(), __a)
732 {
733 // NB: Not required, but considered best practice.
734 if (__s == 0)
735 std::__throw_logic_error(__N("basic_string: "("basic_string: " "construction from null is not valid")
736 "construction from null is not valid")("basic_string: " "construction from null is not valid"));
737 const _CharT* __end = __s + traits_type::length(__s);
738 _M_construct(__s, __end, forward_iterator_tag());
739 }
740
741 /**
742 * @brief Construct string as multiple characters.
743 * @param __n Number of characters.
744 * @param __c Character to use.
745 * @param __a Allocator to use (default is default allocator).
746 */
747#if __cpp_deduction_guides201703L && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
748 // _GLIBCXX_RESOLVE_LIB_DEFECTS
749 // 3076. basic_string CTAD ambiguity
750 template<typename = _RequireAllocator<_Alloc>>
751#endif
752 _GLIBCXX20_CONSTEXPR
753 basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
754 : _M_dataplus(_M_local_data(), __a)
755 { _M_construct(__n, __c); }
756
757#if __cplusplus201703L >= 201103L
758 /**
759 * @brief Move construct string.
760 * @param __str Source string.
761 *
762 * The newly-created string contains the exact contents of @a __str.
763 * @a __str is a valid, but unspecified string.
764 */
765 _GLIBCXX20_CONSTEXPR
766 basic_string(basic_string&& __str) noexcept
767 : _M_dataplus(_M_local_data(), std::move(__str._M_get_allocator()))
768 {
769 if (__str._M_is_local())
770 {
771 _M_init_local_buf();
772 traits_type::copy(_M_local_buf, __str._M_local_buf,
773 __str.length() + 1);
774 }
775 else
776 {
777 _M_data(__str._M_data());
778 _M_capacity(__str._M_allocated_capacity);
779 }
780
781 // Must use _M_length() here not _M_set_length() because
782 // basic_stringbuf relies on writing into unallocated capacity so
783 // we mess up the contents if we put a '\0' in the string.
784 _M_length(__str.length());
785 __str._M_data(__str._M_use_local_data());
786 __str._M_set_length(0);
787 }
788
789#if __glibcxx_containers_ranges // C++ >= 23
790 /**
791 * @brief Construct a string from a range.
792 * @since C++23
793 */
794 template<__detail::__container_compatible_range<_CharT> _Rg>
795 constexpr
796 basic_string(from_range_t, _Rg&& __rg, const _Alloc& __a = _Alloc())
797 : basic_string(__a)
798 {
799 if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>)
800 {
801 const auto __n = static_cast<size_type>(ranges::distance(__rg));
802 reserve(__n);
803 _S_copy_range(_M_data(), std::forward<_Rg>(__rg), __n);
804 _M_set_length(__n);
805 }
806 else
807 {
808 auto __first = ranges::begin(__rg);
809 const auto __last = ranges::end(__rg);
810 for (; __first != __last; ++__first)
811 push_back(*__first);
812 }
813 }
814#endif
815
816 /**
817 * @brief Construct string from an initializer %list.
818 * @param __l std::initializer_list of characters.
819 * @param __a Allocator to use (default is default allocator).
820 */
821 _GLIBCXX20_CONSTEXPR
822 basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
823 : _M_dataplus(_M_local_data(), __a)
824 { _M_construct(__l.begin(), __l.end(), std::forward_iterator_tag()); }
825
826 _GLIBCXX20_CONSTEXPR
827 basic_string(const basic_string& __str, const _Alloc& __a)
828 : _M_dataplus(_M_local_data(), __a)
829 { _M_construct(__str.begin(), __str.end(), std::forward_iterator_tag()); }
830
831 _GLIBCXX20_CONSTEXPR
832 basic_string(basic_string&& __str, const _Alloc& __a)
833 noexcept(_Alloc_traits::_S_always_equal())
834 : _M_dataplus(_M_local_data(), __a)
835 {
836 if (__str._M_is_local())
837 {
838 _M_init_local_buf();
839 traits_type::copy(_M_local_buf, __str._M_local_buf,
840 __str.length() + 1);
841 _M_length(__str.length());
842 __str._M_set_length(0);
843 }
844 else if (_Alloc_traits::_S_always_equal()
845 || __str.get_allocator() == __a)
846 {
847 _M_data(__str._M_data());
848 _M_length(__str.length());
849 _M_capacity(__str._M_allocated_capacity);
850 __str._M_data(__str._M_use_local_data());
851 __str._M_set_length(0);
852 }
853 else
854 _M_construct(__str.begin(), __str.end(), std::forward_iterator_tag());
855 }
856#endif // C++11
857
858#if __cplusplus201703L >= 202100L
859 basic_string(nullptr_t) = delete;
860 basic_string& operator=(nullptr_t) = delete;
861#endif // C++23
862
863 /**
864 * @brief Construct string as copy of a range.
865 * @param __beg Start of range.
866 * @param __end End of range.
867 * @param __a Allocator to use (default is default allocator).
868 */
869#if __cplusplus201703L >= 201103L
870 template<typename _InputIterator,
871 typename = std::_RequireInputIter<_InputIterator>>
872#else
873 template<typename _InputIterator>
874#endif
875 _GLIBCXX20_CONSTEXPR
876 basic_string(_InputIterator __beg, _InputIterator __end,
877 const _Alloc& __a = _Alloc())
878 : _M_dataplus(_M_local_data(), __a), _M_string_length(0)
879 {
880#if __cplusplus201703L >= 201103L
881 _M_construct(__beg, __end, std::__iterator_category(__beg));
882#else
883 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
884 _M_construct_aux(__beg, __end, _Integral());
885#endif
886 }
887
888#ifdef __glibcxx_string_view201803L // >= C++17
889 /**
890 * @brief Construct string from a substring of a string_view.
891 * @param __t Source object convertible to string view.
892 * @param __pos The index of the first character to copy from __t.
893 * @param __n The number of characters to copy from __t.
894 * @param __a Allocator to use.
895 */
896 template<typename _Tp,
897 typename = enable_if_t<is_convertible_v<const _Tp&, __sv_type>>>
898 _GLIBCXX20_CONSTEXPR
899 basic_string(const _Tp& __t, size_type __pos, size_type __n,
900 const _Alloc& __a = _Alloc())
901 : basic_string(_S_to_string_view(__t).substr(__pos, __n), __a) { }
902
903 /**
904 * @brief Construct string from a string_view.
905 * @param __t Source object convertible to string view.
906 * @param __a Allocator to use (default is default allocator).
907 */
908 template<typename _Tp, typename = _If_sv<_Tp, void>>
909 _GLIBCXX20_CONSTEXPR
910 explicit
911 basic_string(const _Tp& __t, const _Alloc& __a = _Alloc())
912 : basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
913#endif // C++17
914
915 /**
916 * @brief Destroy the string instance.
917 */
918 _GLIBCXX20_CONSTEXPR
919 ~basic_string()
920 { _M_dispose(); }
921
922 /**
923 * @brief Assign the value of @a str to this string.
924 * @param __str Source string.
925 */
926 _GLIBCXX20_CONSTEXPR
927 basic_string&
928 operator=(const basic_string& __str)
929 {
930 return this->assign(__str);
931 }
932
933 /**
934 * @brief Copy contents of @a s into this string.
935 * @param __s Source null-terminated string.
936 */
937 _GLIBCXX20_CONSTEXPR
938 basic_string&
939 operator=(const _CharT* __s)
940 { return this->assign(__s); }
941
942 /**
943 * @brief Set value to string of length 1.
944 * @param __c Source character.
945 *
946 * Assigning to a character makes this string length 1 and
947 * (*this)[0] == @a c.
948 */
949 _GLIBCXX20_CONSTEXPR
950 basic_string&
951 operator=(_CharT __c)
952 {
953 this->assign(1, __c);
954 return *this;
955 }
956
957#if __cplusplus201703L >= 201103L
958 /**
959 * @brief Move assign the value of @a str to this string.
960 * @param __str Source string.
961 *
962 * The contents of @a str are moved into this string (without copying).
963 * @a str is a valid, but unspecified string.
964 */
965 // _GLIBCXX_RESOLVE_LIB_DEFECTS
966 // 2063. Contradictory requirements for string move assignment
967 _GLIBCXX20_CONSTEXPR
968 basic_string&
969 operator=(basic_string&& __str)
970 noexcept(_Alloc_traits::_S_nothrow_move())
971 {
972 const bool __equal_allocs = _Alloc_traits::_S_always_equal()
973 || _M_get_allocator() == __str._M_get_allocator();
974 if (!_M_is_local() && _Alloc_traits::_S_propagate_on_move_assign()
975 && !__equal_allocs)
976 {
977 // Destroy existing storage before replacing allocator.
978 _M_destroy(_M_allocated_capacity);
979 _M_data(_M_local_data());
980 _M_set_length(0);
981 }
982 // Replace allocator if POCMA is true.
983 std::__alloc_on_move(_M_get_allocator(), __str._M_get_allocator());
984
985 if (__str._M_is_local())
986 {
987 // We've always got room for a short string, just copy it
988 // (unless this is a self-move, because that would violate the
989 // char_traits::copy precondition that the ranges don't overlap).
990 if (__builtin_expect(std::__addressof(__str) != this, true))
991 {
992 if (__str.size())
993 this->_S_copy(_M_data(), __str._M_data(), __str.size());
994 _M_set_length(__str.size());
995 }
996 }
997 else if (_Alloc_traits::_S_propagate_on_move_assign() || __equal_allocs)
998 {
999 // Just move the allocated pointer, our allocator can free it.
1000 pointer __data = nullptr;
1001 size_type __capacity;
1002 if (!_M_is_local())
1003 {
1004 if (__equal_allocs)
1005 {
1006 // __str can reuse our existing storage.
1007 __data = _M_data();
1008 __capacity = _M_allocated_capacity;
1009 }
1010 else // __str can't use it, so free it.
1011 _M_destroy(_M_allocated_capacity);
1012 }
1013
1014 _M_data(__str._M_data());
1015 _M_length(__str.length());
1016 _M_capacity(__str._M_allocated_capacity);
1017 if (__data)
1018 {
1019 __str._M_data(__data);
1020 __str._M_capacity(__capacity);
1021 }
1022 else
1023 __str._M_data(__str._M_use_local_data());
1024 }
1025 else // Need to do a deep copy
1026 _M_assign(__str);
1027 __str.clear();
1028 return *this;
1029 }
1030
1031 /**
1032 * @brief Set value to string constructed from initializer %list.
1033 * @param __l std::initializer_list.
1034 */
1035 _GLIBCXX20_CONSTEXPR
1036 basic_string&
1037 operator=(initializer_list<_CharT> __l)
1038 {
1039 this->assign(__l.begin(), __l.size());
1040 return *this;
1041 }
1042#endif // C++11
1043
1044#ifdef __glibcxx_string_view201803L // >= C++17
1045 /**
1046 * @brief Set value to string constructed from a string_view.
1047 * @param __svt An object convertible to string_view.
1048 */
1049 template<typename _Tp>
1050 _GLIBCXX20_CONSTEXPR
1051 _If_sv<_Tp, basic_string&>
1052 operator=(const _Tp& __svt)
1053 { return this->assign(__svt); }
1054
1055 /**
1056 * @brief Convert to a string_view.
1057 * @return A string_view.
1058 */
1059 _GLIBCXX20_CONSTEXPR
1060 operator __sv_type() const noexcept
1061 { return __sv_type(data(), size()); }
1062#endif // C++17
1063
1064 // Iterators:
1065 /**
1066 * Returns a read/write iterator that points to the first character in
1067 * the %string.
1068 */
1069 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1070 iterator
1071 begin() _GLIBCXX_NOEXCEPTnoexcept
1072 { return iterator(_M_data()); }
1073
1074 /**
1075 * Returns a read-only (constant) iterator that points to the first
1076 * character in the %string.
1077 */
1078 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1079 const_iterator
1080 begin() const _GLIBCXX_NOEXCEPTnoexcept
1081 { return const_iterator(_M_data()); }
1082
1083 /**
1084 * Returns a read/write iterator that points one past the last
1085 * character in the %string.
1086 */
1087 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1088 iterator
1089 end() _GLIBCXX_NOEXCEPTnoexcept
1090 { return iterator(_M_data() + this->size()); }
1091
1092 /**
1093 * Returns a read-only (constant) iterator that points one past the
1094 * last character in the %string.
1095 */
1096 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1097 const_iterator
1098 end() const _GLIBCXX_NOEXCEPTnoexcept
1099 { return const_iterator(_M_data() + this->size()); }
1100
1101 /**
1102 * Returns a read/write reverse iterator that points to the last
1103 * character in the %string. Iteration is done in reverse element
1104 * order.
1105 */
1106 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1107 reverse_iterator
1108 rbegin() _GLIBCXX_NOEXCEPTnoexcept
1109 { return reverse_iterator(this->end()); }
1110
1111 /**
1112 * Returns a read-only (constant) reverse iterator that points
1113 * to the last character in the %string. Iteration is done in
1114 * reverse element order.
1115 */
1116 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1117 const_reverse_iterator
1118 rbegin() const _GLIBCXX_NOEXCEPTnoexcept
1119 { return const_reverse_iterator(this->end()); }
1120
1121 /**
1122 * Returns a read/write reverse iterator that points to one before the
1123 * first character in the %string. Iteration is done in reverse
1124 * element order.
1125 */
1126 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1127 reverse_iterator
1128 rend() _GLIBCXX_NOEXCEPTnoexcept
1129 { return reverse_iterator(this->begin()); }
1130
1131 /**
1132 * Returns a read-only (constant) reverse iterator that points
1133 * to one before the first character in the %string. Iteration
1134 * is done in reverse element order.
1135 */
1136 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1137 const_reverse_iterator
1138 rend() const _GLIBCXX_NOEXCEPTnoexcept
1139 { return const_reverse_iterator(this->begin()); }
1140
1141#if __cplusplus201703L >= 201103L
1142 /**
1143 * Returns a read-only (constant) iterator that points to the first
1144 * character in the %string.
1145 */
1146 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1147 const_iterator
1148 cbegin() const noexcept
1149 { return const_iterator(this->_M_data()); }
1150
1151 /**
1152 * Returns a read-only (constant) iterator that points one past the
1153 * last character in the %string.
1154 */
1155 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1156 const_iterator
1157 cend() const noexcept
1158 { return const_iterator(this->_M_data() + this->size()); }
1159
1160 /**
1161 * Returns a read-only (constant) reverse iterator that points
1162 * to the last character in the %string. Iteration is done in
1163 * reverse element order.
1164 */
1165 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1166 const_reverse_iterator
1167 crbegin() const noexcept
1168 { return const_reverse_iterator(this->end()); }
1169
1170 /**
1171 * Returns a read-only (constant) reverse iterator that points
1172 * to one before the first character in the %string. Iteration
1173 * is done in reverse element order.
1174 */
1175 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1176 const_reverse_iterator
1177 crend() const noexcept
1178 { return const_reverse_iterator(this->begin()); }
1179#endif
1180
1181 public:
1182 // Capacity:
1183 /// Returns the number of characters in the string, not including any
1184 /// null-termination.
1185 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1186 size_type
1187 size() const _GLIBCXX_NOEXCEPTnoexcept
1188 {
1189 size_type __sz = _M_string_length;
1190 if (__sz > max_size ())
1191 __builtin_unreachable();
1192 return __sz;
1193 }
1194
1195 /// Returns the number of characters in the string, not including any
1196 /// null-termination.
1197 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1198 size_type
1199 length() const _GLIBCXX_NOEXCEPTnoexcept
1200 { return size(); }
1201
1202 /// Returns the size() of the largest possible %string.
1203 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1204 size_type
1205 max_size() const _GLIBCXX_NOEXCEPTnoexcept
1206 {
1207 const size_t __diffmax
1208 = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max / sizeof(_CharT);
1209 const size_t __allocmax = _Alloc_traits::max_size(_M_get_allocator());
1210 return (std::min)(__diffmax, __allocmax) - 1;
1211 }
1212
1213 /**
1214 * @brief Resizes the %string to the specified number of characters.
1215 * @param __n Number of characters the %string should contain.
1216 * @param __c Character to fill any new elements.
1217 *
1218 * This function will %resize the %string to the specified
1219 * number of characters. If the number is smaller than the
1220 * %string's current size the %string is truncated, otherwise
1221 * the %string is extended and new elements are %set to @a __c.
1222 */
1223 _GLIBCXX20_CONSTEXPR
1224 void
1225 resize(size_type __n, _CharT __c);
1226
1227 /**
1228 * @brief Resizes the %string to the specified number of characters.
1229 * @param __n Number of characters the %string should contain.
1230 *
1231 * This function will resize the %string to the specified length. If
1232 * the new size is smaller than the %string's current size the %string
1233 * is truncated, otherwise the %string is extended and new characters
1234 * are default-constructed. For basic types such as char, this means
1235 * setting them to 0.
1236 */
1237 _GLIBCXX20_CONSTEXPR
1238 void
1239 resize(size_type __n)
1240 { this->resize(__n, _CharT()); }
1241
1242#if __cplusplus201703L >= 201103L
1243#pragma GCC diagnostic push
1244#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
1245 /// A non-binding request to reduce capacity() to size().
1246 _GLIBCXX20_CONSTEXPR
1247 void
1248 shrink_to_fit() noexcept
1249 { reserve(); }
1250#pragma GCC diagnostic pop
1251#endif
1252
1253#ifdef __glibcxx_string_resize_and_overwrite // C++ >= 23
1254 /** Resize the string and call a function to fill it.
1255 *
1256 * @param __n The maximum size requested.
1257 * @param __op A callable object that writes characters to the string.
1258 *
1259 * This is a low-level function that is easy to misuse, be careful.
1260 *
1261 * Calling `str.resize_and_overwrite(n, op)` will reserve at least `n`
1262 * characters in `str`, evaluate `n2 = std::move(op)(str.data(), n)`,
1263 * and finally set the string length to `n2` (adding a null terminator
1264 * at the end). The function object `op` is allowed to write to the
1265 * extra capacity added by the initial reserve operation, which is not
1266 * allowed if you just call `str.reserve(n)` yourself.
1267 *
1268 * This can be used to efficiently fill a `string` buffer without the
1269 * overhead of zero-initializing characters that will be overwritten
1270 * anyway.
1271 *
1272 * The callable `op` must not access the string directly (only through
1273 * the pointer passed as its first argument), must not write more than
1274 * `n` characters to the string, must return a value no greater than `n`,
1275 * and must ensure that all characters up to the returned length are
1276 * valid after it returns (i.e. there must be no uninitialized values
1277 * left in the string after the call, because accessing them would
1278 * have undefined behaviour). If `op` exits by throwing an exception
1279 * the behaviour is undefined.
1280 *
1281 * @since C++23
1282 */
1283 template<typename _Operation>
1284 constexpr void
1285 resize_and_overwrite(size_type __n, _Operation __op);
1286#endif
1287
1288#if __cplusplus201703L >= 201103L
1289 /// Non-standard version of resize_and_overwrite for C++11 and above.
1290 template<typename _Operation>
1291 _GLIBCXX20_CONSTEXPR void
1292 __resize_and_overwrite(size_type __n, _Operation __op);
1293#endif
1294
1295 /**
1296 * Returns the total number of characters that the %string can hold
1297 * before needing to allocate more memory.
1298 */
1299 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1300 size_type
1301 capacity() const _GLIBCXX_NOEXCEPTnoexcept
1302 {
1303 size_t __sz = _M_is_local() ? size_type(_S_local_capacity)
1304 : _M_allocated_capacity;
1305 if (__sz < _S_local_capacity || __sz > max_size ())
1306 __builtin_unreachable();
1307 return __sz;
1308 }
1309
1310 /**
1311 * @brief Attempt to preallocate enough memory for specified number of
1312 * characters.
1313 * @param __res_arg Number of characters required.
1314 * @throw std::length_error If @a __res_arg exceeds @c max_size().
1315 *
1316 * This function attempts to reserve enough memory for the
1317 * %string to hold the specified number of characters. If the
1318 * number requested is more than max_size(), length_error is
1319 * thrown.
1320 *
1321 * The advantage of this function is that if optimal code is a
1322 * necessity and the user can determine the string length that will be
1323 * required, the user can reserve the memory in %advance, and thus
1324 * prevent a possible reallocation of memory and copying of %string
1325 * data.
1326 */
1327 _GLIBCXX20_CONSTEXPR
1328 void
1329 reserve(size_type __res_arg);
1330
1331 /**
1332 * Equivalent to shrink_to_fit().
1333 */
1334#if __cplusplus201703L >= 202002L
1335 [[deprecated("use shrink_to_fit() instead")]]
1336#endif
1337 _GLIBCXX20_CONSTEXPR
1338 void
1339 reserve();
1340
1341 /**
1342 * Erases the string, making it empty.
1343 */
1344 _GLIBCXX20_CONSTEXPR
1345 void
1346 clear() _GLIBCXX_NOEXCEPTnoexcept
1347 { _M_set_length(0); }
1348
1349 /**
1350 * Returns true if the %string is empty. Equivalent to
1351 * <code>*this == ""</code>.
1352 */
1353 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1354 bool
1355 empty() const _GLIBCXX_NOEXCEPTnoexcept
1356 { return _M_string_length == 0; }
1357
1358 // Element access:
1359 /**
1360 * @brief Subscript access to the data contained in the %string.
1361 * @param __pos The index of the character to access.
1362 * @return Read-only (constant) reference to the character.
1363 *
1364 * This operator allows for easy, array-style, data access.
1365 * Note that data access with this operator is unchecked and
1366 * out_of_range lookups are not defined. (For checked lookups
1367 * see at().)
1368 */
1369 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1370 const_reference
1371 operator[] (size_type __pos) const _GLIBCXX_NOEXCEPTnoexcept
1372 {
1373 __glibcxx_assert(__pos <= size())do { if (__builtin_expect(!bool(__pos <= size()), false)) std
::__glibcxx_assert_fail("/usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16/bits/basic_string.h"
, 1373, __PRETTY_FUNCTION__, "__pos <= size()"); } while (
false)
;
1374 return _M_data()[__pos];
1375 }
1376
1377 /**
1378 * @brief Subscript access to the data contained in the %string.
1379 * @param __pos The index of the character to access.
1380 * @return Read/write reference to the character.
1381 *
1382 * This operator allows for easy, array-style, data access.
1383 * Note that data access with this operator is unchecked and
1384 * out_of_range lookups are not defined. (For checked lookups
1385 * see at().)
1386 */
1387 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1388 reference
1389 operator[](size_type __pos)
1390 {
1391 // Allow pos == size() both in C++98 mode, as v3 extension,
1392 // and in C++11 mode.
1393 __glibcxx_assert(__pos <= size())do { if (__builtin_expect(!bool(__pos <= size()), false)) std
::__glibcxx_assert_fail("/usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16/bits/basic_string.h"
, 1393, __PRETTY_FUNCTION__, "__pos <= size()"); } while (
false)
;
1394 // In pedantic mode be strict in C++98 mode.
1395 _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos < size());
1396 return _M_data()[__pos];
1397 }
1398
1399 /**
1400 * @brief Provides access to the data contained in the %string.
1401 * @param __n The index of the character to access.
1402 * @return Read-only (const) reference to the character.
1403 * @throw std::out_of_range If @a n is an invalid index.
1404 *
1405 * This function provides for safer data access. The parameter is
1406 * first checked that it is in the range of the string. The function
1407 * throws out_of_range if the check fails.
1408 */
1409 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1410 const_reference
1411 at(size_type __n) const
1412 {
1413 if (__n >= this->size())
1414 __throw_out_of_range_fmt(__N("basic_string::at: __n "("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
1415 "(which is %zu) >= this->size() "("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
1416 "(which is %zu)")("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
,
1417 __n, this->size());
1418 return _M_data()[__n];
1419 }
1420
1421 /**
1422 * @brief Provides access to the data contained in the %string.
1423 * @param __n The index of the character to access.
1424 * @return Read/write reference to the character.
1425 * @throw std::out_of_range If @a n is an invalid index.
1426 *
1427 * This function provides for safer data access. The parameter is
1428 * first checked that it is in the range of the string. The function
1429 * throws out_of_range if the check fails.
1430 */
1431 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1432 reference
1433 at(size_type __n)
1434 {
1435 if (__n >= size())
1436 __throw_out_of_range_fmt(__N("basic_string::at: __n "("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
1437 "(which is %zu) >= this->size() "("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
1438 "(which is %zu)")("basic_string::at: __n " "(which is %zu) >= this->size() "
"(which is %zu)")
,
1439 __n, this->size());
1440 return _M_data()[__n];
1441 }
1442
1443#if __cplusplus201703L >= 201103L
1444 /**
1445 * Returns a read/write reference to the data at the first
1446 * element of the %string.
1447 */
1448 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1449 reference
1450 front() noexcept
1451 {
1452 __glibcxx_assert(!empty())do { if (__builtin_expect(!bool(!empty()), false)) std::__glibcxx_assert_fail
("/usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16/bits/basic_string.h"
, 1452, __PRETTY_FUNCTION__, "!empty()"); } while (false)
;
1453 return operator[](0);
1454 }
1455
1456 /**
1457 * Returns a read-only (constant) reference to the data at the first
1458 * element of the %string.
1459 */
1460 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1461 const_reference
1462 front() const noexcept
1463 {
1464 __glibcxx_assert(!empty())do { if (__builtin_expect(!bool(!empty()), false)) std::__glibcxx_assert_fail
("/usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16/bits/basic_string.h"
, 1464, __PRETTY_FUNCTION__, "!empty()"); } while (false)
;
1465 return operator[](0);
1466 }
1467
1468 /**
1469 * Returns a read/write reference to the data at the last
1470 * element of the %string.
1471 */
1472 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1473 reference
1474 back() noexcept
1475 {
1476 __glibcxx_assert(!empty())do { if (__builtin_expect(!bool(!empty()), false)) std::__glibcxx_assert_fail
("/usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16/bits/basic_string.h"
, 1476, __PRETTY_FUNCTION__, "!empty()"); } while (false)
;
1477 return operator[](this->size() - 1);
1478 }
1479
1480 /**
1481 * Returns a read-only (constant) reference to the data at the
1482 * last element of the %string.
1483 */
1484 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
1485 const_reference
1486 back() const noexcept
1487 {
1488 __glibcxx_assert(!empty())do { if (__builtin_expect(!bool(!empty()), false)) std::__glibcxx_assert_fail
("/usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16/bits/basic_string.h"
, 1488, __PRETTY_FUNCTION__, "!empty()"); } while (false)
;
1489 return operator[](this->size() - 1);
1490 }
1491#endif
1492
1493 // Modifiers:
1494 /**
1495 * @brief Append a string to this string.
1496 * @param __str The string to append.
1497 * @return Reference to this string.
1498 */
1499 _GLIBCXX20_CONSTEXPR
1500 basic_string&
1501 operator+=(const basic_string& __str)
1502 { return this->append(__str); }
1503
1504 /**
1505 * @brief Append a C string.
1506 * @param __s The C string to append.
1507 * @return Reference to this string.
1508 */
1509 _GLIBCXX20_CONSTEXPR
1510 basic_string&
1511 operator+=(const _CharT* __s)
1512 { return this->append(__s); }
1513
1514 /**
1515 * @brief Append a character.
1516 * @param __c The character to append.
1517 * @return Reference to this string.
1518 */
1519 _GLIBCXX20_CONSTEXPR
1520 basic_string&
1521 operator+=(_CharT __c)
1522 {
1523 this->push_back(__c);
1524 return *this;
1525 }
1526
1527#if __cplusplus201703L >= 201103L
1528 /**
1529 * @brief Append an initializer_list of characters.
1530 * @param __l The initializer_list of characters to be appended.
1531 * @return Reference to this string.
1532 */
1533 _GLIBCXX20_CONSTEXPR
1534 basic_string&
1535 operator+=(initializer_list<_CharT> __l)
1536 { return this->append(__l.begin(), __l.size()); }
1537#endif // C++11
1538
1539#ifdef __glibcxx_string_view201803L // >= C++17
1540 /**
1541 * @brief Append a string_view.
1542 * @param __svt An object convertible to string_view to be appended.
1543 * @return Reference to this string.
1544 */
1545 template<typename _Tp>
1546 _GLIBCXX20_CONSTEXPR
1547 _If_sv<_Tp, basic_string&>
1548 operator+=(const _Tp& __svt)
1549 { return this->append(__svt); }
1550#endif // C++17
1551
1552 /**
1553 * @brief Append a string to this string.
1554 * @param __str The string to append.
1555 * @return Reference to this string.
1556 */
1557 _GLIBCXX20_CONSTEXPR
1558 basic_string&
1559 append(const basic_string& __str)
1560 { return this->append(__str._M_data(), __str.size()); }
1561
1562 /**
1563 * @brief Append a substring.
1564 * @param __str The string to append.
1565 * @param __pos Index of the first character of str to append.
1566 * @param __n The number of characters to append.
1567 * @return Reference to this string.
1568 * @throw std::out_of_range if @a __pos is not a valid index.
1569 *
1570 * This function appends @a __n characters from @a __str
1571 * starting at @a __pos to this string. If @a __n is is larger
1572 * than the number of available characters in @a __str, the
1573 * remainder of @a __str is appended.
1574 */
1575 _GLIBCXX20_CONSTEXPR
1576 basic_string&
1577 append(const basic_string& __str, size_type __pos, size_type __n = npos)
1578 { return this->append(__str._M_data()
1579 + __str._M_check(__pos, "basic_string::append"),
1580 __str._M_limit(__pos, __n)); }
1581
1582 /**
1583 * @brief Append a C substring.
1584 * @param __s The C string to append.
1585 * @param __n The number of characters to append.
1586 * @return Reference to this string.
1587 */
1588 _GLIBCXX20_CONSTEXPR
1589 basic_string&
1590 append(const _CharT* __s, size_type __n)
1591 {
1592 __glibcxx_requires_string_len(__s, __n);
1593 _M_check_length(size_type(0), __n, "basic_string::append");
1594 return _M_append(__s, __n);
1595 }
1596
1597 /**
1598 * @brief Append a C string.
1599 * @param __s The C string to append.
1600 * @return Reference to this string.
1601 */
1602 _GLIBCXX20_CONSTEXPR
1603 basic_string&
1604 append(const _CharT* __s)
1605 {
1606 __glibcxx_requires_string(__s);
1607 const size_type __n = traits_type::length(__s);
1608 _M_check_length(size_type(0), __n, "basic_string::append");
1609 return _M_append(__s, __n);
1610 }
1611
1612 /**
1613 * @brief Append multiple characters.
1614 * @param __n The number of characters to append.
1615 * @param __c The character to use.
1616 * @return Reference to this string.
1617 *
1618 * Appends __n copies of __c to this string.
1619 */
1620 _GLIBCXX20_CONSTEXPR
1621 basic_string&
1622 append(size_type __n, _CharT __c)
1623 { return _M_replace_aux(this->size(), size_type(0), __n, __c); }
1624
1625#if __glibcxx_containers_ranges // C++ >= 23
1626 /**
1627 * @brief Append a range to the string.
1628 * @param __rg A range of values that are convertible to `value_type`.
1629 * @since C++23
1630 *
1631 * The range `__rg` is allowed to overlap with `*this`.
1632 */
1633 template<__detail::__container_compatible_range<_CharT> _Rg>
1634 constexpr basic_string&
1635 append_range(_Rg&& __rg)
1636 {
1637 // N.B. __rg may overlap with *this, so we must copy from __rg before
1638 // existing elements or iterators referring to *this are invalidated.
1639 // e.g. in s.append_range(views::concat(s, str)), rg overlaps s.
1640 if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>)
1641 {
1642 const auto __len = size_type(ranges::distance(__rg));
1643
1644 // Don't care if this addition wraps around, we check it below:
1645 const size_type __newlen = size() + __len;
1646
1647 if ((capacity() - size()) >= __len)
1648 _S_copy_range(_M_data() + size(), std::forward<_Rg>(__rg),
1649 __len);
1650 else
1651 {
1652 _M_check_length(0, __len, "basic_string::append_range");
1653 basic_string __s(_M_get_allocator());
1654 __s.reserve(__newlen);
1655 _S_copy_range(__s._M_data() + size(), std::forward<_Rg>(__rg),
1656 __len);
1657 _S_copy(__s._M_data(), _M_data(), size());
1658 if (!_M_is_local())
1659 _M_destroy(_M_allocated_capacity);
1660 _M_data(__s._M_data());
1661 _M_capacity(__s._M_allocated_capacity);
1662 __s._M_data(__s._M_local_data());
1663 __s._M_length(0);
1664 }
1665 _M_set_length(__newlen); // adds null-terminator
1666 }
1667 else
1668 {
1669 basic_string __s(from_range, std::forward<_Rg>(__rg),
1670 _M_get_allocator());
1671 append(__s);
1672 }
1673 return *this;
1674 }
1675#endif
1676
1677#if __cplusplus201703L >= 201103L
1678 /**
1679 * @brief Append an initializer_list of characters.
1680 * @param __l The initializer_list of characters to append.
1681 * @return Reference to this string.
1682 */
1683 _GLIBCXX20_CONSTEXPR
1684 basic_string&
1685 append(initializer_list<_CharT> __l)
1686 { return this->append(__l.begin(), __l.size()); }
1687#endif // C++11
1688
1689 /**
1690 * @brief Append a range of characters.
1691 * @param __first Iterator referencing the first character to append.
1692 * @param __last Iterator marking the end of the range.
1693 * @return Reference to this string.
1694 *
1695 * Appends characters in the range [__first,__last) to this string.
1696 */
1697#if __cplusplus201703L >= 201103L
1698 template<class _InputIterator,
1699 typename = std::_RequireInputIter<_InputIterator>>
1700 _GLIBCXX20_CONSTEXPR
1701#else
1702 template<class _InputIterator>
1703#endif
1704 basic_string&
1705 append(_InputIterator __first, _InputIterator __last)
1706 { return this->replace(end(), end(), __first, __last); }
1707
1708#ifdef __glibcxx_string_view201803L
1709 /**
1710 * @brief Append a string_view.
1711 * @param __svt An object convertible to string_view to be appended.
1712 * @return Reference to this string.
1713 */
1714 template<typename _Tp>
1715 _GLIBCXX20_CONSTEXPR
1716 _If_sv<_Tp, basic_string&>
1717 append(const _Tp& __svt)
1718 {
1719 __sv_type __sv = __svt;
1720 return this->append(__sv.data(), __sv.size());
1721 }
1722
1723 /**
1724 * @brief Append a range of characters from a string_view.
1725 * @param __svt An object convertible to string_view to be appended from.
1726 * @param __pos The position in the string_view to append from.
1727 * @param __n The number of characters to append from the string_view.
1728 * @return Reference to this string.
1729 */
1730 template<typename _Tp>
1731 _GLIBCXX20_CONSTEXPR
1732 _If_sv<_Tp, basic_string&>
1733 append(const _Tp& __svt, size_type __pos, size_type __n = npos)
1734 {
1735 __sv_type __sv = __svt;
1736 return _M_append(__sv.data()
1737 + std::__sv_check(__sv.size(), __pos, "basic_string::append"),
1738 std::__sv_limit(__sv.size(), __pos, __n));
1739 }
1740#endif // C++17
1741
1742 /**
1743 * @brief Append a single character.
1744 * @param __c Character to append.
1745 */
1746 _GLIBCXX20_CONSTEXPR
1747 void
1748 push_back(_CharT __c)
1749 {
1750 const size_type __size = this->size();
1751 if (__size + 1 > this->capacity())
1752 this->_M_mutate(__size, size_type(0), 0, size_type(1));
1753 traits_type::assign(this->_M_data()[__size], __c);
1754 this->_M_set_length(__size + 1);
1755 }
1756
1757 /**
1758 * @brief Set value to contents of another string.
1759 * @param __str Source string to use.
1760 * @return Reference to this string.
1761 */
1762 _GLIBCXX20_CONSTEXPR
1763 basic_string&
1764 assign(const basic_string& __str)
1765 {
1766#if __cplusplus201703L >= 201103L
1767 if (_Alloc_traits::_S_propagate_on_copy_assign())
1768 {
1769 if (!_Alloc_traits::_S_always_equal() && !_M_is_local()
1770 && _M_get_allocator() != __str._M_get_allocator())
1771 {
1772 // Propagating allocator cannot free existing storage so must
1773 // deallocate it before replacing current allocator.
1774 if (__str.size() <= _S_local_capacity)
1775 {
1776 _M_destroy(_M_allocated_capacity);
1777 _M_data(_M_use_local_data());
1778 _M_set_length(0);
1779 }
1780 else
1781 {
1782 const auto __len = __str.size();
1783 auto __alloc = __str._M_get_allocator();
1784 // If this allocation throws there are no effects:
1785 auto __ptr = _S_allocate(__alloc, __len + 1);
1786 _M_destroy(_M_allocated_capacity);
1787 _M_data(__ptr);
1788 _M_capacity(__len);
1789 _M_set_length(__len);
1790 }
1791 }
1792 std::__alloc_on_copy(_M_get_allocator(), __str._M_get_allocator());
1793 }
1794#endif
1795 this->_M_assign(__str);
1796 return *this;
1797 }
1798
1799#if __cplusplus201703L >= 201103L
1800 /**
1801 * @brief Set value to contents of another string.
1802 * @param __str Source string to use.
1803 * @return Reference to this string.
1804 *
1805 * This function sets this string to the exact contents of @a __str.
1806 * @a __str is a valid, but unspecified string.
1807 */
1808 _GLIBCXX20_CONSTEXPR
1809 basic_string&
1810 assign(basic_string&& __str)
1811 noexcept(_Alloc_traits::_S_nothrow_move())
1812 {
1813 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1814 // 2063. Contradictory requirements for string move assignment
1815 return *this = std::move(__str);
1816 }
1817#endif // C++11
1818
1819 /**
1820 * @brief Set value to a substring of a string.
1821 * @param __str The string to use.
1822 * @param __pos Index of the first character of str.
1823 * @param __n Number of characters to use.
1824 * @return Reference to this string.
1825 * @throw std::out_of_range if @a pos is not a valid index.
1826 *
1827 * This function sets this string to the substring of @a __str
1828 * consisting of @a __n characters at @a __pos. If @a __n is
1829 * is larger than the number of available characters in @a
1830 * __str, the remainder of @a __str is used.
1831 */
1832 _GLIBCXX20_CONSTEXPR
1833 basic_string&
1834 assign(const basic_string& __str, size_type __pos, size_type __n = npos)
1835 { return _M_replace(size_type(0), this->size(), __str._M_data()
1836 + __str._M_check(__pos, "basic_string::assign"),
1837 __str._M_limit(__pos, __n)); }
1838
1839 /**
1840 * @brief Set value to a C substring.
1841 * @param __s The C string to use.
1842 * @param __n Number of characters to use.
1843 * @return Reference to this string.
1844 *
1845 * This function sets the value of this string to the first @a __n
1846 * characters of @a __s. If @a __n is is larger than the number of
1847 * available characters in @a __s, the remainder of @a __s is used.
1848 */
1849 _GLIBCXX20_CONSTEXPR
1850 basic_string&
1851 assign(const _CharT* __s, size_type __n)
1852 {
1853 __glibcxx_requires_string_len(__s, __n);
1854 return _M_replace(size_type(0), this->size(), __s, __n);
1855 }
1856
1857 /**
1858 * @brief Set value to contents of a C string.
1859 * @param __s The C string to use.
1860 * @return Reference to this string.
1861 *
1862 * This function sets the value of this string to the value of @a __s.
1863 * The data is copied, so there is no dependence on @a __s once the
1864 * function returns.
1865 */
1866 _GLIBCXX20_CONSTEXPR
1867 basic_string&
1868 assign(const _CharT* __s)
1869 {
1870 __glibcxx_requires_string(__s);
1871 return _M_replace(size_type(0), this->size(), __s,
1872 traits_type::length(__s));
1873 }
1874
1875 /**
1876 * @brief Set value to multiple characters.
1877 * @param __n Length of the resulting string.
1878 * @param __c The character to use.
1879 * @return Reference to this string.
1880 *
1881 * This function sets the value of this string to @a __n copies of
1882 * character @a __c.
1883 */
1884 _GLIBCXX20_CONSTEXPR
1885 basic_string&
1886 assign(size_type __n, _CharT __c)
1887 { return _M_replace_aux(size_type(0), this->size(), __n, __c); }
1888
1889 /**
1890 * @brief Set value to a range of characters.
1891 * @param __first Iterator referencing the first character to append.
1892 * @param __last Iterator marking the end of the range.
1893 * @return Reference to this string.
1894 *
1895 * Sets value of string to characters in the range [__first,__last).
1896 */
1897#if __cplusplus201703L >= 201103L
1898#pragma GCC diagnostic push
1899#pragma GCC diagnostic ignored "-Wc++17-extensions"
1900 template<class _InputIterator,
1901 typename = std::_RequireInputIter<_InputIterator>>
1902 _GLIBCXX20_CONSTEXPR
1903 basic_string&
1904 assign(_InputIterator __first, _InputIterator __last)
1905 {
1906 using _IterTraits = iterator_traits<_InputIterator>;
1907 if constexpr (is_pointer<decltype(std::__niter_base(__first))>::value
1908 && is_same<typename _IterTraits::value_type,
1909 _CharT>::value)
1910 {
1911 __glibcxx_requires_valid_range(__first, __last);
1912 return _M_replace(size_type(0), size(),
1913 std::__niter_base(__first), __last - __first);
1914 }
1915#if __cplusplus201703L >= 202002L
1916 else if constexpr (contiguous_iterator<_InputIterator>
1917 && is_same_v<iter_value_t<_InputIterator>,
1918 _CharT>)
1919 {
1920 __glibcxx_requires_valid_range(__first, __last);
1921 return _M_replace(size_type(0), size(),
1922 std::to_address(__first), __last - __first);
1923 }
1924#endif
1925 else
1926 return *this = basic_string(__first, __last, get_allocator());
1927 }
1928#pragma GCC diagnostic pop
1929#else
1930 template<class _InputIterator>
1931 basic_string&
1932 assign(_InputIterator __first, _InputIterator __last)
1933 { return this->replace(begin(), end(), __first, __last); }
1934#endif
1935
1936#if __glibcxx_containers_ranges // C++ >= 23
1937 /**
1938 * @brief Assign a range to the string.
1939 * @param __rg A range of values that are convertible to `value_type`.
1940 * @since C++23
1941 *
1942 * The range `__rg` is allowed to overlap with `*this`.
1943 */
1944 template<__detail::__container_compatible_range<_CharT> _Rg>
1945 constexpr basic_string&
1946 assign_range(_Rg&& __rg)
1947 {
1948 basic_string __s(from_range, std::forward<_Rg>(__rg),
1949 _M_get_allocator());
1950 assign(std::move(__s));
1951 return *this;
1952 }
1953#endif
1954
1955#if __cplusplus201703L >= 201103L
1956 /**
1957 * @brief Set value to an initializer_list of characters.
1958 * @param __l The initializer_list of characters to assign.
1959 * @return Reference to this string.
1960 */
1961 _GLIBCXX20_CONSTEXPR
1962 basic_string&
1963 assign(initializer_list<_CharT> __l)
1964 {
1965 // The initializer_list array cannot alias the characters in *this
1966 // so we don't need to use replace to that case.
1967 const size_type __n = __l.size();
1968 if (__n > capacity())
1969 *this = basic_string(__l.begin(), __l.end(), get_allocator());
1970 else
1971 {
1972 if (__n)
1973 _S_copy(_M_data(), __l.begin(), __n);
1974 _M_set_length(__n);
1975 }
1976 return *this;
1977 }
1978#endif // C++11
1979
1980#ifdef __glibcxx_string_view201803L // >= C++17
1981 /**
1982 * @brief Set value from a string_view.
1983 * @param __svt The source object convertible to string_view.
1984 * @return Reference to this string.
1985 */
1986 template<typename _Tp>
1987 _GLIBCXX20_CONSTEXPR
1988 _If_sv<_Tp, basic_string&>
1989 assign(const _Tp& __svt)
1990 {
1991 __sv_type __sv = __svt;
1992 return this->assign(__sv.data(), __sv.size());
1993 }
1994
1995 /**
1996 * @brief Set value from a range of characters in a string_view.
1997 * @param __svt The source object convertible to string_view.
1998 * @param __pos The position in the string_view to assign from.
1999 * @param __n The number of characters to assign.
2000 * @return Reference to this string.
2001 */
2002 template<typename _Tp>
2003 _GLIBCXX20_CONSTEXPR
2004 _If_sv<_Tp, basic_string&>
2005 assign(const _Tp& __svt, size_type __pos, size_type __n = npos)
2006 {
2007 __sv_type __sv = __svt;
2008 return _M_replace(size_type(0), this->size(),
2009 __sv.data()
2010 + std::__sv_check(__sv.size(), __pos, "basic_string::assign"),
2011 std::__sv_limit(__sv.size(), __pos, __n));
2012 }
2013#endif // C++17
2014
2015#if __cplusplus201703L >= 201103L
2016 /**
2017 * @brief Insert multiple characters.
2018 * @param __p Const_iterator referencing location in string to
2019 * insert at.
2020 * @param __n Number of characters to insert
2021 * @param __c The character to insert.
2022 * @return Iterator referencing the first inserted char.
2023 * @throw std::length_error If new length exceeds @c max_size().
2024 *
2025 * Inserts @a __n copies of character @a __c starting at the
2026 * position referenced by iterator @a __p. If adding
2027 * characters causes the length to exceed max_size(),
2028 * length_error is thrown. The value of the string doesn't
2029 * change if an error is thrown.
2030 */
2031 _GLIBCXX20_CONSTEXPR
2032 iterator
2033 insert(const_iterator __p, size_type __n, _CharT __c)
2034 {
2035 _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end());
2036 const size_type __pos = __p - begin();
2037 this->replace(__p, __p, __n, __c);
2038 return iterator(this->_M_data() + __pos);
2039 }
2040#else
2041 /**
2042 * @brief Insert multiple characters.
2043 * @param __p Iterator referencing location in string to insert at.
2044 * @param __n Number of characters to insert
2045 * @param __c The character to insert.
2046 * @throw std::length_error If new length exceeds @c max_size().
2047 *
2048 * Inserts @a __n copies of character @a __c starting at the
2049 * position referenced by iterator @a __p. If adding
2050 * characters causes the length to exceed max_size(),
2051 * length_error is thrown. The value of the string doesn't
2052 * change if an error is thrown.
2053 */
2054 void
2055 insert(iterator __p, size_type __n, _CharT __c)
2056 { this->replace(__p, __p, __n, __c); }
2057#endif
2058
2059#if __cplusplus201703L >= 201103L
2060 /**
2061 * @brief Insert a range of characters.
2062 * @param __p Const_iterator referencing location in string to
2063 * insert at.
2064 * @param __beg Start of range.
2065 * @param __end End of range.
2066 * @return Iterator referencing the first inserted char.
2067 * @throw std::length_error If new length exceeds @c max_size().
2068 *
2069 * Inserts characters in range [beg,end). If adding characters
2070 * causes the length to exceed max_size(), length_error is
2071 * thrown. The value of the string doesn't change if an error
2072 * is thrown.
2073 */
2074 template<class _InputIterator,
2075 typename = std::_RequireInputIter<_InputIterator>>
2076 _GLIBCXX20_CONSTEXPR
2077 iterator
2078 insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)
2079 {
2080 _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end());
2081 const size_type __pos = __p - begin();
2082 this->replace(__p, __p, __beg, __end);
2083 return iterator(this->_M_data() + __pos);
2084 }
2085#else
2086 /**
2087 * @brief Insert a range of characters.
2088 * @param __p Iterator referencing location in string to insert at.
2089 * @param __beg Start of range.
2090 * @param __end End of range.
2091 * @throw std::length_error If new length exceeds @c max_size().
2092 *
2093 * Inserts characters in range [__beg,__end). If adding
2094 * characters causes the length to exceed max_size(),
2095 * length_error is thrown. The value of the string doesn't
2096 * change if an error is thrown.
2097 */
2098 template<class _InputIterator>
2099 void
2100 insert(iterator __p, _InputIterator __beg, _InputIterator __end)
2101 { this->replace(__p, __p, __beg, __end); }
2102#endif
2103
2104#if __glibcxx_containers_ranges // C++ >= 23
2105 /**
2106 * @brief Insert a range into the string.
2107 * @param __rg A range of values that are convertible to `value_type`.
2108 * @since C++23
2109 *
2110 * The range `__rg` is allowed to overlap with `*this`.
2111 */
2112 template<__detail::__container_compatible_range<_CharT> _Rg>
2113 constexpr iterator
2114 insert_range(const_iterator __p, _Rg&& __rg)
2115 {
2116 auto __pos = __p - cbegin();
2117
2118 if constexpr (ranges::forward_range<_Rg>)
2119 if (ranges::empty(__rg))
2120 return begin() + __pos;
2121
2122
2123 if (__p == cend())
2124 append_range(std::forward<_Rg>(__rg));
2125 else
2126 {
2127 basic_string __s(from_range, std::forward<_Rg>(__rg),
2128 _M_get_allocator());
2129 insert(__pos, __s);
2130 }
2131 return begin() + __pos;
2132 }
2133#endif
2134
2135#if __cplusplus201703L >= 201103L
2136 /**
2137 * @brief Insert an initializer_list of characters.
2138 * @param __p Iterator referencing location in string to insert at.
2139 * @param __l The initializer_list of characters to insert.
2140 * @throw std::length_error If new length exceeds @c max_size().
2141 */
2142 _GLIBCXX20_CONSTEXPR
2143 iterator
2144 insert(const_iterator __p, initializer_list<_CharT> __l)
2145 { return this->insert(__p, __l.begin(), __l.end()); }
2146
2147#ifdef _GLIBCXX_DEFINING_STRING_INSTANTIATIONS
2148 // See PR libstdc++/83328
2149 void
2150 insert(iterator __p, initializer_list<_CharT> __l)
2151 {
2152 _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end());
2153 this->insert(__p - begin(), __l.begin(), __l.size());
2154 }
2155#endif
2156#endif // C++11
2157
2158 /**
2159 * @brief Insert value of a string.
2160 * @param __pos1 Position in string to insert at.
2161 * @param __str The string to insert.
2162 * @return Reference to this string.
2163 * @throw std::length_error If new length exceeds @c max_size().
2164 *
2165 * Inserts value of @a __str starting at @a __pos1. If adding
2166 * characters causes the length to exceed max_size(),
2167 * length_error is thrown. The value of the string doesn't
2168 * change if an error is thrown.
2169 */
2170 _GLIBCXX20_CONSTEXPR
2171 basic_string&
2172 insert(size_type __pos1, const basic_string& __str)
2173 { return this->replace(__pos1, size_type(0),
2174 __str._M_data(), __str.size()); }
2175
2176 /**
2177 * @brief Insert a substring.
2178 * @param __pos1 Position in string to insert at.
2179 * @param __str The string to insert.
2180 * @param __pos2 Start of characters in str to insert.
2181 * @param __n Number of characters to insert.
2182 * @return Reference to this string.
2183 * @throw std::length_error If new length exceeds @c max_size().
2184 * @throw std::out_of_range If @a pos1 > size() or
2185 * @a __pos2 > @a str.size().
2186 *
2187 * Starting at @a pos1, insert @a __n character of @a __str
2188 * beginning with @a __pos2. If adding characters causes the
2189 * length to exceed max_size(), length_error is thrown. If @a
2190 * __pos1 is beyond the end of this string or @a __pos2 is
2191 * beyond the end of @a __str, out_of_range is thrown. The
2192 * value of the string doesn't change if an error is thrown.
2193 */
2194 _GLIBCXX20_CONSTEXPR
2195 basic_string&
2196 insert(size_type __pos1, const basic_string& __str,
2197 size_type __pos2, size_type __n = npos)
2198 { return this->replace(__pos1, size_type(0), __str._M_data()
2199 + __str._M_check(__pos2, "basic_string::insert"),
2200 __str._M_limit(__pos2, __n)); }
2201
2202 /**
2203 * @brief Insert a C substring.
2204 * @param __pos Position in string to insert at.
2205 * @param __s The C string to insert.
2206 * @param __n The number of characters to insert.
2207 * @return Reference to this string.
2208 * @throw std::length_error If new length exceeds @c max_size().
2209 * @throw std::out_of_range If @a __pos is beyond the end of this
2210 * string.
2211 *
2212 * Inserts the first @a __n characters of @a __s starting at @a
2213 * __pos. If adding characters causes the length to exceed
2214 * max_size(), length_error is thrown. If @a __pos is beyond
2215 * end(), out_of_range is thrown. The value of the string
2216 * doesn't change if an error is thrown.
2217 */
2218 _GLIBCXX20_CONSTEXPR
2219 basic_string&
2220 insert(size_type __pos, const _CharT* __s, size_type __n)
2221 { return this->replace(__pos, size_type(0), __s, __n); }
2222
2223 /**
2224 * @brief Insert a C string.
2225 * @param __pos Position in string to insert at.
2226 * @param __s The C string to insert.
2227 * @return Reference to this string.
2228 * @throw std::length_error If new length exceeds @c max_size().
2229 * @throw std::out_of_range If @a pos is beyond the end of this
2230 * string.
2231 *
2232 * Inserts the first @a n characters of @a __s starting at @a __pos. If
2233 * adding characters causes the length to exceed max_size(),
2234 * length_error is thrown. If @a __pos is beyond end(), out_of_range is
2235 * thrown. The value of the string doesn't change if an error is
2236 * thrown.
2237 */
2238 _GLIBCXX20_CONSTEXPR
2239 basic_string&
2240 insert(size_type __pos, const _CharT* __s)
2241 {
2242 __glibcxx_requires_string(__s);
2243 return this->replace(__pos, size_type(0), __s,
2244 traits_type::length(__s));
2245 }
2246
2247 /**
2248 * @brief Insert multiple characters.
2249 * @param __pos Index in string to insert at.
2250 * @param __n Number of characters to insert
2251 * @param __c The character to insert.
2252 * @return Reference to this string.
2253 * @throw std::length_error If new length exceeds @c max_size().
2254 * @throw std::out_of_range If @a __pos is beyond the end of this
2255 * string.
2256 *
2257 * Inserts @a __n copies of character @a __c starting at index
2258 * @a __pos. If adding characters causes the length to exceed
2259 * max_size(), length_error is thrown. If @a __pos > length(),
2260 * out_of_range is thrown. The value of the string doesn't
2261 * change if an error is thrown.
2262 */
2263 _GLIBCXX20_CONSTEXPR
2264 basic_string&
2265 insert(size_type __pos, size_type __n, _CharT __c)
2266 { return _M_replace_aux(_M_check(__pos, "basic_string::insert"),
2267 size_type(0), __n, __c); }
2268
2269 /**
2270 * @brief Insert one character.
2271 * @param __p Iterator referencing position in string to insert at.
2272 * @param __c The character to insert.
2273 * @return Iterator referencing newly inserted char.
2274 * @throw std::length_error If new length exceeds @c max_size().
2275 *
2276 * Inserts character @a __c at position referenced by @a __p.
2277 * If adding character causes the length to exceed max_size(),
2278 * length_error is thrown. If @a __p is beyond end of string,
2279 * out_of_range is thrown. The value of the string doesn't
2280 * change if an error is thrown.
2281 */
2282 _GLIBCXX20_CONSTEXPR
2283 iterator
2284 insert(__const_iterator __p, _CharT __c)
2285 {
2286 _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end());
2287 const size_type __pos = __p - begin();
2288 _M_replace_aux(__pos, size_type(0), size_type(1), __c);
2289 return iterator(_M_data() + __pos);
2290 }
2291
2292#ifdef __glibcxx_string_view201803L // >= C++17
2293 /**
2294 * @brief Insert a string_view.
2295 * @param __pos Position in string to insert at.
2296 * @param __svt The object convertible to string_view to insert.
2297 * @return Reference to this string.
2298 */
2299 template<typename _Tp>
2300 _GLIBCXX20_CONSTEXPR
2301 _If_sv<_Tp, basic_string&>
2302 insert(size_type __pos, const _Tp& __svt)
2303 {
2304 __sv_type __sv = __svt;
2305 return this->insert(__pos, __sv.data(), __sv.size());
2306 }
2307
2308 /**
2309 * @brief Insert a string_view.
2310 * @param __pos1 Position in string to insert at.
2311 * @param __svt The object convertible to string_view to insert from.
2312 * @param __pos2 Start of characters in str to insert.
2313 * @param __n The number of characters to insert.
2314 * @return Reference to this string.
2315 */
2316 template<typename _Tp>
2317 _GLIBCXX20_CONSTEXPR
2318 _If_sv<_Tp, basic_string&>
2319 insert(size_type __pos1, const _Tp& __svt,
2320 size_type __pos2, size_type __n = npos)
2321 {
2322 __sv_type __sv = __svt;
2323 return this->replace(__pos1, size_type(0),
2324 __sv.data()
2325 + std::__sv_check(__sv.size(), __pos2, "basic_string::insert"),
2326 std::__sv_limit(__sv.size(), __pos2, __n));
2327 }
2328#endif // C++17
2329
2330 /**
2331 * @brief Remove characters.
2332 * @param __pos Index of first character to remove (default 0).
2333 * @param __n Number of characters to remove (default remainder).
2334 * @return Reference to this string.
2335 * @throw std::out_of_range If @a pos is beyond the end of this
2336 * string.
2337 *
2338 * Removes @a __n characters from this string starting at @a
2339 * __pos. The length of the string is reduced by @a __n. If
2340 * there are < @a __n characters to remove, the remainder of
2341 * the string is truncated. If @a __p is beyond end of string,
2342 * out_of_range is thrown. The value of the string doesn't
2343 * change if an error is thrown.
2344 */
2345 _GLIBCXX20_CONSTEXPR
2346 basic_string&
2347 erase(size_type __pos = 0, size_type __n = npos)
2348 {
2349 _M_check(__pos, "basic_string::erase");
2350 if (__n == npos)
2351 this->_M_set_length(__pos);
2352 else if (__n != 0)
2353 this->_M_erase(__pos, _M_limit(__pos, __n));
2354 return *this;
2355 }
2356
2357 /**
2358 * @brief Remove one character.
2359 * @param __position Iterator referencing the character to remove.
2360 * @return iterator referencing same location after removal.
2361 *
2362 * Removes the character at @a __position from this string. The value
2363 * of the string doesn't change if an error is thrown.
2364 */
2365 _GLIBCXX20_CONSTEXPR
2366 iterator
2367 erase(__const_iterator __position)
2368 {
2369 _GLIBCXX_DEBUG_PEDASSERT(__position >= begin()
2370 && __position < end());
2371 const size_type __pos = __position - begin();
2372 this->_M_erase(__pos, size_type(1));
2373 return iterator(_M_data() + __pos);
2374 }
2375
2376 /**
2377 * @brief Remove a range of characters.
2378 * @param __first Iterator referencing the first character to remove.
2379 * @param __last Iterator referencing the end of the range.
2380 * @return Iterator referencing location of first after removal.
2381 *
2382 * Removes the characters in the range [first,last) from this string.
2383 * The value of the string doesn't change if an error is thrown.
2384 */
2385 _GLIBCXX20_CONSTEXPR
2386 iterator
2387 erase(__const_iterator __first, __const_iterator __last)
2388 {
2389 _GLIBCXX_DEBUG_PEDASSERT(__first >= begin() && __first <= __last
2390 && __last <= end());
2391 const size_type __pos = __first - begin();
2392 if (__last == end())
2393 this->_M_set_length(__pos);
2394 else
2395 this->_M_erase(__pos, __last - __first);
2396 return iterator(this->_M_data() + __pos);
2397 }
2398
2399#if __cplusplus201703L >= 201103L
2400 /**
2401 * @brief Remove the last character.
2402 *
2403 * The string must be non-empty.
2404 */
2405 _GLIBCXX20_CONSTEXPR
2406 void
2407 pop_back() noexcept
2408 {
2409 __glibcxx_assert(!empty())do { if (__builtin_expect(!bool(!empty()), false)) std::__glibcxx_assert_fail
("/usr/bin/../lib/gcc/x86_64-redhat-linux/16/../../../../include/c++/16/bits/basic_string.h"
, 2409, __PRETTY_FUNCTION__, "!empty()"); } while (false)
;
2410 _M_erase(size() - 1, 1);
2411 }
2412#endif // C++11
2413
2414 /**
2415 * @brief Replace characters with value from another string.
2416 * @param __pos Index of first character to replace.
2417 * @param __n Number of characters to be replaced.
2418 * @param __str String to insert.
2419 * @return Reference to this string.
2420 * @throw std::out_of_range If @a pos is beyond the end of this
2421 * string.
2422 * @throw std::length_error If new length exceeds @c max_size().
2423 *
2424 * Removes the characters in the range [__pos,__pos+__n) from
2425 * this string. In place, the value of @a __str is inserted.
2426 * If @a __pos is beyond end of string, out_of_range is thrown.
2427 * If the length of the result exceeds max_size(), length_error
2428 * is thrown. The value of the string doesn't change if an
2429 * error is thrown.
2430 */
2431 _GLIBCXX20_CONSTEXPR
2432 basic_string&
2433 replace(size_type __pos, size_type __n, const basic_string& __str)
2434 { return this->replace(__pos, __n, __str._M_data(), __str.size()); }
2435
2436 /**
2437 * @brief Replace characters with value from another string.
2438 * @param __pos1 Index of first character to replace.
2439 * @param __n1 Number of characters to be replaced.
2440 * @param __str String to insert.
2441 * @param __pos2 Index of first character of str to use.
2442 * @param __n2 Number of characters from str to use.
2443 * @return Reference to this string.
2444 * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 >
2445 * __str.size().
2446 * @throw std::length_error If new length exceeds @c max_size().
2447 *
2448 * Removes the characters in the range [__pos1,__pos1 + n) from this
2449 * string. In place, the value of @a __str is inserted. If @a __pos is
2450 * beyond end of string, out_of_range is thrown. If the length of the
2451 * result exceeds max_size(), length_error is thrown. The value of the
2452 * string doesn't change if an error is thrown.
2453 */
2454 _GLIBCXX20_CONSTEXPR
2455 basic_string&
2456 replace(size_type __pos1, size_type __n1, const basic_string& __str,
2457 size_type __pos2, size_type __n2 = npos)
2458 { return this->replace(__pos1, __n1, __str._M_data()
2459 + __str._M_check(__pos2, "basic_string::replace"),
2460 __str._M_limit(__pos2, __n2)); }
2461
2462 /**
2463 * @brief Replace characters with value of a C substring.
2464 * @param __pos Index of first character to replace.
2465 * @param __n1 Number of characters to be replaced.
2466 * @param __s C string to insert.
2467 * @param __n2 Number of characters from @a s to use.
2468 * @return Reference to this string.
2469 * @throw std::out_of_range If @a pos1 > size().
2470 * @throw std::length_error If new length exceeds @c max_size().
2471 *
2472 * Removes the characters in the range [__pos,__pos + __n1)
2473 * from this string. In place, the first @a __n2 characters of
2474 * @a __s are inserted, or all of @a __s if @a __n2 is too large. If
2475 * @a __pos is beyond end of string, out_of_range is thrown. If
2476 * the length of result exceeds max_size(), length_error is
2477 * thrown. The value of the string doesn't change if an error
2478 * is thrown.
2479 */
2480 _GLIBCXX20_CONSTEXPR
2481 basic_string&
2482 replace(size_type __pos, size_type __n1, const _CharT* __s,
2483 size_type __n2)
2484 {
2485 __glibcxx_requires_string_len(__s, __n2);
2486 return _M_replace(_M_check(__pos, "basic_string::replace"),
2487 _M_limit(__pos, __n1), __s, __n2);
2488 }
2489
2490 /**
2491 * @brief Replace characters with value of a C string.
2492 * @param __pos Index of first character to replace.
2493 * @param __n1 Number of characters to be replaced.
2494 * @param __s C string to insert.
2495 * @return Reference to this string.
2496 * @throw std::out_of_range If @a pos > size().
2497 * @throw std::length_error If new length exceeds @c max_size().
2498 *
2499 * Removes the characters in the range [__pos,__pos + __n1)
2500 * from this string. In place, the characters of @a __s are
2501 * inserted. If @a __pos is beyond end of string, out_of_range
2502 * is thrown. If the length of result exceeds max_size(),
2503 * length_error is thrown. The value of the string doesn't
2504 * change if an error is thrown.
2505 */
2506 _GLIBCXX20_CONSTEXPR
2507 basic_string&
2508 replace(size_type __pos, size_type __n1, const _CharT* __s)
2509 {
2510 __glibcxx_requires_string(__s);
2511 return this->replace(__pos, __n1, __s, traits_type::length(__s));
2512 }
2513
2514 /**
2515 * @brief Replace characters with multiple characters.
2516 * @param __pos Index of first character to replace.
2517 * @param __n1 Number of characters to be replaced.
2518 * @param __n2 Number of characters to insert.
2519 * @param __c Character to insert.
2520 * @return Reference to this string.
2521 * @throw std::out_of_range If @a __pos > size().
2522 * @throw std::length_error If new length exceeds @c max_size().
2523 *
2524 * Removes the characters in the range [pos,pos + n1) from this
2525 * string. In place, @a __n2 copies of @a __c are inserted.
2526 * If @a __pos is beyond end of string, out_of_range is thrown.
2527 * If the length of result exceeds max_size(), length_error is
2528 * thrown. The value of the string doesn't change if an error
2529 * is thrown.
2530 */
2531 _GLIBCXX20_CONSTEXPR
2532 basic_string&
2533 replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
2534 { return _M_replace_aux(_M_check(__pos, "basic_string::replace"),
2535 _M_limit(__pos, __n1), __n2, __c); }
2536
2537 /**
2538 * @brief Replace range of characters with string.
2539 * @param __i1 Iterator referencing start of range to replace.
2540 * @param __i2 Iterator referencing end of range to replace.
2541 * @param __str String value to insert.
2542 * @return Reference to this string.
2543 * @throw std::length_error If new length exceeds @c max_size().
2544 *
2545 * Removes the characters in the range [__i1,__i2). In place,
2546 * the value of @a __str is inserted. If the length of result
2547 * exceeds max_size(), length_error is thrown. The value of
2548 * the string doesn't change if an error is thrown.
2549 */
2550 _GLIBCXX20_CONSTEXPR
2551 basic_string&
2552 replace(__const_iterator __i1, __const_iterator __i2,
2553 const basic_string& __str)
2554 { return this->replace(__i1, __i2, __str._M_data(), __str.size()); }
2555
2556 /**
2557 * @brief Replace range of characters with C substring.
2558 * @param __i1 Iterator referencing start of range to replace.
2559 * @param __i2 Iterator referencing end of range to replace.
2560 * @param __s C string value to insert.
2561 * @param __n Number of characters from s to insert.
2562 * @return Reference to this string.
2563 * @throw std::length_error If new length exceeds @c max_size().
2564 *
2565 * Removes the characters in the range [__i1,__i2). In place,
2566 * the first @a __n characters of @a __s are inserted. If the
2567 * length of result exceeds max_size(), length_error is thrown.
2568 * The value of the string doesn't change if an error is
2569 * thrown.
2570 */
2571 _GLIBCXX20_CONSTEXPR
2572 basic_string&
2573 replace(__const_iterator __i1, __const_iterator __i2,
2574 const _CharT* __s, size_type __n)
2575 {
2576 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2577 && __i2 <= end());
2578 return this->replace(__i1 - begin(), __i2 - __i1, __s, __n);
2579 }
2580
2581 /**
2582 * @brief Replace range of characters with C string.
2583 * @param __i1 Iterator referencing start of range to replace.
2584 * @param __i2 Iterator referencing end of range to replace.
2585 * @param __s C string value to insert.
2586 * @return Reference to this string.
2587 * @throw std::length_error If new length exceeds @c max_size().
2588 *
2589 * Removes the characters in the range [__i1,__i2). In place,
2590 * the characters of @a __s are inserted. If the length of
2591 * result exceeds max_size(), length_error is thrown. The
2592 * value of the string doesn't change if an error is thrown.
2593 */
2594 _GLIBCXX20_CONSTEXPR
2595 basic_string&
2596 replace(__const_iterator __i1, __const_iterator __i2, const _CharT* __s)
2597 {
2598 __glibcxx_requires_string(__s);
2599 return this->replace(__i1, __i2, __s, traits_type::length(__s));
2600 }
2601
2602 /**
2603 * @brief Replace range of characters with multiple characters
2604 * @param __i1 Iterator referencing start of range to replace.
2605 * @param __i2 Iterator referencing end of range to replace.
2606 * @param __n Number of characters to insert.
2607 * @param __c Character to insert.
2608 * @return Reference to this string.
2609 * @throw std::length_error If new length exceeds @c max_size().
2610 *
2611 * Removes the characters in the range [__i1,__i2). In place,
2612 * @a __n copies of @a __c are inserted. If the length of
2613 * result exceeds max_size(), length_error is thrown. The
2614 * value of the string doesn't change if an error is thrown.
2615 */
2616 _GLIBCXX20_CONSTEXPR
2617 basic_string&
2618 replace(__const_iterator __i1, __const_iterator __i2, size_type __n,
2619 _CharT __c)
2620 {
2621 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2622 && __i2 <= end());
2623 return _M_replace_aux(__i1 - begin(), __i2 - __i1, __n, __c);
2624 }
2625
2626 /**
2627 * @brief Replace range of characters with range.
2628 * @param __i1 Iterator referencing start of range to replace.
2629 * @param __i2 Iterator referencing end of range to replace.
2630 * @param __k1 Iterator referencing start of range to insert.
2631 * @param __k2 Iterator referencing end of range to insert.
2632 * @return Reference to this string.
2633 * @throw std::length_error If new length exceeds @c max_size().
2634 *
2635 * Removes the characters in the range [__i1,__i2). In place,
2636 * characters in the range [__k1,__k2) are inserted. If the
2637 * length of result exceeds max_size(), length_error is thrown.
2638 * The value of the string doesn't change if an error is
2639 * thrown.
2640 */
2641#if __cplusplus201703L >= 201103L
2642 template<class _InputIterator,
2643 typename = std::_RequireInputIter<_InputIterator>>
2644 _GLIBCXX20_CONSTEXPR
2645 basic_string&
2646 replace(const_iterator __i1, const_iterator __i2,
2647 _InputIterator __k1, _InputIterator __k2)
2648 {
2649 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2650 && __i2 <= end());
2651 __glibcxx_requires_valid_range(__k1, __k2);
2652 return this->_M_replace_dispatch(__i1, __i2, __k1, __k2,
2653 std::__false_type());
2654 }
2655#else
2656 template<class _InputIterator>
2657#ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST
2658 typename __enable_if_not_native_iterator<_InputIterator>::__type
2659#else
2660 basic_string&
2661#endif
2662 replace(iterator __i1, iterator __i2,
2663 _InputIterator __k1, _InputIterator __k2)
2664 {
2665 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2666 && __i2 <= end());
2667 __glibcxx_requires_valid_range(__k1, __k2);
2668 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
2669 return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral());
2670 }
2671#endif
2672
2673 // Specializations for the common case of pointer and iterator:
2674 // useful to avoid the overhead of temporary buffering in _M_replace.
2675 _GLIBCXX20_CONSTEXPR
2676 basic_string&
2677 replace(__const_iterator __i1, __const_iterator __i2,
2678 _CharT* __k1, _CharT* __k2)
2679 {
2680 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2681 && __i2 <= end());
2682 __glibcxx_requires_valid_range(__k1, __k2);
2683 return this->replace(__i1 - begin(), __i2 - __i1,
2684 __k1, __k2 - __k1);
2685 }
2686
2687 _GLIBCXX20_CONSTEXPR
2688 basic_string&
2689 replace(__const_iterator __i1, __const_iterator __i2,
2690 const _CharT* __k1, const _CharT* __k2)
2691 {
2692 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2693 && __i2 <= end());
2694 __glibcxx_requires_valid_range(__k1, __k2);
2695 return this->replace(__i1 - begin(), __i2 - __i1,
2696 __k1, __k2 - __k1);
2697 }
2698
2699 _GLIBCXX20_CONSTEXPR
2700 basic_string&
2701 replace(__const_iterator __i1, __const_iterator __i2,
2702 iterator __k1, iterator __k2)
2703 {
2704 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2705 && __i2 <= end());
2706 __glibcxx_requires_valid_range(__k1, __k2);
2707 return this->replace(__i1 - begin(), __i2 - __i1,
2708 __k1.base(), __k2 - __k1);
2709 }
2710
2711 _GLIBCXX20_CONSTEXPR
2712 basic_string&
2713 replace(__const_iterator __i1, __const_iterator __i2,
2714 const_iterator __k1, const_iterator __k2)
2715 {
2716 _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2
2717 && __i2 <= end());
2718 __glibcxx_requires_valid_range(__k1, __k2);
2719 return this->replace(__i1 - begin(), __i2 - __i1,
2720 __k1.base(), __k2 - __k1);
2721 }
2722
2723#if __glibcxx_containers_ranges // C++ >= 23
2724 /**
2725 * @brief Replace part of the string with a range.
2726 * @param __rg A range of values that are convertible to `value_type`.
2727 * @since C++23
2728 *
2729 * The range `__rg` is allowed to overlap with `*this`.
2730 */
2731 template<__detail::__container_compatible_range<_CharT> _Rg>
2732 constexpr basic_string&
2733 replace_with_range(const_iterator __i1, const_iterator __i2, _Rg&& __rg)
2734 {
2735 if (__i1 == cend())
2736 append_range(std::forward<_Rg>(__rg));
2737 else
2738 {
2739 basic_string __s(from_range, std::forward<_Rg>(__rg),
2740 _M_get_allocator());
2741 replace(__i1, __i2, __s);
2742 }
2743 return *this;
2744 }
2745#endif
2746
2747#if __cplusplus201703L >= 201103L
2748 /**
2749 * @brief Replace range of characters with initializer_list.
2750 * @param __i1 Iterator referencing start of range to replace.
2751 * @param __i2 Iterator referencing end of range to replace.
2752 * @param __l The initializer_list of characters to insert.
2753 * @return Reference to this string.
2754 * @throw std::length_error If new length exceeds @c max_size().
2755 *
2756 * Removes the characters in the range [__i1,__i2). In place,
2757 * characters in the range [__k1,__k2) are inserted. If the
2758 * length of result exceeds max_size(), length_error is thrown.
2759 * The value of the string doesn't change if an error is
2760 * thrown.
2761 */
2762 _GLIBCXX20_CONSTEXPR
2763 basic_string& replace(const_iterator __i1, const_iterator __i2,
2764 initializer_list<_CharT> __l)
2765 { return this->replace(__i1, __i2, __l.begin(), __l.size()); }
2766#endif // C++11
2767
2768#ifdef __glibcxx_string_view201803L // >= C++17
2769 /**
2770 * @brief Replace range of characters with string_view.
2771 * @param __pos The position to replace at.
2772 * @param __n The number of characters to replace.
2773 * @param __svt The object convertible to string_view to insert.
2774 * @return Reference to this string.
2775 */
2776 template<typename _Tp>
2777 _GLIBCXX20_CONSTEXPR
2778 _If_sv<_Tp, basic_string&>
2779 replace(size_type __pos, size_type __n, const _Tp& __svt)
2780 {
2781 __sv_type __sv = __svt;
2782 return this->replace(__pos, __n, __sv.data(), __sv.size());
2783 }
2784
2785 /**
2786 * @brief Replace range of characters with string_view.
2787 * @param __pos1 The position to replace at.
2788 * @param __n1 The number of characters to replace.
2789 * @param __svt The object convertible to string_view to insert from.
2790 * @param __pos2 The position in the string_view to insert from.
2791 * @param __n2 The number of characters to insert.
2792 * @return Reference to this string.
2793 */
2794 template<typename _Tp>
2795 _GLIBCXX20_CONSTEXPR
2796 _If_sv<_Tp, basic_string&>
2797 replace(size_type __pos1, size_type __n1, const _Tp& __svt,
2798 size_type __pos2, size_type __n2 = npos)
2799 {
2800 __sv_type __sv = __svt;
2801 return this->replace(__pos1, __n1,
2802 __sv.data()
2803 + std::__sv_check(__sv.size(), __pos2, "basic_string::replace"),
2804 std::__sv_limit(__sv.size(), __pos2, __n2));
2805 }
2806
2807 /**
2808 * @brief Replace range of characters with string_view.
2809 * @param __i1 An iterator referencing the start position
2810 to replace at.
2811 * @param __i2 An iterator referencing the end position
2812 for the replace.
2813 * @param __svt The object convertible to string_view to insert from.
2814 * @return Reference to this string.
2815 */
2816 template<typename _Tp>
2817 _GLIBCXX20_CONSTEXPR
2818 _If_sv<_Tp, basic_string&>
2819 replace(const_iterator __i1, const_iterator __i2, const _Tp& __svt)
2820 {
2821 __sv_type __sv = __svt;
2822 return this->replace(__i1 - begin(), __i2 - __i1, __sv);
2823 }
2824#endif // C++17
2825
2826 private:
2827 template<class _Integer>
2828 _GLIBCXX20_CONSTEXPR
2829 basic_string&
2830 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2831 _Integer __n, _Integer __val, __true_type)
2832 { return _M_replace_aux(__i1 - begin(), __i2 - __i1, __n, __val); }
2833
2834 template<class _InputIterator>
2835 _GLIBCXX20_CONSTEXPR
2836 basic_string&
2837 _M_replace_dispatch(const_iterator __i1, const_iterator __i2,
2838 _InputIterator __k1, _InputIterator __k2,
2839 __false_type);
2840
2841 _GLIBCXX20_CONSTEXPR
2842 basic_string&
2843 _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
2844 _CharT __c);
2845
2846 __attribute__((__noinline__, __noclone__, __cold__)) void
2847 _M_replace_cold(pointer __p, size_type __len1, const _CharT* __s,
2848 const size_type __len2, const size_type __how_much);
2849
2850 _GLIBCXX20_CONSTEXPR
2851 basic_string&
2852 _M_replace(size_type __pos, size_type __len1, const _CharT* __s,
2853 const size_type __len2);
2854
2855 _GLIBCXX20_CONSTEXPR
2856 basic_string&
2857 _M_append(const _CharT* __s, size_type __n);
2858
2859 public:
2860
2861 /**
2862 * @brief Copy substring into C string.
2863 * @param __s C string to copy value into.
2864 * @param __n Number of characters to copy.
2865 * @param __pos Index of first character to copy.
2866 * @return Number of characters actually copied
2867 * @throw std::out_of_range If __pos > size().
2868 *
2869 * Copies up to @a __n characters starting at @a __pos into the
2870 * C string @a __s. If @a __pos is %greater than size(),
2871 * out_of_range is thrown.
2872 */
2873 _GLIBCXX20_CONSTEXPR
2874 size_type
2875 copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
2876
2877 /**
2878 * @brief Swap contents with another string.
2879 * @param __s String to swap with.
2880 *
2881 * Exchanges the contents of this string with that of @a __s in constant
2882 * time.
2883 */
2884 _GLIBCXX20_CONSTEXPR
2885 void
2886 swap(basic_string& __s) _GLIBCXX_NOEXCEPTnoexcept;
2887
2888 // String operations:
2889 /**
2890 * @brief Return const pointer to null-terminated contents.
2891 *
2892 * This is a handle to internal data. Do not modify or dire things may
2893 * happen.
2894 */
2895 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
2896 const _CharT*
2897 c_str() const _GLIBCXX_NOEXCEPTnoexcept
2898 { return _M_data(); }
2899
2900 /**
2901 * @brief Return const pointer to contents.
2902 *
2903 * This is a pointer to internal data. It is undefined to modify
2904 * the contents through the returned pointer. To get a pointer that
2905 * allows modifying the contents use @c &str[0] instead,
2906 * (or in C++17 the non-const @c str.data() overload).
2907 */
2908 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
2909 const _CharT*
2910 data() const _GLIBCXX_NOEXCEPTnoexcept
2911 { return _M_data(); }
2912
2913#if __cplusplus201703L >= 201703L
2914 /**
2915 * @brief Return non-const pointer to contents.
2916 *
2917 * This is a pointer to the character sequence held by the string.
2918 * Modifying the characters in the sequence is allowed.
2919 */
2920 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
2921 _CharT*
2922 data() noexcept
2923 { return _M_data(); }
2924#endif
2925
2926 /**
2927 * @brief Return copy of allocator used to construct this string.
2928 */
2929 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
2930 allocator_type
2931 get_allocator() const _GLIBCXX_NOEXCEPTnoexcept
2932 { return _M_get_allocator(); }
2933
2934 /**
2935 * @brief Find position of a C substring.
2936 * @param __s C string to locate.
2937 * @param __pos Index of character to search from.
2938 * @param __n Number of characters from @a s to search for.
2939 * @return Index of start of first occurrence.
2940 *
2941 * Starting from @a __pos, searches forward for the first @a
2942 * __n characters in @a __s within this string. If found,
2943 * returns the index where it begins. If not found, returns
2944 * npos.
2945 */
2946 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
2947 size_type
2948 find(const _CharT* __s, size_type __pos, size_type __n) const
2949 _GLIBCXX_NOEXCEPTnoexcept;
2950
2951 /**
2952 * @brief Find position of a string.
2953 * @param __str String to locate.
2954 * @param __pos Index of character to search from (default 0).
2955 * @return Index of start of first occurrence.
2956 *
2957 * Starting from @a __pos, searches forward for value of @a __str within
2958 * this string. If found, returns the index where it begins. If not
2959 * found, returns npos.
2960 */
2961 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
2962 size_type
2963 find(const basic_string& __str, size_type __pos = 0) const
2964 _GLIBCXX_NOEXCEPTnoexcept
2965 { return this->find(__str.data(), __pos, __str.size()); }
2966
2967#ifdef __glibcxx_string_view201803L // >= C++17
2968 /**
2969 * @brief Find position of a string_view.
2970 * @param __svt The object convertible to string_view to locate.
2971 * @param __pos Index of character to search from (default 0).
2972 * @return Index of start of first occurrence.
2973 */
2974 template<typename _Tp>
2975 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
2976 _If_sv<_Tp, size_type>
2977 find(const _Tp& __svt, size_type __pos = 0) const
2978 noexcept(is_same<_Tp, __sv_type>::value)
2979 {
2980 __sv_type __sv = __svt;
2981 return this->find(__sv.data(), __pos, __sv.size());
2982 }
2983#endif // C++17
2984
2985 /**
2986 * @brief Find position of a C string.
2987 * @param __s C string to locate.
2988 * @param __pos Index of character to search from (default 0).
2989 * @return Index of start of first occurrence.
2990 *
2991 * Starting from @a __pos, searches forward for the value of @a
2992 * __s within this string. If found, returns the index where
2993 * it begins. If not found, returns npos.
2994 */
2995 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
2996 size_type
2997 find(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPTnoexcept
2998 {
2999 __glibcxx_requires_string(__s);
3000 return this->find(__s, __pos, traits_type::length(__s));
3001 }
3002
3003 /**
3004 * @brief Find position of a character.
3005 * @param __c Character to locate.
3006 * @param __pos Index of character to search from (default 0).
3007 * @return Index of first occurrence.
3008 *
3009 * Starting from @a __pos, searches forward for @a __c within
3010 * this string. If found, returns the index where it was
3011 * found. If not found, returns npos.
3012 */
3013 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3014 size_type
3015 find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPTnoexcept;
3016
3017 /**
3018 * @brief Find last position of a string.
3019 * @param __str String to locate.
3020 * @param __pos Index of character to search back from (default end).
3021 * @return Index of start of last occurrence.
3022 *
3023 * Starting from @a __pos, searches backward for value of @a
3024 * __str within this string. If found, returns the index where
3025 * it begins. If not found, returns npos.
3026 */
3027 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3028 size_type
3029 rfind(const basic_string& __str, size_type __pos = npos) const
3030 _GLIBCXX_NOEXCEPTnoexcept
3031 { return this->rfind(__str.data(), __pos, __str.size()); }
3032
3033#ifdef __glibcxx_string_view201803L // >= C++17
3034 /**
3035 * @brief Find last position of a string_view.
3036 * @param __svt The object convertible to string_view to locate.
3037 * @param __pos Index of character to search back from (default end).
3038 * @return Index of start of last occurrence.
3039 */
3040 template<typename _Tp>
3041 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3042 _If_sv<_Tp, size_type>
3043 rfind(const _Tp& __svt, size_type __pos = npos) const
3044 noexcept(is_same<_Tp, __sv_type>::value)
3045 {
3046 __sv_type __sv = __svt;
3047 return this->rfind(__sv.data(), __pos, __sv.size());
3048 }
3049#endif // C++17
3050
3051 /**
3052 * @brief Find last position of a C substring.
3053 * @param __s C string to locate.
3054 * @param __pos Index of character to search back from.
3055 * @param __n Number of characters from s to search for.
3056 * @return Index of start of last occurrence.
3057 *
3058 * Starting from @a __pos, searches backward for the first @a
3059 * __n characters in @a __s within this string. If found,
3060 * returns the index where it begins. If not found, returns
3061 * npos.
3062 */
3063 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3064 size_type
3065 rfind(const _CharT* __s, size_type __pos, size_type __n) const
3066 _GLIBCXX_NOEXCEPTnoexcept;
3067
3068 /**
3069 * @brief Find last position of a C string.
3070 * @param __s C string to locate.
3071 * @param __pos Index of character to start search at (default end).
3072 * @return Index of start of last occurrence.
3073 *
3074 * Starting from @a __pos, searches backward for the value of
3075 * @a __s within this string. If found, returns the index
3076 * where it begins. If not found, returns npos.
3077 */
3078 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3079 size_type
3080 rfind(const _CharT* __s, size_type __pos = npos) const
3081 {
3082 __glibcxx_requires_string(__s);
3083 return this->rfind(__s, __pos, traits_type::length(__s));
3084 }
3085
3086 /**
3087 * @brief Find last position of a character.
3088 * @param __c Character to locate.
3089 * @param __pos Index of character to search back from (default end).
3090 * @return Index of last occurrence.
3091 *
3092 * Starting from @a __pos, searches backward for @a __c within
3093 * this string. If found, returns the index where it was
3094 * found. If not found, returns npos.
3095 */
3096 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3097 size_type
3098 rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPTnoexcept;
3099
3100 /**
3101 * @brief Find position of a character of string.
3102 * @param __str String containing characters to locate.
3103 * @param __pos Index of character to search from (default 0).
3104 * @return Index of first occurrence.
3105 *
3106 * Starting from @a __pos, searches forward for one of the
3107 * characters of @a __str within this string. If found,
3108 * returns the index where it was found. If not found, returns
3109 * npos.
3110 */
3111 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3112 size_type
3113 find_first_of(const basic_string& __str, size_type __pos = 0) const
3114 _GLIBCXX_NOEXCEPTnoexcept
3115 { return this->find_first_of(__str.data(), __pos, __str.size()); }
3116
3117#ifdef __glibcxx_string_view201803L // >= C++17
3118 /**
3119 * @brief Find position of a character of a string_view.
3120 * @param __svt An object convertible to string_view containing
3121 * characters to locate.
3122 * @param __pos Index of character to search from (default 0).
3123 * @return Index of first occurrence.
3124 */
3125 template<typename _Tp>
3126 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3127 _If_sv<_Tp, size_type>
3128 find_first_of(const _Tp& __svt, size_type __pos = 0) const
3129 noexcept(is_same<_Tp, __sv_type>::value)
3130 {
3131 __sv_type __sv = __svt;
3132 return this->find_first_of(__sv.data(), __pos, __sv.size());
3133 }
3134#endif // C++17
3135
3136 /**
3137 * @brief Find position of a character of C substring.
3138 * @param __s String containing characters to locate.
3139 * @param __pos Index of character to search from.
3140 * @param __n Number of characters from s to search for.
3141 * @return Index of first occurrence.
3142 *
3143 * Starting from @a __pos, searches forward for one of the
3144 * first @a __n characters of @a __s within this string. If
3145 * found, returns the index where it was found. If not found,
3146 * returns npos.
3147 */
3148 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3149 size_type
3150 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
3151 _GLIBCXX_NOEXCEPTnoexcept;
3152
3153 /**
3154 * @brief Find position of a character of C string.
3155 * @param __s String containing characters to locate.
3156 * @param __pos Index of character to search from (default 0).
3157 * @return Index of first occurrence.
3158 *
3159 * Starting from @a __pos, searches forward for one of the
3160 * characters of @a __s within this string. If found, returns
3161 * the index where it was found. If not found, returns npos.
3162 */
3163 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3164 size_type
3165 find_first_of(const _CharT* __s, size_type __pos = 0) const
3166 _GLIBCXX_NOEXCEPTnoexcept
3167 {
3168 __glibcxx_requires_string(__s);
3169 return this->find_first_of(__s, __pos, traits_type::length(__s));
3170 }
3171
3172 /**
3173 * @brief Find position of a character.
3174 * @param __c Character to locate.
3175 * @param __pos Index of character to search from (default 0).
3176 * @return Index of first occurrence.
3177 *
3178 * Starting from @a __pos, searches forward for the character
3179 * @a __c within this string. If found, returns the index
3180 * where it was found. If not found, returns npos.
3181 *
3182 * Note: equivalent to find(__c, __pos).
3183 */
3184 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3185 size_type
3186 find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPTnoexcept
3187 { return this->find(__c, __pos); }
3188
3189 /**
3190 * @brief Find last position of a character of string.
3191 * @param __str String containing characters to locate.
3192 * @param __pos Index of character to search back from (default end).
3193 * @return Index of last occurrence.
3194 *
3195 * Starting from @a __pos, searches backward for one of the
3196 * characters of @a __str within this string. If found,
3197 * returns the index where it was found. If not found, returns
3198 * npos.
3199 */
3200 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3201 size_type
3202 find_last_of(const basic_string& __str, size_type __pos = npos) const
3203 _GLIBCXX_NOEXCEPTnoexcept
3204 { return this->find_last_of(__str.data(), __pos, __str.size()); }
3205
3206#ifdef __glibcxx_string_view201803L // >= C++17
3207 /**
3208 * @brief Find last position of a character of string.
3209 * @param __svt An object convertible to string_view containing
3210 * characters to locate.
3211 * @param __pos Index of character to search back from (default end).
3212 * @return Index of last occurrence.
3213 */
3214 template<typename _Tp>
3215 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3216 _If_sv<_Tp, size_type>
3217 find_last_of(const _Tp& __svt, size_type __pos = npos) const
3218 noexcept(is_same<_Tp, __sv_type>::value)
3219 {
3220 __sv_type __sv = __svt;
3221 return this->find_last_of(__sv.data(), __pos, __sv.size());
3222 }
3223#endif // C++17
3224
3225 /**
3226 * @brief Find last position of a character of C substring.
3227 * @param __s C string containing characters to locate.
3228 * @param __pos Index of character to search back from.
3229 * @param __n Number of characters from s to search for.
3230 * @return Index of last occurrence.
3231 *
3232 * Starting from @a __pos, searches backward for one of the
3233 * first @a __n characters of @a __s within this string. If
3234 * found, returns the index where it was found. If not found,
3235 * returns npos.
3236 */
3237 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3238 size_type
3239 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
3240 _GLIBCXX_NOEXCEPTnoexcept;
3241
3242 /**
3243 * @brief Find last position of a character of C string.
3244 * @param __s C string containing characters to locate.
3245 * @param __pos Index of character to search back from (default end).
3246 * @return Index of last occurrence.
3247 *
3248 * Starting from @a __pos, searches backward for one of the
3249 * characters of @a __s within this string. If found, returns
3250 * the index where it was found. If not found, returns npos.
3251 */
3252 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3253 size_type
3254 find_last_of(const _CharT* __s, size_type __pos = npos) const
3255 _GLIBCXX_NOEXCEPTnoexcept
3256 {
3257 __glibcxx_requires_string(__s);
3258 return this->find_last_of(__s, __pos, traits_type::length(__s));
3259 }
3260
3261 /**
3262 * @brief Find last position of a character.
3263 * @param __c Character to locate.
3264 * @param __pos Index of character to search back from (default end).
3265 * @return Index of last occurrence.
3266 *
3267 * Starting from @a __pos, searches backward for @a __c within
3268 * this string. If found, returns the index where it was
3269 * found. If not found, returns npos.
3270 *
3271 * Note: equivalent to rfind(__c, __pos).
3272 */
3273 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3274 size_type
3275 find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPTnoexcept
3276 { return this->rfind(__c, __pos); }
3277
3278 /**
3279 * @brief Find position of a character not in string.
3280 * @param __str String containing characters to avoid.
3281 * @param __pos Index of character to search from (default 0).
3282 * @return Index of first occurrence.
3283 *
3284 * Starting from @a __pos, searches forward for a character not contained
3285 * in @a __str within this string. If found, returns the index where it
3286 * was found. If not found, returns npos.
3287 */
3288 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3289 size_type
3290 find_first_not_of(const basic_string& __str, size_type __pos = 0) const
3291 _GLIBCXX_NOEXCEPTnoexcept
3292 { return this->find_first_not_of(__str.data(), __pos, __str.size()); }
3293
3294#ifdef __glibcxx_string_view201803L // >= C++17
3295 /**
3296 * @brief Find position of a character not in a string_view.
3297 * @param __svt A object convertible to string_view containing
3298 * characters to avoid.
3299 * @param __pos Index of character to search from (default 0).
3300 * @return Index of first occurrence.
3301 */
3302 template<typename _Tp>
3303 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3304 _If_sv<_Tp, size_type>
3305 find_first_not_of(const _Tp& __svt, size_type __pos = 0) const
3306 noexcept(is_same<_Tp, __sv_type>::value)
3307 {
3308 __sv_type __sv = __svt;
3309 return this->find_first_not_of(__sv.data(), __pos, __sv.size());
3310 }
3311#endif // C++17
3312
3313 /**
3314 * @brief Find position of a character not in C substring.
3315 * @param __s C string containing characters to avoid.
3316 * @param __pos Index of character to search from.
3317 * @param __n Number of characters from __s to consider.
3318 * @return Index of first occurrence.
3319 *
3320 * Starting from @a __pos, searches forward for a character not
3321 * contained in the first @a __n characters of @a __s within
3322 * this string. If found, returns the index where it was
3323 * found. If not found, returns npos.
3324 */
3325 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3326 size_type
3327 find_first_not_of(const _CharT* __s, size_type __pos,
3328 size_type __n) const _GLIBCXX_NOEXCEPTnoexcept;
3329
3330 /**
3331 * @brief Find position of a character not in C string.
3332 * @param __s C string containing characters to avoid.
3333 * @param __pos Index of character to search from (default 0).
3334 * @return Index of first occurrence.
3335 *
3336 * Starting from @a __pos, searches forward for a character not
3337 * contained in @a __s within this string. If found, returns
3338 * the index where it was found. If not found, returns npos.
3339 */
3340 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3341 size_type
3342 find_first_not_of(const _CharT* __s, size_type __pos = 0) const
3343 _GLIBCXX_NOEXCEPTnoexcept
3344 {
3345 __glibcxx_requires_string(__s);
3346 return this->find_first_not_of(__s, __pos, traits_type::length(__s));
3347 }
3348
3349 /**
3350 * @brief Find position of a different character.
3351 * @param __c Character to avoid.
3352 * @param __pos Index of character to search from (default 0).
3353 * @return Index of first occurrence.
3354 *
3355 * Starting from @a __pos, searches forward for a character
3356 * other than @a __c within this string. If found, returns the
3357 * index where it was found. If not found, returns npos.
3358 */
3359 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3360 size_type
3361 find_first_not_of(_CharT __c, size_type __pos = 0) const
3362 _GLIBCXX_NOEXCEPTnoexcept;
3363
3364 /**
3365 * @brief Find last position of a character not in string.
3366 * @param __str String containing characters to avoid.
3367 * @param __pos Index of character to search back from (default end).
3368 * @return Index of last occurrence.
3369 *
3370 * Starting from @a __pos, searches backward for a character
3371 * not contained in @a __str within this string. If found,
3372 * returns the index where it was found. If not found, returns
3373 * npos.
3374 */
3375 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3376 size_type
3377 find_last_not_of(const basic_string& __str, size_type __pos = npos) const
3378 _GLIBCXX_NOEXCEPTnoexcept
3379 { return this->find_last_not_of(__str.data(), __pos, __str.size()); }
3380
3381#ifdef __glibcxx_string_view201803L // >= C++17
3382 /**
3383 * @brief Find last position of a character not in a string_view.
3384 * @param __svt An object convertible to string_view containing
3385 * characters to avoid.
3386 * @param __pos Index of character to search back from (default end).
3387 * @return Index of last occurrence.
3388 */
3389 template<typename _Tp>
3390 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3391 _If_sv<_Tp, size_type>
3392 find_last_not_of(const _Tp& __svt, size_type __pos = npos) const
3393 noexcept(is_same<_Tp, __sv_type>::value)
3394 {
3395 __sv_type __sv = __svt;
3396 return this->find_last_not_of(__sv.data(), __pos, __sv.size());
3397 }
3398#endif // C++17
3399
3400 /**
3401 * @brief Find last position of a character not in C substring.
3402 * @param __s C string containing characters to avoid.
3403 * @param __pos Index of character to search back from.
3404 * @param __n Number of characters from s to consider.
3405 * @return Index of last occurrence.
3406 *
3407 * Starting from @a __pos, searches backward for a character not
3408 * contained in the first @a __n characters of @a __s within this string.
3409 * If found, returns the index where it was found. If not found,
3410 * returns npos.
3411 */
3412 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3413 size_type
3414 find_last_not_of(const _CharT* __s, size_type __pos,
3415 size_type __n) const _GLIBCXX_NOEXCEPTnoexcept;
3416 /**
3417 * @brief Find last position of a character not in C string.
3418 * @param __s C string containing characters to avoid.
3419 * @param __pos Index of character to search back from (default end).
3420 * @return Index of last occurrence.
3421 *
3422 * Starting from @a __pos, searches backward for a character
3423 * not contained in @a __s within this string. If found,
3424 * returns the index where it was found. If not found, returns
3425 * npos.
3426 */
3427 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3428 size_type
3429 find_last_not_of(const _CharT* __s, size_type __pos = npos) const
3430 _GLIBCXX_NOEXCEPTnoexcept
3431 {
3432 __glibcxx_requires_string(__s);
3433 return this->find_last_not_of(__s, __pos, traits_type::length(__s));
3434 }
3435
3436 /**
3437 * @brief Find last position of a different character.
3438 * @param __c Character to avoid.
3439 * @param __pos Index of character to search back from (default end).
3440 * @return Index of last occurrence.
3441 *
3442 * Starting from @a __pos, searches backward for a character other than
3443 * @a __c within this string. If found, returns the index where it was
3444 * found. If not found, returns npos.
3445 */
3446 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3447 size_type
3448 find_last_not_of(_CharT __c, size_type __pos = npos) const
3449 _GLIBCXX_NOEXCEPTnoexcept;
3450
3451 /**
3452 * @brief Get a substring.
3453 * @param __pos Index of first character (default 0).
3454 * @param __n Number of characters in substring (default remainder).
3455 * @return The new string.
3456 * @throw std::out_of_range If __pos > size().
3457 *
3458 * Construct and return a new string using the @a __n
3459 * characters starting at @a __pos. If the string is too
3460 * short, use the remainder of the characters. If @a __pos is
3461 * beyond the end of the string, out_of_range is thrown.
3462 */
3463 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3464 basic_string
3465 substr(size_type __pos = 0, size_type __n = npos) const
3466 { return basic_string(*this,
3467 _M_check(__pos, "basic_string::substr"), __n); }
3468
3469#if __cplusplus201703L >= 202302L
3470 _GLIBCXX_NODISCARD[[__nodiscard__]]
3471 constexpr basic_string
3472 substr(size_type __pos = 0) &&
3473 { return basic_string(std::move(*this), __pos); }
3474
3475 _GLIBCXX_NODISCARD[[__nodiscard__]]
3476 constexpr basic_string
3477 substr(size_type __pos, size_type __n) &&
3478 { return basic_string(std::move(*this), __pos, __n); }
3479#endif // C++23
3480
3481#ifdef __glibcxx_string_subview // >= C++26
3482 /**
3483 * @brief Get a subview.
3484 * @param __pos Index of first character (default 0).
3485 * @param __n Number of characters in subview (default remainder).
3486 * @return The subview.
3487 * @throw std::out_of_range If __pos > size().
3488 *
3489 * Construct and return a subview using the `__n` characters starting at
3490 * `__pos`. If the string is too short, use the remainder of the
3491 * characters. If `__pos` is beyond the end of the string, out_of_range
3492 * is thrown.
3493 */
3494 [[nodiscard]]
3495 constexpr basic_string_view<_CharT, _Traits>
3496 subview(size_type __pos = 0, size_type __n = npos) const
3497 { return __sv_type(*this).subview(__pos, __n); }
3498#endif
3499
3500 /**
3501 * @brief Compare to a string.
3502 * @param __str String to compare against.
3503 * @return Integer < 0, 0, or > 0.
3504 *
3505 * Returns an integer < 0 if this string is ordered before @a
3506 * __str, 0 if their values are equivalent, or > 0 if this
3507 * string is ordered after @a __str. Determines the effective
3508 * length rlen of the strings to compare as the smallest of
3509 * size() and str.size(). The function then compares the two
3510 * strings by calling traits::compare(data(), str.data(),rlen).
3511 * If the result of the comparison is nonzero returns it,
3512 * otherwise the shorter one is ordered first.
3513 */
3514 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3515 int
3516 compare(const basic_string& __str) const
3517 {
3518 const size_type __size = this->size();
3519 const size_type __osize = __str.size();
3520 const size_type __len = std::min(__size, __osize);
3521
3522 int __r = traits_type::compare(_M_data(), __str.data(), __len);
3523 if (!__r)
3524 __r = _S_compare(__size, __osize);
3525 return __r;
3526 }
3527
3528#ifdef __glibcxx_string_view201803L // >= C++17
3529 /**
3530 * @brief Compare to a string_view.
3531 * @param __svt An object convertible to string_view to compare against.
3532 * @return Integer < 0, 0, or > 0.
3533 */
3534 template<typename _Tp>
3535 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3536 _If_sv<_Tp, int>
3537 compare(const _Tp& __svt) const
3538 noexcept(is_same<_Tp, __sv_type>::value)
3539 {
3540 __sv_type __sv = __svt;
3541 const size_type __size = this->size();
3542 const size_type __osize = __sv.size();
3543 const size_type __len = std::min(__size, __osize);
3544
3545 int __r = traits_type::compare(_M_data(), __sv.data(), __len);
3546 if (!__r)
3547 __r = _S_compare(__size, __osize);
3548 return __r;
3549 }
3550
3551 /**
3552 * @brief Compare to a string_view.
3553 * @param __pos A position in the string to start comparing from.
3554 * @param __n The number of characters to compare.
3555 * @param __svt An object convertible to string_view to compare
3556 * against.
3557 * @return Integer < 0, 0, or > 0.
3558 */
3559 template<typename _Tp>
3560 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3561 _If_sv<_Tp, int>
3562 compare(size_type __pos, size_type __n, const _Tp& __svt) const
3563 {
3564 __sv_type __sv = __svt;
3565 return __sv_type(*this).substr(__pos, __n).compare(__sv);
3566 }
3567
3568 /**
3569 * @brief Compare to a string_view.
3570 * @param __pos1 A position in the string to start comparing from.
3571 * @param __n1 The number of characters to compare.
3572 * @param __svt An object convertible to string_view to compare
3573 * against.
3574 * @param __pos2 A position in the string_view to start comparing from.
3575 * @param __n2 The number of characters to compare.
3576 * @return Integer < 0, 0, or > 0.
3577 */
3578 template<typename _Tp>
3579 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3580 _If_sv<_Tp, int>
3581 compare(size_type __pos1, size_type __n1, const _Tp& __svt,
3582 size_type __pos2, size_type __n2 = npos) const
3583 {
3584 __sv_type __sv = __svt;
3585 return __sv_type(*this)
3586 .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
3587 }
3588#endif // C++17
3589
3590 /**
3591 * @brief Compare substring to a string.
3592 * @param __pos Index of first character of substring.
3593 * @param __n Number of characters in substring.
3594 * @param __str String to compare against.
3595 * @return Integer < 0, 0, or > 0.
3596 *
3597 * Form the substring of this string from the @a __n characters
3598 * starting at @a __pos. Returns an integer < 0 if the
3599 * substring is ordered before @a __str, 0 if their values are
3600 * equivalent, or > 0 if the substring is ordered after @a
3601 * __str. Determines the effective length rlen of the strings
3602 * to compare as the smallest of the length of the substring
3603 * and @a __str.size(). The function then compares the two
3604 * strings by calling
3605 * traits::compare(substring.data(),str.data(),rlen). If the
3606 * result of the comparison is nonzero returns it, otherwise
3607 * the shorter one is ordered first.
3608 */
3609 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3610 int
3611 compare(size_type __pos, size_type __n, const basic_string& __str) const
3612 {
3613 _M_check(__pos, "basic_string::compare");
3614 __n = _M_limit(__pos, __n);
3615 const size_type __osize = __str.size();
3616 const size_type __len = std::min(__n, __osize);
3617 int __r = traits_type::compare(_M_data() + __pos, __str.data(), __len);
3618 if (!__r)
3619 __r = _S_compare(__n, __osize);
3620 return __r;
3621 }
3622
3623 /**
3624 * @brief Compare substring to a substring.
3625 * @param __pos1 Index of first character of substring.
3626 * @param __n1 Number of characters in substring.
3627 * @param __str String to compare against.
3628 * @param __pos2 Index of first character of substring of str.
3629 * @param __n2 Number of characters in substring of str.
3630 * @return Integer < 0, 0, or > 0.
3631 *
3632 * Form the substring of this string from the @a __n1
3633 * characters starting at @a __pos1. Form the substring of @a
3634 * __str from the @a __n2 characters starting at @a __pos2.
3635 * Returns an integer < 0 if this substring is ordered before
3636 * the substring of @a __str, 0 if their values are equivalent,
3637 * or > 0 if this substring is ordered after the substring of
3638 * @a __str. Determines the effective length rlen of the
3639 * strings to compare as the smallest of the lengths of the
3640 * substrings. The function then compares the two strings by
3641 * calling
3642 * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen).
3643 * If the result of the comparison is nonzero returns it,
3644 * otherwise the shorter one is ordered first.
3645 */
3646 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3647 int
3648 compare(size_type __pos1, size_type __n1, const basic_string& __str,
3649 size_type __pos2, size_type __n2 = npos) const
3650 {
3651 _M_check(__pos1, "basic_string::compare");
3652 __str._M_check(__pos2, "basic_string::compare");
3653 __n1 = _M_limit(__pos1, __n1);
3654 __n2 = __str._M_limit(__pos2, __n2);
3655 const size_type __len = std::min(__n1, __n2);
3656 int __r = traits_type::compare(_M_data() + __pos1,
3657 __str.data() + __pos2, __len);
3658 if (!__r)
3659 __r = _S_compare(__n1, __n2);
3660 return __r;
3661 }
3662
3663 /**
3664 * @brief Compare to a C string.
3665 * @param __s C string to compare against.
3666 * @return Integer < 0, 0, or > 0.
3667 *
3668 * Returns an integer < 0 if this string is ordered before @a __s, 0 if
3669 * their values are equivalent, or > 0 if this string is ordered after
3670 * @a __s. Determines the effective length rlen of the strings to
3671 * compare as the smallest of size() and the length of a string
3672 * constructed from @a __s. The function then compares the two strings
3673 * by calling traits::compare(data(),s,rlen). If the result of the
3674 * comparison is nonzero returns it, otherwise the shorter one is
3675 * ordered first.
3676 */
3677 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3678 int
3679 compare(const _CharT* __s) const _GLIBCXX_NOEXCEPTnoexcept
3680 {
3681 __glibcxx_requires_string(__s);
3682 const size_type __size = this->size();
3683 const size_type __osize = traits_type::length(__s);
3684 const size_type __len = std::min(__size, __osize);
3685 int __r = traits_type::compare(_M_data(), __s, __len);
3686 if (!__r)
3687 __r = _S_compare(__size, __osize);
3688 return __r;
3689 }
3690
3691 // _GLIBCXX_RESOLVE_LIB_DEFECTS
3692 // 5 String::compare specification questionable
3693 /**
3694 * @brief Compare substring to a C string.
3695 * @param __pos Index of first character of substring.
3696 * @param __n1 Number of characters in substring.
3697 * @param __s C string to compare against.
3698 * @return Integer < 0, 0, or > 0.
3699 *
3700 * Form the substring of this string from the @a __n1
3701 * characters starting at @a pos. Returns an integer < 0 if
3702 * the substring is ordered before @a __s, 0 if their values
3703 * are equivalent, or > 0 if the substring is ordered after @a
3704 * __s. Determines the effective length rlen of the strings to
3705 * compare as the smallest of the length of the substring and
3706 * the length of a string constructed from @a __s. The
3707 * function then compares the two string by calling
3708 * traits::compare(substring.data(),__s,rlen). If the result of
3709 * the comparison is nonzero returns it, otherwise the shorter
3710 * one is ordered first.
3711 */
3712 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3713 int
3714 compare(size_type __pos, size_type __n1, const _CharT* __s) const
3715 {
3716 __glibcxx_requires_string(__s);
3717 _M_check(__pos, "basic_string::compare");
3718 __n1 = _M_limit(__pos, __n1);
3719 const size_type __osize = traits_type::length(__s);
3720 const size_type __len = std::min(__n1, __osize);
3721 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
3722 if (!__r)
3723 __r = _S_compare(__n1, __osize);
3724 return __r;
3725 }
3726
3727 /**
3728 * @brief Compare substring against a character %array.
3729 * @param __pos Index of first character of substring.
3730 * @param __n1 Number of characters in substring.
3731 * @param __s character %array to compare against.
3732 * @param __n2 Number of characters of s.
3733 * @return Integer < 0, 0, or > 0.
3734 *
3735 * Form the substring of this string from the @a __n1
3736 * characters starting at @a __pos. Form a string from the
3737 * first @a __n2 characters of @a __s. Returns an integer < 0
3738 * if this substring is ordered before the string from @a __s,
3739 * 0 if their values are equivalent, or > 0 if this substring
3740 * is ordered after the string from @a __s. Determines the
3741 * effective length rlen of the strings to compare as the
3742 * smallest of the length of the substring and @a __n2. The
3743 * function then compares the two strings by calling
3744 * traits::compare(substring.data(),s,rlen). If the result of
3745 * the comparison is nonzero returns it, otherwise the shorter
3746 * one is ordered first.
3747 *
3748 * NB: s must have at least n2 characters, &apos;\\0&apos; has
3749 * no special meaning.
3750 */
3751 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3752 int
3753 compare(size_type __pos, size_type __n1, const _CharT* __s,
3754 size_type __n2) const
3755 {
3756 __glibcxx_requires_string_len(__s, __n2);
3757 _M_check(__pos, "basic_string::compare");
3758 __n1 = _M_limit(__pos, __n1);
3759 const size_type __len = std::min(__n1, __n2);
3760 int __r = traits_type::compare(_M_data() + __pos, __s, __len);
3761 if (!__r)
3762 __r = _S_compare(__n1, __n2);
3763 return __r;
3764 }
3765
3766#if __cplusplus201703L >= 202002L
3767 [[nodiscard]]
3768 constexpr bool
3769 starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept
3770 { return __sv_type(this->data(), this->size()).starts_with(__x); }
3771
3772 [[nodiscard]]
3773 constexpr bool
3774 starts_with(_CharT __x) const noexcept
3775 { return __sv_type(this->data(), this->size()).starts_with(__x); }
3776
3777 [[nodiscard, __gnu__::__nonnull__]]
3778 constexpr bool
3779 starts_with(const _CharT* __x) const noexcept
3780 { return __sv_type(this->data(), this->size()).starts_with(__x); }
3781
3782 [[nodiscard]]
3783 constexpr bool
3784 ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept
3785 { return __sv_type(this->data(), this->size()).ends_with(__x); }
3786
3787 [[nodiscard]]
3788 constexpr bool
3789 ends_with(_CharT __x) const noexcept
3790 { return __sv_type(this->data(), this->size()).ends_with(__x); }
3791
3792 [[nodiscard, __gnu__::__nonnull__]]
3793 constexpr bool
3794 ends_with(const _CharT* __x) const noexcept
3795 { return __sv_type(this->data(), this->size()).ends_with(__x); }
3796#endif // C++20
3797
3798#if __cplusplus201703L > 202002L
3799 [[nodiscard]]
3800 constexpr bool
3801 contains(basic_string_view<_CharT, _Traits> __x) const noexcept
3802 { return __sv_type(this->data(), this->size()).contains(__x); }
3803
3804 [[nodiscard]]
3805 constexpr bool
3806 contains(_CharT __x) const noexcept
3807 { return __sv_type(this->data(), this->size()).contains(__x); }
3808
3809 [[nodiscard, __gnu__::__nonnull__]]
3810 constexpr bool
3811 contains(const _CharT* __x) const noexcept
3812 { return __sv_type(this->data(), this->size()).contains(__x); }
3813#endif // C++23
3814
3815 // Allow basic_stringbuf::__xfer_bufptrs to call _M_length:
3816 template<typename, typename, typename> friend class basic_stringbuf;
3817 };
3818_GLIBCXX_END_NAMESPACE_CXX11}
3819_GLIBCXX_END_NAMESPACE_VERSION
3820} // namespace std
3821#endif // _GLIBCXX_USE_CXX11_ABI
3822
3823namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default")))
3824{
3825_GLIBCXX_BEGIN_NAMESPACE_VERSION
3826
3827#if __cpp_deduction_guides201703L >= 201606
3828_GLIBCXX_BEGIN_NAMESPACE_CXX11namespace __cxx11 {
3829 template<typename _InputIterator, typename _CharT
3830 = typename iterator_traits<_InputIterator>::value_type,
3831 typename _Allocator = allocator<_CharT>,
3832 typename = _RequireInputIter<_InputIterator>,
3833 typename = _RequireAllocator<_Allocator>>
3834 basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
3835 -> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
3836
3837 // _GLIBCXX_RESOLVE_LIB_DEFECTS
3838 // 3075. basic_string needs deduction guides from basic_string_view
3839 template<typename _CharT, typename _Traits,
3840 typename _Allocator = allocator<_CharT>,
3841 typename = _RequireAllocator<_Allocator>>
3842 basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
3843 -> basic_string<_CharT, _Traits, _Allocator>;
3844
3845 template<typename _CharT, typename _Traits,
3846 typename _Allocator = allocator<_CharT>,
3847 typename = _RequireAllocator<_Allocator>>
3848 basic_string(basic_string_view<_CharT, _Traits>,
3849 typename basic_string<_CharT, _Traits, _Allocator>::size_type,
3850 typename basic_string<_CharT, _Traits, _Allocator>::size_type,
3851 const _Allocator& = _Allocator())
3852 -> basic_string<_CharT, _Traits, _Allocator>;
3853
3854#if __glibcxx_containers_ranges // C++ >= 23
3855 template<ranges::input_range _Rg,
3856 typename _Allocator = allocator<ranges::range_value_t<_Rg>>>
3857 basic_string(from_range_t, _Rg&&, _Allocator = _Allocator())
3858 -> basic_string<ranges::range_value_t<_Rg>,
3859 char_traits<ranges::range_value_t<_Rg>>,
3860 _Allocator>;
3861#endif
3862_GLIBCXX_END_NAMESPACE_CXX11}
3863#endif
3864
3865 template<typename _Str>
3866 _GLIBCXX20_CONSTEXPR
3867 inline _Str
3868 __str_concat(typename _Str::value_type const* __lhs,
3869 typename _Str::size_type __lhs_len,
3870 typename _Str::value_type const* __rhs,
3871 typename _Str::size_type __rhs_len,
3872 typename _Str::allocator_type const& __a)
3873 {
3874 typedef typename _Str::allocator_type allocator_type;
3875 typedef __gnu_cxx::__alloc_traits<allocator_type> _Alloc_traits;
3876 _Str __str(_Alloc_traits::_S_select_on_copy(__a));
3877 __str.reserve(__lhs_len + __rhs_len);
3878 __str.append(__lhs, __lhs_len);
3879 __str.append(__rhs, __rhs_len);
3880 return __str;
3881 }
3882
3883 // operator+
3884 /**
3885 * @brief Concatenate two strings.
3886 * @param __lhs First string.
3887 * @param __rhs Last string.
3888 * @return New string with value of @a __lhs followed by @a __rhs.
3889 */
3890 template<typename _CharT, typename _Traits, typename _Alloc>
3891 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3892 inline basic_string<_CharT, _Traits, _Alloc>
3893 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3894 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3895 {
3896 typedef basic_string<_CharT, _Traits, _Alloc> _Str;
3897 return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(),
3898 __rhs.c_str(), __rhs.size(),
3899 __lhs.get_allocator());
3900 }
3901
3902 /**
3903 * @brief Concatenate C string and string.
3904 * @param __lhs First string.
3905 * @param __rhs Last string.
3906 * @return New string with value of @a __lhs followed by @a __rhs.
3907 */
3908 template<typename _CharT, typename _Traits, typename _Alloc>
3909 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3910 inline basic_string<_CharT,_Traits,_Alloc>
3911 operator+(const _CharT* __lhs,
3912 const basic_string<_CharT,_Traits,_Alloc>& __rhs)
3913 {
3914 __glibcxx_requires_string(__lhs);
3915 typedef basic_string<_CharT, _Traits, _Alloc> _Str;
3916 return std::__str_concat<_Str>(__lhs, _Traits::length(__lhs),
3917 __rhs.c_str(), __rhs.size(),
3918 __rhs.get_allocator());
3919 }
3920
3921 /**
3922 * @brief Concatenate character and string.
3923 * @param __lhs First string.
3924 * @param __rhs Last string.
3925 * @return New string with @a __lhs followed by @a __rhs.
3926 */
3927 template<typename _CharT, typename _Traits, typename _Alloc>
3928 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3929 inline basic_string<_CharT,_Traits,_Alloc>
3930 operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs)
3931 {
3932 typedef basic_string<_CharT, _Traits, _Alloc> _Str;
3933 return std::__str_concat<_Str>(__builtin_addressof(__lhs), 1,
3934 __rhs.c_str(), __rhs.size(),
3935 __rhs.get_allocator());
3936 }
3937
3938 /**
3939 * @brief Concatenate string and C string.
3940 * @param __lhs First string.
3941 * @param __rhs Last string.
3942 * @return New string with @a __lhs followed by @a __rhs.
3943 */
3944 template<typename _CharT, typename _Traits, typename _Alloc>
3945 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3946 inline basic_string<_CharT, _Traits, _Alloc>
3947 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3948 const _CharT* __rhs)
3949 {
3950 __glibcxx_requires_string(__rhs);
3951 typedef basic_string<_CharT, _Traits, _Alloc> _Str;
3952 return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(),
3953 __rhs, _Traits::length(__rhs),
3954 __lhs.get_allocator());
3955 }
3956 /**
3957 * @brief Concatenate string and character.
3958 * @param __lhs First string.
3959 * @param __rhs Last string.
3960 * @return New string with @a __lhs followed by @a __rhs.
3961 */
3962 template<typename _CharT, typename _Traits, typename _Alloc>
3963 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3964 inline basic_string<_CharT, _Traits, _Alloc>
3965 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
3966 {
3967 typedef basic_string<_CharT, _Traits, _Alloc> _Str;
3968 return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(),
3969 __builtin_addressof(__rhs), 1,
3970 __lhs.get_allocator());
3971 }
3972
3973#if __cplusplus201703L >= 201103L
3974 template<typename _CharT, typename _Traits, typename _Alloc>
3975 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3976 inline basic_string<_CharT, _Traits, _Alloc>
3977 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3978 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
3979 { return std::move(__lhs.append(__rhs)); }
3980
3981 template<typename _CharT, typename _Traits, typename _Alloc>
3982 _GLIBCXX20_CONSTEXPR
3983 inline basic_string<_CharT, _Traits, _Alloc>
3984 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
3985 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3986 { return std::move(__rhs.insert(0, __lhs)); }
3987
3988 template<typename _CharT, typename _Traits, typename _Alloc>
3989 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
3990 inline basic_string<_CharT, _Traits, _Alloc>
3991 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
3992 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
3993 {
3994#pragma GCC diagnostic push
3995#pragma GCC diagnostic ignored "-Wc++17-extensions" // if constexpr
3996 // Return value must use __lhs.get_allocator(), but if __rhs has equal
3997 // allocator then we can choose which parameter to modify in-place.
3998 bool __use_rhs = false;
3999 if constexpr (allocator_traits<_Alloc>::is_always_equal::value)
4000 __use_rhs = true;
4001 else if (__lhs.get_allocator() == __rhs.get_allocator())
4002 __use_rhs = true;
4003 if (__use_rhs)
4004 {
4005 const auto __size = __lhs.size() + __rhs.size();
4006 if (__size > __lhs.capacity() && __size <= __rhs.capacity())
4007 return std::move(__rhs.insert(0, __lhs));
4008 }
4009 return std::move(__lhs.append(__rhs));
4010#pragma GCC diagnostic pop
4011 }
4012
4013 template<typename _CharT, typename _Traits, typename _Alloc>
4014 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
4015 inline basic_string<_CharT, _Traits, _Alloc>
4016 operator+(const _CharT* __lhs,
4017 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
4018 { return std::move(__rhs.insert(0, __lhs)); }
4019
4020 template<typename _CharT, typename _Traits, typename _Alloc>
4021 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
4022 inline basic_string<_CharT, _Traits, _Alloc>
4023 operator+(_CharT __lhs,
4024 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
4025 { return std::move(__rhs.insert(0, 1, __lhs)); }
4026
4027 template<typename _CharT, typename _Traits, typename _Alloc>
4028 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
4029 inline basic_string<_CharT, _Traits, _Alloc>
4030 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
4031 const _CharT* __rhs)
4032 { return std::move(__lhs.append(__rhs)); }
4033
4034 template<typename _CharT, typename _Traits, typename _Alloc>
4035 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
4036 inline basic_string<_CharT, _Traits, _Alloc>
4037 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
4038 _CharT __rhs)
4039 { return std::move(__lhs.append(1, __rhs)); }
4040#endif
4041
4042#if __glibcxx_string_view201803L >= 202403L
4043 // const string & + string_view
4044 template<typename _CharT, typename _Traits, typename _Alloc>
4045 [[nodiscard]]
4046 constexpr basic_string<_CharT, _Traits, _Alloc>
4047 operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4048 type_identity_t<basic_string_view<_CharT, _Traits>> __rhs)
4049 {
4050 using _Str = basic_string<_CharT, _Traits, _Alloc>;
4051 return std::__str_concat<_Str>(__lhs.data(), __lhs.size(),
4052 __rhs.data(), __rhs.size(),
4053 __lhs.get_allocator());
4054 }
4055
4056 // string && + string_view
4057 template<typename _CharT, typename _Traits, typename _Alloc>
4058 [[nodiscard]]
4059 constexpr basic_string<_CharT, _Traits, _Alloc>
4060 operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
4061 type_identity_t<basic_string_view<_CharT, _Traits>> __rhs)
4062 {
4063 return std::move(__lhs.append(__rhs));
4064 }
4065
4066 // string_view + const string &
4067 template<typename _CharT, typename _Traits, typename _Alloc>
4068 [[nodiscard]]
4069 constexpr basic_string<_CharT, _Traits, _Alloc>
4070 operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs,
4071 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4072 {
4073 using _Str = basic_string<_CharT, _Traits, _Alloc>;
4074 return std::__str_concat<_Str>(__lhs.data(), __lhs.size(),
4075 __rhs.data(), __rhs.size(),
4076 __rhs.get_allocator());
4077 }
4078
4079 // string_view + string &&
4080 template<typename _CharT, typename _Traits, typename _Alloc>
4081 [[nodiscard]]
4082 constexpr basic_string<_CharT, _Traits, _Alloc>
4083 operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs,
4084 basic_string<_CharT, _Traits, _Alloc>&& __rhs)
4085 {
4086 return std::move(__rhs.insert(0, __lhs));
4087 }
4088#endif
4089
4090 // operator ==
4091 /**
4092 * @brief Test equivalence of two strings.
4093 * @param __lhs First string.
4094 * @param __rhs Second string.
4095 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
4096 */
4097 template<typename _CharT, typename _Traits, typename _Alloc>
4098 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
4099 inline bool
4100 operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4101 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4102 _GLIBCXX_NOEXCEPTnoexcept
4103 {
4104 return __lhs.size() == __rhs.size()
4105 && !_Traits::compare(__lhs.data(), __rhs.data(), __lhs.size());
4106 }
4107
4108 /**
4109 * @brief Test equivalence of string and C string.
4110 * @param __lhs String.
4111 * @param __rhs C string.
4112 * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
4113 */
4114 template<typename _CharT, typename _Traits, typename _Alloc>
4115 _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR
4116 inline bool
4117 operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4118 const _CharT* __rhs)
4119 {
4120 return __lhs.size() == _Traits::length(__rhs)
4121 && !_Traits::compare(__lhs.data(), __rhs, __lhs.size());
4122 }
4123
4124#if __cpp_lib_three_way_comparison
4125 /**
4126 * @brief Three-way comparison of a string and a C string.
4127 * @param __lhs A string.
4128 * @param __rhs A null-terminated string.
4129 * @return A value indicating whether `__lhs` is less than, equal to,
4130 * greater than, or incomparable with `__rhs`.
4131 */
4132 template<typename _CharT, typename _Traits, typename _Alloc>
4133 [[nodiscard]]
4134 constexpr auto
4135 operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4136 const basic_string<_CharT, _Traits, _Alloc>& __rhs) noexcept
4137 -> decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
4138 { return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); }
4139
4140 /**
4141 * @brief Three-way comparison of a string and a C string.
4142 * @param __lhs A string.
4143 * @param __rhs A null-terminated string.
4144 * @return A value indicating whether `__lhs` is less than, equal to,
4145 * greater than, or incomparable with `__rhs`.
4146 */
4147 template<typename _CharT, typename _Traits, typename _Alloc>
4148 [[nodiscard]]
4149 constexpr auto
4150 operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4151 const _CharT* __rhs) noexcept
4152 -> decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
4153 { return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); }
4154#else
4155 /**
4156 * @brief Test equivalence of C string and string.
4157 * @param __lhs C string.
4158 * @param __rhs String.
4159 * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise.
4160 */
4161 template<typename _CharT, typename _Traits, typename _Alloc>
4162 _GLIBCXX_NODISCARD[[__nodiscard__]]
4163 inline bool
4164 operator==(const _CharT* __lhs,
4165 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4166 { return __rhs == __lhs; }
4167
4168 // operator !=
4169 /**
4170 * @brief Test difference of two strings.
4171 * @param __lhs First string.
4172 * @param __rhs Second string.
4173 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
4174 */
4175 template<typename _CharT, typename _Traits, typename _Alloc>
4176 _GLIBCXX_NODISCARD[[__nodiscard__]]
4177 inline bool
4178 operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4179 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4180 _GLIBCXX_NOEXCEPTnoexcept
4181 { return !(__lhs == __rhs); }
4182
4183 /**
4184 * @brief Test difference of C string and string.
4185 * @param __lhs C string.
4186 * @param __rhs String.
4187 * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise.
4188 */
4189 template<typename _CharT, typename _Traits, typename _Alloc>
4190 _GLIBCXX_NODISCARD[[__nodiscard__]]
4191 inline bool
4192 operator!=(const _CharT* __lhs,
4193 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4194 { return !(__rhs == __lhs); }
4195
4196 /**
4197 * @brief Test difference of string and C string.
4198 * @param __lhs String.
4199 * @param __rhs C string.
4200 * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise.
4201 */
4202 template<typename _CharT, typename _Traits, typename _Alloc>
4203 _GLIBCXX_NODISCARD[[__nodiscard__]]
4204 inline bool
4205 operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4206 const _CharT* __rhs)
4207 { return !(__lhs == __rhs); }
4208
4209 // operator <
4210 /**
4211 * @brief Test if string precedes string.
4212 * @param __lhs First string.
4213 * @param __rhs Second string.
4214 * @return True if @a __lhs precedes @a __rhs. False otherwise.
4215 */
4216 template<typename _CharT, typename _Traits, typename _Alloc>
4217 _GLIBCXX_NODISCARD[[__nodiscard__]]
4218 inline bool
4219 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4220 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4221 _GLIBCXX_NOEXCEPTnoexcept
4222 { return __lhs.compare(__rhs) < 0; }
4223
4224 /**
4225 * @brief Test if string precedes C string.
4226 * @param __lhs String.
4227 * @param __rhs C string.
4228 * @return True if @a __lhs precedes @a __rhs. False otherwise.
4229 */
4230 template<typename _CharT, typename _Traits, typename _Alloc>
4231 _GLIBCXX_NODISCARD[[__nodiscard__]]
4232 inline bool
4233 operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4234 const _CharT* __rhs)
4235 { return __lhs.compare(__rhs) < 0; }
4236
4237 /**
4238 * @brief Test if C string precedes string.
4239 * @param __lhs C string.
4240 * @param __rhs String.
4241 * @return True if @a __lhs precedes @a __rhs. False otherwise.
4242 */
4243 template<typename _CharT, typename _Traits, typename _Alloc>
4244 _GLIBCXX_NODISCARD[[__nodiscard__]]
4245 inline bool
4246 operator<(const _CharT* __lhs,
4247 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4248 { return __rhs.compare(__lhs) > 0; }
4249
4250 // operator >
4251 /**
4252 * @brief Test if string follows string.
4253 * @param __lhs First string.
4254 * @param __rhs Second string.
4255 * @return True if @a __lhs follows @a __rhs. False otherwise.
4256 */
4257 template<typename _CharT, typename _Traits, typename _Alloc>
4258 _GLIBCXX_NODISCARD[[__nodiscard__]]
4259 inline bool
4260 operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4261 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4262 _GLIBCXX_NOEXCEPTnoexcept
4263 { return __lhs.compare(__rhs) > 0; }
4264
4265 /**
4266 * @brief Test if string follows C string.
4267 * @param __lhs String.
4268 * @param __rhs C string.
4269 * @return True if @a __lhs follows @a __rhs. False otherwise.
4270 */
4271 template<typename _CharT, typename _Traits, typename _Alloc>
4272 _GLIBCXX_NODISCARD[[__nodiscard__]]
4273 inline bool
4274 operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4275 const _CharT* __rhs)
4276 { return __lhs.compare(__rhs) > 0; }
4277
4278 /**
4279 * @brief Test if C string follows string.
4280 * @param __lhs C string.
4281 * @param __rhs String.
4282 * @return True if @a __lhs follows @a __rhs. False otherwise.
4283 */
4284 template<typename _CharT, typename _Traits, typename _Alloc>
4285 _GLIBCXX_NODISCARD[[__nodiscard__]]
4286 inline bool
4287 operator>(const _CharT* __lhs,
4288 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4289 { return __rhs.compare(__lhs) < 0; }
4290
4291 // operator <=
4292 /**
4293 * @brief Test if string doesn't follow string.
4294 * @param __lhs First string.
4295 * @param __rhs Second string.
4296 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
4297 */
4298 template<typename _CharT, typename _Traits, typename _Alloc>
4299 _GLIBCXX_NODISCARD[[__nodiscard__]]
4300 inline bool
4301 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4302 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4303 _GLIBCXX_NOEXCEPTnoexcept
4304 { return __lhs.compare(__rhs) <= 0; }
4305
4306 /**
4307 * @brief Test if string doesn't follow C string.
4308 * @param __lhs String.
4309 * @param __rhs C string.
4310 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
4311 */
4312 template<typename _CharT, typename _Traits, typename _Alloc>
4313 _GLIBCXX_NODISCARD[[__nodiscard__]]
4314 inline bool
4315 operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4316 const _CharT* __rhs)
4317 { return __lhs.compare(__rhs) <= 0; }
4318
4319 /**
4320 * @brief Test if C string doesn't follow string.
4321 * @param __lhs C string.
4322 * @param __rhs String.
4323 * @return True if @a __lhs doesn't follow @a __rhs. False otherwise.
4324 */
4325 template<typename _CharT, typename _Traits, typename _Alloc>
4326 _GLIBCXX_NODISCARD[[__nodiscard__]]
4327 inline bool
4328 operator<=(const _CharT* __lhs,
4329 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4330 { return __rhs.compare(__lhs) >= 0; }
4331
4332 // operator >=
4333 /**
4334 * @brief Test if string doesn't precede string.
4335 * @param __lhs First string.
4336 * @param __rhs Second string.
4337 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
4338 */
4339 template<typename _CharT, typename _Traits, typename _Alloc>
4340 _GLIBCXX_NODISCARD[[__nodiscard__]]
4341 inline bool
4342 operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4343 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4344 _GLIBCXX_NOEXCEPTnoexcept
4345 { return __lhs.compare(__rhs) >= 0; }
4346
4347 /**
4348 * @brief Test if string doesn't precede C string.
4349 * @param __lhs String.
4350 * @param __rhs C string.
4351 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
4352 */
4353 template<typename _CharT, typename _Traits, typename _Alloc>
4354 _GLIBCXX_NODISCARD[[__nodiscard__]]
4355 inline bool
4356 operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
4357 const _CharT* __rhs)
4358 { return __lhs.compare(__rhs) >= 0; }
4359
4360 /**
4361 * @brief Test if C string doesn't precede string.
4362 * @param __lhs C string.
4363 * @param __rhs String.
4364 * @return True if @a __lhs doesn't precede @a __rhs. False otherwise.
4365 */
4366 template<typename _CharT, typename _Traits, typename _Alloc>
4367 _GLIBCXX_NODISCARD[[__nodiscard__]]
4368 inline bool
4369 operator>=(const _CharT* __lhs,
4370 const basic_string<_CharT, _Traits, _Alloc>& __rhs)
4371 { return __rhs.compare(__lhs) <= 0; }
4372#endif // three-way comparison
4373
4374 /**
4375 * @brief Swap contents of two strings.
4376 * @param __lhs First string.
4377 * @param __rhs Second string.
4378 *
4379 * Exchanges the contents of @a __lhs and @a __rhs in constant time.
4380 */
4381 template<typename _CharT, typename _Traits, typename _Alloc>
4382 _GLIBCXX20_CONSTEXPR
4383 inline void
4384 swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
4385 basic_string<_CharT, _Traits, _Alloc>& __rhs)
4386 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))noexcept(noexcept(__lhs.swap(__rhs)))
4387 { __lhs.swap(__rhs); }
4388
4389
4390 /**
4391 * @brief Read stream into a string.
4392 * @param __is Input stream.
4393 * @param __str Buffer to store into.
4394 * @return Reference to the input stream.
4395 *
4396 * Stores characters from @a __is into @a __str until whitespace is
4397 * found, the end of the stream is encountered, or str.max_size()
4398 * is reached. If is.width() is non-zero, that is the limit on the
4399 * number of characters stored into @a __str. Any previous
4400 * contents of @a __str are erased.
4401 */
4402 template<typename _CharT, typename _Traits, typename _Alloc>
4403 basic_istream<_CharT, _Traits>&
4404 operator>>(basic_istream<_CharT, _Traits>& __is,
4405 basic_string<_CharT, _Traits, _Alloc>& __str);
4406
4407 template<>
4408 basic_istream<char>&
4409 operator>>(basic_istream<char>& __is, basic_string<char>& __str);
4410
4411 /**
4412 * @brief Write string to a stream.
4413 * @param __os Output stream.
4414 * @param __str String to write out.
4415 * @return Reference to the output stream.
4416 *
4417 * Output characters of @a __str into os following the same rules as for
4418 * writing a C string.
4419 */
4420 template<typename _CharT, typename _Traits, typename _Alloc>
4421 inline basic_ostream<_CharT, _Traits>&
4422 operator<<(basic_ostream<_CharT, _Traits>& __os,
4423 const basic_string<_CharT, _Traits, _Alloc>& __str)
4424 {
4425 // _GLIBCXX_RESOLVE_LIB_DEFECTS
4426 // 586. string inserter not a formatted function
4427 return __ostream_insert(__os, __str.data(), __str.size());
4428 }
4429
4430 /**
4431 * @brief Read a line from stream into a string.
4432 * @param __is Input stream.
4433 * @param __str Buffer to store into.
4434 * @param __delim Character marking end of line.
4435 * @return Reference to the input stream.
4436 *
4437 * Stores characters from @a __is into @a __str until @a __delim is
4438 * found, the end of the stream is encountered, or str.max_size()
4439 * is reached. Any previous contents of @a __str are erased. If
4440 * @a __delim is encountered, it is extracted but not stored into
4441 * @a __str.
4442 */
4443 template<typename _CharT, typename _Traits, typename _Alloc>
4444 basic_istream<_CharT, _Traits>&
4445 getline(basic_istream<_CharT, _Traits>& __is,
4446 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim);
4447
4448 /**
4449 * @brief Read a line from stream into a string.
4450 * @param __is Input stream.
4451 * @param __str Buffer to store into.
4452 * @return Reference to the input stream.
4453 *
4454 * Stores characters from is into @a __str until &apos;\n&apos; is
4455 * found, the end of the stream is encountered, or str.max_size()
4456 * is reached. Any previous contents of @a __str are erased. If
4457 * end of line is encountered, it is extracted but not stored into
4458 * @a __str.
4459 */
4460 template<typename _CharT, typename _Traits, typename _Alloc>
4461 inline basic_istream<_CharT, _Traits>&
4462 getline(basic_istream<_CharT, _Traits>& __is,
4463 basic_string<_CharT, _Traits, _Alloc>& __str)
4464 { return std::getline(__is, __str, __is.widen('\n')); }
4465
4466#if __cplusplus201703L >= 201103L
4467 /// Read a line from an rvalue stream into a string.
4468 template<typename _CharT, typename _Traits, typename _Alloc>
4469 inline basic_istream<_CharT, _Traits>&
4470 getline(basic_istream<_CharT, _Traits>&& __is,
4471 basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim)
4472 { return std::getline(__is, __str, __delim); }
4473
4474 /// Read a line from an rvalue stream into a string.
4475 template<typename _CharT, typename _Traits, typename _Alloc>
4476 inline basic_istream<_CharT, _Traits>&
4477 getline(basic_istream<_CharT, _Traits>&& __is,
4478 basic_string<_CharT, _Traits, _Alloc>& __str)
4479 { return std::getline(__is, __str); }
4480#endif
4481
4482 template<>
4483 basic_istream<char>&
4484 getline(basic_istream<char>& __in, basic_string<char>& __str,
4485 char __delim);
4486
4487#ifdef _GLIBCXX_USE_WCHAR_T1
4488 template<>
4489 basic_istream<wchar_t>&
4490 getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str,
4491 wchar_t __delim);
4492#endif
4493
4494_GLIBCXX_END_NAMESPACE_VERSION
4495} // namespace
4496
4497#if __cplusplus201703L >= 201103L
4498
4499#include <ext/string_conversions.h>
4500#include <bits/charconv.h>
4501
4502namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default")))
4503{
4504_GLIBCXX_BEGIN_NAMESPACE_VERSION
4505_GLIBCXX_BEGIN_NAMESPACE_CXX11namespace __cxx11 {
4506
4507 // 21.4 Numeric Conversions [string.conversions].
4508 inline int
4509 stoi(const string& __str, size_t* __idx = 0, int __base = 10)
4510 { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(),
4511 __idx, __base); }
4512
4513 inline long
4514 stol(const string& __str, size_t* __idx = 0, int __base = 10)
4515 { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(),
4516 __idx, __base); }
4517
4518 inline unsigned long
4519 stoul(const string& __str, size_t* __idx = 0, int __base = 10)
4520 { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(),
4521 __idx, __base); }
4522
4523#if _GLIBCXX_USE_C99_STDLIB1
4524 inline long long
4525 stoll(const string& __str, size_t* __idx = 0, int __base = 10)
4526 { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(),
4527 __idx, __base); }
4528
4529 inline unsigned long long
4530 stoull(const string& __str, size_t* __idx = 0, int __base = 10)
4531 { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(),
4532 __idx, __base); }
4533#elif __LONG_WIDTH__64 == __LONG_LONG_WIDTH__
4534 inline long long
4535 stoll(const string& __str, size_t* __idx = 0, int __base = 10)
4536 { return std::stol(__str, __idx, __base); }
4537
4538 inline unsigned long long
4539 stoull(const string& __str, size_t* __idx = 0, int __base = 10)
4540 { return std::stoul(__str, __idx, __base); }
4541#endif
4542
4543 inline double
4544 stod(const string& __str, size_t* __idx = 0)
4545 { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); }
4546
4547#if _GLIBCXX_HAVE_STRTOF1
4548 // NB: strtof vs strtod.
4549 inline float
4550 stof(const string& __str, size_t* __idx = 0)
4551 { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); }
4552#else
4553 inline float
4554 stof(const string& __str, size_t* __idx = 0)
4555 {
4556 double __d = std::stod(__str, __idx);
4557 if (__builtin_isfinite(__d) && __d != 0.0)
4558 {
4559 double __abs_d = __builtin_fabs(__d);
4560 if (__abs_d < __FLT_MIN__1.17549435e-38F || __abs_d > __FLT_MAX__3.40282347e+38F)
4561 {
4562 errno(*__errno_location ()) = ERANGE34;
4563 std::__throw_out_of_range("stof");
4564 }
4565 }
4566 return __d;
4567 }
4568#endif
4569
4570#if _GLIBCXX_HAVE_STRTOLD1 && ! _GLIBCXX_HAVE_BROKEN_STRTOLD
4571 inline long double
4572 stold(const string& __str, size_t* __idx = 0)
4573 { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); }
4574#elif __DBL_MANT_DIG__53 == __LDBL_MANT_DIG__64
4575 inline long double
4576 stold(const string& __str, size_t* __idx = 0)
4577 { return std::stod(__str, __idx); }
4578#endif
4579
4580 // _GLIBCXX_RESOLVE_LIB_DEFECTS
4581 // DR 1261. Insufficent overloads for to_string / to_wstring
4582
4583 _GLIBCXX_NODISCARD[[__nodiscard__]]
4584 inline string
4585 to_string(int __val)
4586#if _GLIBCXX_USE_CXX11_ABI1 && (__CHAR_BIT__8 * __SIZEOF_INT__4) <= 32
4587 noexcept // any 32-bit value fits in the SSO buffer
4588#endif
4589 {
4590 const bool __neg = __val < 0;
4591 const unsigned __uval = __neg ? (unsigned)~__val + 1u : __val;
4592 const auto __len = __detail::__to_chars_len(__uval);
4593 string __str;
4594 __str.__resize_and_overwrite(__neg + __len, [=](char* __p, size_t __n) {
4595 __p[0] = '-';
4596 __detail::__to_chars_10_impl(__p + (int)__neg, __len, __uval);
4597 return __n;
4598 });
4599 return __str;
4600 }
4601
4602 _GLIBCXX_NODISCARD[[__nodiscard__]]
4603 inline string
4604 to_string(unsigned __val)
4605#if _GLIBCXX_USE_CXX11_ABI1 && (__CHAR_BIT__8 * __SIZEOF_INT__4) <= 32
4606 noexcept // any 32-bit value fits in the SSO buffer
4607#endif
4608 {
4609 const auto __len = __detail::__to_chars_len(__val);
4610 string __str;
4611 __str.__resize_and_overwrite(__len, [__val](char* __p, size_t __n) {
4612 __detail::__to_chars_10_impl(__p, __n, __val);
4613 return __n;
4614 });
4615 return __str;
4616 }
4617
4618 _GLIBCXX_NODISCARD[[__nodiscard__]]
4619 inline string
4620 to_string(long __val)
4621#if _GLIBCXX_USE_CXX11_ABI1 && (__CHAR_BIT__8 * __SIZEOF_LONG__8) <= 32
4622 noexcept // any 32-bit value fits in the SSO buffer
4623#endif
4624 {
4625 const bool __neg = __val < 0;
4626 const unsigned long __uval = __neg ? (unsigned long)~__val + 1ul : __val;
4627 const auto __len = __detail::__to_chars_len(__uval);
4628 string __str;
4629 __str.__resize_and_overwrite(__neg + __len, [=](char* __p, size_t __n) {
4630 __p[0] = '-';
4631 __detail::__to_chars_10_impl(__p + (int)__neg, __len, __uval);
4632 return __n;
4633 });
4634 return __str;
4635 }
4636
4637 _GLIBCXX_NODISCARD[[__nodiscard__]]
4638 inline string
4639 to_string(unsigned long __val)
4640#if _GLIBCXX_USE_CXX11_ABI1 && (__CHAR_BIT__8 * __SIZEOF_LONG__8) <= 32
4641 noexcept // any 32-bit value fits in the SSO buffer
4642#endif
4643 {
4644 const auto __len = __detail::__to_chars_len(__val);
4645 string __str;
4646 __str.__resize_and_overwrite(__len, [__val](char* __p, size_t __n) {
4647 __detail::__to_chars_10_impl(__p, __n, __val);
4648 return __n;
4649 });
4650 return __str;
4651 }
4652
4653 _GLIBCXX_NODISCARD[[__nodiscard__]]
4654 inline string
4655 to_string(long long __val)
4656 {
4657 const bool __neg = __val < 0;
4658 const unsigned long long __uval
4659 = __neg ? (unsigned long long)~__val + 1ull : __val;
4660 const auto __len = __detail::__to_chars_len(__uval);
4661 string __str;
4662 __str.__resize_and_overwrite(__neg + __len, [=](char* __p, size_t __n) {
4663 __p[0] = '-';
4664 __detail::__to_chars_10_impl(__p + (int)__neg, __len, __uval);
4665 return __n;
4666 });
4667 return __str;
4668 }
4669
4670 _GLIBCXX_NODISCARD[[__nodiscard__]]
4671 inline string
4672 to_string(unsigned long long __val)
4673 {
4674 const auto __len = __detail::__to_chars_len(__val);
4675 string __str;
4676 __str.__resize_and_overwrite(__len, [__val](char* __p, size_t __n) {
4677 __detail::__to_chars_10_impl(__p, __n, __val);
4678 return __n;
4679 });
4680 return __str;
4681 }
4682
4683#if __glibcxx_to_string >= 202306L // C++ >= 26
4684
4685 [[nodiscard]]
4686 inline string
4687 to_string(float __val)
4688 {
4689 string __str;
4690 size_t __len = 15;
4691 do {
4692 __str.resize_and_overwrite(__len,
4693 [__val, &__len] (char* __p, size_t __n) {
4694 auto [__end, __err] = std::to_chars(__p, __p + __n, __val);
4695 if (__err == errc{}) [[likely]]
4696 return __end - __p;
4697 __len *= 2;
4698 return __p - __p;;
4699 });
4700 } while (__str.empty());
4701 return __str;
4702 }
4703
4704 [[nodiscard]]
4705 inline string
4706 to_string(double __val)
4707 {
4708 string __str;
4709 size_t __len = 15;
4710 do {
4711 __str.resize_and_overwrite(__len,
4712 [__val, &__len] (char* __p, size_t __n) {
4713 auto [__end, __err] = std::to_chars(__p, __p + __n, __val);
4714 if (__err == errc{}) [[likely]]
4715 return __end - __p;
4716 __len *= 2;
4717 return __p - __p;;
4718 });
4719 } while (__str.empty());
4720 return __str;
4721 }
4722
4723 [[nodiscard]]
4724 inline string
4725 to_string(long double __val)
4726 {
4727 string __str;
4728 size_t __len = 15;
4729 do {
4730 __str.resize_and_overwrite(__len,
4731 [__val, &__len] (char* __p, size_t __n) {
4732 auto [__end, __err] = std::to_chars(__p, __p + __n, __val);
4733 if (__err == errc{}) [[likely]]
4734 return __end - __p;
4735 __len *= 2;
4736 return __p - __p;;
4737 });
4738 } while (__str.empty());
4739 return __str;
4740 }
4741#elif _GLIBCXX_USE_C99_STDIO1
4742#pragma GCC diagnostic push
4743#pragma GCC diagnostic ignored "-Wsuggest-attribute=format"
4744 // NB: (v)snprintf vs sprintf.
4745
4746 _GLIBCXX_NODISCARD[[__nodiscard__]]
4747 inline string
4748 to_string(float __val)
4749 {
4750 const int __n =
4751 __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20;
4752 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
4753 "%f", __val);
4754 }
4755
4756 _GLIBCXX_NODISCARD[[__nodiscard__]]
4757 inline string
4758 to_string(double __val)
4759 {
4760 const int __n =
4761 __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20;
4762 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
4763 "%f", __val);
4764 }
4765
4766 _GLIBCXX_NODISCARD[[__nodiscard__]]
4767 inline string
4768 to_string(long double __val)
4769 {
4770 const int __n =
4771 __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20;
4772 return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n,
4773 "%Lf", __val);
4774 }
4775#pragma GCC diagnostic pop
4776#endif // _GLIBCXX_USE_C99_STDIO
4777
4778#if defined(_GLIBCXX_USE_WCHAR_T1) && _GLIBCXX_USE_C99_WCHAR1
4779 inline int
4780 stoi(const wstring& __str, size_t* __idx = 0, int __base = 10)
4781 { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(),
4782 __idx, __base); }
4783
4784 inline long
4785 stol(const wstring& __str, size_t* __idx = 0, int __base = 10)
4786 { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(),
4787 __idx, __base); }
4788
4789 inline unsigned long
4790 stoul(const wstring& __str, size_t* __idx = 0, int __base = 10)
4791 { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(),
4792 __idx, __base); }
4793
4794 inline long long
4795 stoll(const wstring& __str, size_t* __idx = 0, int __base = 10)
4796 { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(),
4797 __idx, __base); }
4798
4799 inline unsigned long long
4800 stoull(const wstring& __str, size_t* __idx = 0, int __base = 10)
4801 { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(),
4802 __idx, __base); }
4803
4804 // NB: wcstof vs wcstod.
4805 inline float
4806 stof(const wstring& __str, size_t* __idx = 0)
4807 { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); }
4808
4809 inline double
4810 stod(const wstring& __str, size_t* __idx = 0)
4811 { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); }
4812
4813 inline long double
4814 stold(const wstring& __str, size_t* __idx = 0)
4815 { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); }
4816#endif
4817
4818#ifdef _GLIBCXX_USE_WCHAR_T1
4819#pragma GCC diagnostic push
4820#pragma GCC diagnostic ignored "-Wc++17-extensions"
4821 _GLIBCXX20_CONSTEXPR
4822 inline void
4823 __to_wstring_numeric(const char* __s, int __len, wchar_t* __wout)
4824 {
4825 // This condition is true if exec-charset and wide-exec-charset share the
4826 // same values for the ASCII subset or the EBCDIC invariant character set.
4827 if constexpr (wchar_t('0') == L'0' && wchar_t('-') == L'-'
4828 && wchar_t('.') == L'.' && wchar_t('e') == L'e')
4829 {
4830 for (int __i = 0; __i < __len; ++__i)
4831 __wout[__i] = (wchar_t) __s[__i];
4832 }
4833 else
4834 {
4835 wchar_t __wc[256];
4836 for (int __i = '0'; __i <= '9'; ++__i)
4837 __wc[__i] = L'0' + __i;
4838 __wc['.'] = L'.';
4839 __wc['+'] = L'+';
4840 __wc['-'] = L'-';
4841 __wc['a'] = L'a';
4842 __wc['b'] = L'b';
4843 __wc['c'] = L'c';
4844 __wc['d'] = L'd';
4845 __wc['e'] = L'e';
4846 __wc['f'] = L'f';
4847 __wc['i'] = L'i'; // for "inf"
4848 __wc['n'] = L'n'; // for "nan" and "inf"
4849 __wc['p'] = L'p'; // for hexfloats "0x1p1"
4850 __wc['x'] = L'x';
4851 __wc['A'] = L'A';
4852 __wc['B'] = L'B';
4853 __wc['C'] = L'C';
4854 __wc['D'] = L'D';
4855 __wc['E'] = L'E';
4856 __wc['F'] = L'F';
4857 __wc['I'] = L'I';
4858 __wc['N'] = L'N';
4859 __wc['P'] = L'P';
4860 __wc['X'] = L'X';
4861
4862 for (int __i = 0; __i < __len; ++__i)
4863 __wout[__i] = __wc[(int)__s[__i]];
4864 }
4865 }
4866
4867#if __glibcxx_constexpr_string201611L >= 201907L
4868 constexpr
4869#endif
4870 inline wstring
4871#ifdef __glibcxx_string_view201803L // >= C++17
4872 __to_wstring_numeric(string_view __s)
4873#else
4874 __to_wstring_numeric(const string& __s)
4875#endif
4876 {
4877 if constexpr (wchar_t('0') == L'0' && wchar_t('-') == L'-'
4878 && wchar_t('.') == L'.' && wchar_t('e') == L'e')
4879 return wstring(__s.data(), __s.data() + __s.size());
4880 else
4881 {
4882 wstring __ws;
4883 auto __f = __s.data();
4884 __ws.__resize_and_overwrite(__s.size(),
4885 [__f] (wchar_t* __to, int __n) {
4886 std::__to_wstring_numeric(__f, __n, __to);
4887 return __n;
4888 });
4889 return __ws;
4890 }
4891 }
4892#pragma GCC diagnostic pop
4893
4894 _GLIBCXX_NODISCARD[[__nodiscard__]]
4895 inline wstring
4896 to_wstring(int __val)
4897 { return std::__to_wstring_numeric(std::to_string(__val)); }
4898
4899 _GLIBCXX_NODISCARD[[__nodiscard__]]
4900 inline wstring
4901 to_wstring(unsigned __val)
4902 { return std::__to_wstring_numeric(std::to_string(__val)); }
4903
4904 _GLIBCXX_NODISCARD[[__nodiscard__]]
4905 inline wstring
4906 to_wstring(long __val)
4907 { return std::__to_wstring_numeric(std::to_string(__val)); }
4908
4909 _GLIBCXX_NODISCARD[[__nodiscard__]]
4910 inline wstring
4911 to_wstring(unsigned long __val)
4912 { return std::__to_wstring_numeric(std::to_string(__val)); }
4913
4914 _GLIBCXX_NODISCARD[[__nodiscard__]]
4915 inline wstring
4916 to_wstring(long long __val)
4917 { return std::__to_wstring_numeric(std::to_string(__val)); }
4918
4919 _GLIBCXX_NODISCARD[[__nodiscard__]]
4920 inline wstring
4921 to_wstring(unsigned long long __val)
4922 { return std::__to_wstring_numeric(std::to_string(__val)); }
4923
4924#if __glibcxx_to_string || _GLIBCXX_USE_C99_STDIO1
4925 _GLIBCXX_NODISCARD[[__nodiscard__]]
4926 inline wstring
4927 to_wstring(float __val)
4928 { return std::__to_wstring_numeric(std::to_string(__val)); }
4929
4930 _GLIBCXX_NODISCARD[[__nodiscard__]]
4931 inline wstring
4932 to_wstring(double __val)
4933 { return std::__to_wstring_numeric(std::to_string(__val)); }
4934
4935 _GLIBCXX_NODISCARD[[__nodiscard__]]
4936 inline wstring
4937 to_wstring(long double __val)
4938 { return std::__to_wstring_numeric(std::to_string(__val)); }
4939#endif
4940#endif // _GLIBCXX_USE_WCHAR_T
4941
4942_GLIBCXX_END_NAMESPACE_CXX11}
4943_GLIBCXX_END_NAMESPACE_VERSION
4944} // namespace
4945
4946#endif /* C++11 */
4947
4948#if __cplusplus201703L >= 201103L
4949
4950#include <bits/functional_hash.h>
4951
4952namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default")))
4953{
4954_GLIBCXX_BEGIN_NAMESPACE_VERSION
4955
4956 // _GLIBCXX_RESOLVE_LIB_DEFECTS
4957 // 3705. Hashability shouldn't depend on basic_string's allocator
4958
4959 template<typename _CharT, typename _Alloc,
4960 typename _StrT = basic_string<_CharT, char_traits<_CharT>, _Alloc>>
4961 struct __str_hash_base
4962 : public __hash_base<size_t, _StrT>
4963 {
4964 [[__nodiscard__]]
4965 size_t
4966 operator()(const _StrT& __s) const noexcept
4967 { return _Hash_impl::hash(__s.data(), __s.length() * sizeof(_CharT)); }
4968 };
4969
4970#ifndef _GLIBCXX_COMPATIBILITY_CXX0X
4971 /// std::hash specialization for string.
4972 template<typename _Alloc>
4973 struct hash<basic_string<char, char_traits<char>, _Alloc>>
4974 : public __str_hash_base<char, _Alloc>
4975 { };
4976
4977 /// std::hash specialization for wstring.
4978 template<typename _Alloc>
4979 struct hash<basic_string<wchar_t, char_traits<wchar_t>, _Alloc>>
4980 : public __str_hash_base<wchar_t, _Alloc>
4981 { };
4982
4983 template<typename _Alloc>
4984 struct __is_fast_hash<hash<basic_string<wchar_t, char_traits<wchar_t>,
4985 _Alloc>>>
4986 : std::false_type
4987 { };
4988#endif /* _GLIBCXX_COMPATIBILITY_CXX0X */
4989
4990#ifdef _GLIBCXX_USE_CHAR8_T
4991 /// std::hash specialization for u8string.
4992 template<typename _Alloc>
4993 struct hash<basic_string<char8_t, char_traits<char8_t>, _Alloc>>
4994 : public __str_hash_base<char8_t, _Alloc>
4995 { };
4996#endif
4997
4998 /// std::hash specialization for u16string.
4999 template<typename _Alloc>
5000 struct hash<basic_string<char16_t, char_traits<char16_t>, _Alloc>>
5001 : public __str_hash_base<char16_t, _Alloc>
5002 { };
5003
5004 /// std::hash specialization for u32string.
5005 template<typename _Alloc>
5006 struct hash<basic_string<char32_t, char_traits<char32_t>, _Alloc>>
5007 : public __str_hash_base<char32_t, _Alloc>
5008 { };
5009
5010#if ! _GLIBCXX_INLINE_VERSION0
5011 // PR libstdc++/105907 - __is_fast_hash affects unordered container ABI.
5012 template<> struct __is_fast_hash<hash<string>> : std::false_type { };
5013 template<> struct __is_fast_hash<hash<wstring>> : std::false_type { };
5014 template<> struct __is_fast_hash<hash<u16string>> : std::false_type { };
5015 template<> struct __is_fast_hash<hash<u32string>> : std::false_type { };
5016#ifdef _GLIBCXX_USE_CHAR8_T
5017 template<> struct __is_fast_hash<hash<u8string>> : std::false_type { };
5018#endif
5019#else
5020 // For versioned namespace, assume every std::hash<basic_string<>> is slow.
5021 template<typename _CharT, typename _Traits, typename _Alloc>
5022 struct __is_fast_hash<hash<basic_string<_CharT, _Traits, _Alloc>>>
5023 : std::false_type
5024 { };
5025#endif
5026
5027#ifdef __glibcxx_string_udls201304L // C++ >= 14
5028 inline namespace literals
5029 {
5030 inline namespace string_literals
5031 {
5032#pragma GCC diagnostic push
5033#pragma GCC diagnostic ignored "-Wliteral-suffix"
5034
5035#if __glibcxx_constexpr_string201611L >= 201907L
5036# define _GLIBCXX_STRING_CONSTEXPR constexpr
5037#else
5038# define _GLIBCXX_STRING_CONSTEXPR
5039#endif
5040
5041 _GLIBCXX_DEFAULT_ABI_TAG__attribute ((__abi_tag__ ("cxx11"))) _GLIBCXX_STRING_CONSTEXPR
5042 inline basic_string<char>
5043 operator""s(const char* __str, size_t __len)
5044 { return basic_string<char>{__str, __len}; }
5045
5046 _GLIBCXX_DEFAULT_ABI_TAG__attribute ((__abi_tag__ ("cxx11"))) _GLIBCXX_STRING_CONSTEXPR
5047 inline basic_string<wchar_t>
5048 operator""s(const wchar_t* __str, size_t __len)
5049 { return basic_string<wchar_t>{__str, __len}; }
5050
5051#ifdef _GLIBCXX_USE_CHAR8_T
5052 _GLIBCXX_DEFAULT_ABI_TAG__attribute ((__abi_tag__ ("cxx11"))) _GLIBCXX_STRING_CONSTEXPR
5053 inline basic_string<char8_t>
5054 operator""s(const char8_t* __str, size_t __len)
5055 { return basic_string<char8_t>{__str, __len}; }
5056#endif
5057
5058 _GLIBCXX_DEFAULT_ABI_TAG__attribute ((__abi_tag__ ("cxx11"))) _GLIBCXX_STRING_CONSTEXPR
5059 inline basic_string<char16_t>
5060 operator""s(const char16_t* __str, size_t __len)
5061 { return basic_string<char16_t>{__str, __len}; }
5062
5063 _GLIBCXX_DEFAULT_ABI_TAG__attribute ((__abi_tag__ ("cxx11"))) _GLIBCXX_STRING_CONSTEXPR
5064 inline basic_string<char32_t>
5065 operator""s(const char32_t* __str, size_t __len)
5066 { return basic_string<char32_t>{__str, __len}; }
5067
5068#undef _GLIBCXX_STRING_CONSTEXPR
5069#pragma GCC diagnostic pop
5070 } // inline namespace string_literals
5071 } // inline namespace literals
5072#endif // __glibcxx_string_udls
5073
5074#ifdef __glibcxx_variant202102L // >= C++17
5075 namespace __detail::__variant
5076 {
5077 template<typename> struct _Never_valueless_alt; // see <variant>
5078
5079 // Provide the strong exception-safety guarantee when emplacing a
5080 // basic_string into a variant, but only if moving the string cannot throw.
5081 template<typename _Tp, typename _Traits, typename _Alloc>
5082 struct _Never_valueless_alt<std::basic_string<_Tp, _Traits, _Alloc>>
5083 : __and_<
5084 is_nothrow_move_constructible<std::basic_string<_Tp, _Traits, _Alloc>>,
5085 is_nothrow_move_assignable<std::basic_string<_Tp, _Traits, _Alloc>>
5086 >::type
5087 { };
5088 } // namespace __detail::__variant
5089#endif // C++17
5090
5091_GLIBCXX_END_NAMESPACE_VERSION
5092} // namespace std
5093
5094#endif // C++11
5095
5096#endif /* _BASIC_STRING_H */

/usr/src/googletest/googletest/include/gtest/gtest.h

1// Copyright 2005, Google Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// * Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10// * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14// * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30// The Google C++ Testing and Mocking Framework (Google Test)
31//
32// This header file defines the public API for Google Test. It should be
33// included by any test program that uses Google Test.
34//
35// IMPORTANT NOTE: Due to limitation of the C++ language, we have to
36// leave some internal implementation details in this header file.
37// They are clearly marked by comments like this:
38//
39// // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
40//
41// Such code is NOT meant to be used by a user directly, and is subject
42// to CHANGE WITHOUT NOTICE. Therefore DO NOT DEPEND ON IT in a user
43// program!
44//
45// Acknowledgment: Google Test borrowed the idea of automatic test
46// registration from Barthelemy Dagenais' (barthelemy@prologique.com)
47// easyUnit framework.
48
49#ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_H_
50#define GOOGLETEST_INCLUDE_GTEST_GTEST_H_
51
52#include <cstddef>
53#include <cstdint>
54#include <limits>
55#include <memory>
56#include <ostream>
57#include <set>
58#include <sstream>
59#include <string>
60#include <type_traits>
61#include <vector>
62
63#include "gtest/gtest-assertion-result.h" // IWYU pragma: export
64#include "gtest/gtest-death-test.h" // IWYU pragma: export
65#include "gtest/gtest-matchers.h" // IWYU pragma: export
66#include "gtest/gtest-message.h" // IWYU pragma: export
67#include "gtest/gtest-param-test.h" // IWYU pragma: export
68#include "gtest/gtest-printers.h" // IWYU pragma: export
69#include "gtest/gtest-test-part.h" // IWYU pragma: export
70#include "gtest/gtest-typed-test.h" // IWYU pragma: export
71#include "gtest/gtest_pred_impl.h" // IWYU pragma: export
72#include "gtest/gtest_prod.h" // IWYU pragma: export
73#include "gtest/internal/gtest-internal.h"
74#include "gtest/internal/gtest-string.h"
75
76GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
77/* class A needs to have dll-interface to be used by clients of class B */)
78
79// Declares the flags.
80
81// This flag temporary enables the disabled tests.
82GTEST_DECLARE_bool_(also_run_disabled_tests)namespace testing { __attribute__((visibility("default"))) extern
bool FLAGS_gtest_also_run_disabled_tests; } static_assert(true
, "no-op to require trailing semicolon")
;
83
84// This flag brings the debugger on an assertion failure.
85GTEST_DECLARE_bool_(break_on_failure)namespace testing { __attribute__((visibility("default"))) extern
bool FLAGS_gtest_break_on_failure; } static_assert(true, "no-op to require trailing semicolon"
)
;
86
87// This flag controls whether Google Test catches all test-thrown exceptions
88// and logs them as failures.
89GTEST_DECLARE_bool_(catch_exceptions)namespace testing { __attribute__((visibility("default"))) extern
bool FLAGS_gtest_catch_exceptions; } static_assert(true, "no-op to require trailing semicolon"
)
;
90
91// This flag enables using colors in terminal output. Available values are
92// "yes" to enable colors, "no" (disable colors), or "auto" (the default)
93// to let Google Test decide.
94GTEST_DECLARE_string_(color)namespace testing { __attribute__((visibility("default"))) extern
::std::string FLAGS_gtest_color; } static_assert(true, "no-op to require trailing semicolon"
)
;
95
96// This flag controls whether the test runner should continue execution past
97// first failure.
98GTEST_DECLARE_bool_(fail_fast)namespace testing { __attribute__((visibility("default"))) extern
bool FLAGS_gtest_fail_fast; } static_assert(true, "no-op to require trailing semicolon"
)
;
99
100// This flag sets up the filter to select by name using a glob pattern
101// the tests to run. If the filter is not given all tests are executed.
102GTEST_DECLARE_string_(filter)namespace testing { __attribute__((visibility("default"))) extern
::std::string FLAGS_gtest_filter; } static_assert(true, "no-op to require trailing semicolon"
)
;
103
104// This flag controls whether Google Test installs a signal handler that dumps
105// debugging information when fatal signals are raised.
106GTEST_DECLARE_bool_(install_failure_signal_handler)namespace testing { __attribute__((visibility("default"))) extern
bool FLAGS_gtest_install_failure_signal_handler; } static_assert
(true, "no-op to require trailing semicolon")
;
107
108// This flag causes the Google Test to list tests. None of the tests listed
109// are actually run if the flag is provided.
110GTEST_DECLARE_bool_(list_tests)namespace testing { __attribute__((visibility("default"))) extern
bool FLAGS_gtest_list_tests; } static_assert(true, "no-op to require trailing semicolon"
)
;
111
112// This flag controls whether Google Test emits a detailed XML report to a file
113// in addition to its normal textual output.
114GTEST_DECLARE_string_(output)namespace testing { __attribute__((visibility("default"))) extern
::std::string FLAGS_gtest_output; } static_assert(true, "no-op to require trailing semicolon"
)
;
115
116// This flags control whether Google Test prints only test failures.
117GTEST_DECLARE_bool_(brief)namespace testing { __attribute__((visibility("default"))) extern
bool FLAGS_gtest_brief; } static_assert(true, "no-op to require trailing semicolon"
)
;
118
119// This flags control whether Google Test prints the elapsed time for each
120// test.
121GTEST_DECLARE_bool_(print_time)namespace testing { __attribute__((visibility("default"))) extern
bool FLAGS_gtest_print_time; } static_assert(true, "no-op to require trailing semicolon"
)
;
122
123// This flags control whether Google Test prints UTF8 characters as text.
124GTEST_DECLARE_bool_(print_utf8)namespace testing { __attribute__((visibility("default"))) extern
bool FLAGS_gtest_print_utf8; } static_assert(true, "no-op to require trailing semicolon"
)
;
125
126// This flag specifies the random number seed.
127GTEST_DECLARE_int32_(random_seed)namespace testing { __attribute__((visibility("default"))) extern
std::int32_t FLAGS_gtest_random_seed; } static_assert(true, "no-op to require trailing semicolon"
)
;
128
129// This flag sets how many times the tests are repeated. The default value
130// is 1. If the value is -1 the tests are repeating forever.
131GTEST_DECLARE_int32_(repeat)namespace testing { __attribute__((visibility("default"))) extern
std::int32_t FLAGS_gtest_repeat; } static_assert(true, "no-op to require trailing semicolon"
)
;
132
133// This flag controls whether Google Test Environments are recreated for each
134// repeat of the tests. The default value is true. If set to false the global
135// test Environment objects are only set up once, for the first iteration, and
136// only torn down once, for the last.
137GTEST_DECLARE_bool_(recreate_environments_when_repeating)namespace testing { __attribute__((visibility("default"))) extern
bool FLAGS_gtest_recreate_environments_when_repeating; } static_assert
(true, "no-op to require trailing semicolon")
;
138
139// This flag controls whether Google Test includes Google Test internal
140// stack frames in failure stack traces.
141GTEST_DECLARE_bool_(show_internal_stack_frames)namespace testing { __attribute__((visibility("default"))) extern
bool FLAGS_gtest_show_internal_stack_frames; } static_assert
(true, "no-op to require trailing semicolon")
;
142
143// When this flag is specified, tests' order is randomized on every iteration.
144GTEST_DECLARE_bool_(shuffle)namespace testing { __attribute__((visibility("default"))) extern
bool FLAGS_gtest_shuffle; } static_assert(true, "no-op to require trailing semicolon"
)
;
145
146// This flag specifies the maximum number of stack frames to be
147// printed in a failure message.
148GTEST_DECLARE_int32_(stack_trace_depth)namespace testing { __attribute__((visibility("default"))) extern
std::int32_t FLAGS_gtest_stack_trace_depth; } static_assert(
true, "no-op to require trailing semicolon")
;
149
150// When this flag is specified, a failed assertion will throw an
151// exception if exceptions are enabled, or exit the program with a
152// non-zero code otherwise. For use with an external test framework.
153GTEST_DECLARE_bool_(throw_on_failure)namespace testing { __attribute__((visibility("default"))) extern
bool FLAGS_gtest_throw_on_failure; } static_assert(true, "no-op to require trailing semicolon"
)
;
154
155// When this flag is set with a "host:port" string, on supported
156// platforms test results are streamed to the specified port on
157// the specified host machine.
158GTEST_DECLARE_string_(stream_result_to)namespace testing { __attribute__((visibility("default"))) extern
::std::string FLAGS_gtest_stream_result_to; } static_assert(
true, "no-op to require trailing semicolon")
;
159
160#if GTEST_USE_OWN_FLAGFILE_FLAG_1
161GTEST_DECLARE_string_(flagfile)namespace testing { __attribute__((visibility("default"))) extern
::std::string FLAGS_gtest_flagfile; } static_assert(true, "no-op to require trailing semicolon"
)
;
162#endif // GTEST_USE_OWN_FLAGFILE_FLAG_
163
164namespace testing {
165
166// Silence C4100 (unreferenced formal parameter) and 4805
167// unsafe mix of type 'const int' and type 'const bool'
168GTEST_DISABLE_MSC_WARNINGS_PUSH_(4805 4100)
169
170// The upper limit for valid stack trace depths.
171const int kMaxStackTraceDepth = 100;
172
173namespace internal {
174
175class AssertHelper;
176class DefaultGlobalTestPartResultReporter;
177class ExecDeathTest;
178class NoExecDeathTest;
179class FinalSuccessChecker;
180class GTestFlagSaver;
181class StreamingListenerTest;
182class TestResultAccessor;
183class TestEventListenersAccessor;
184class TestEventRepeater;
185class UnitTestRecordPropertyTestHelper;
186class WindowsDeathTest;
187class FuchsiaDeathTest;
188class UnitTestImpl* GetUnitTestImpl();
189void ReportFailureInUnknownLocation(TestPartResult::Type result_type,
190 const std::string& message);
191std::set<std::string>* GetIgnoredParameterizedTestSuites();
192
193// A base class that prevents subclasses from being copyable.
194// We do this instead of using '= delete' so as to avoid triggering warnings
195// inside user code regarding any of our declarations.
196class GTestNonCopyable {
197 public:
198 GTestNonCopyable() = default;
199 GTestNonCopyable(const GTestNonCopyable&) = delete;
200 GTestNonCopyable& operator=(const GTestNonCopyable&) = delete;
201 ~GTestNonCopyable() = default;
202};
203
204} // namespace internal
205
206// The friend relationship of some of these classes is cyclic.
207// If we don't forward declare them the compiler might confuse the classes
208// in friendship clauses with same named classes on the scope.
209class Test;
210class TestSuite;
211
212// Old API is still available but deprecated
213#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
214using TestCase = TestSuite;
215#endif
216class TestInfo;
217class UnitTest;
218
219// The abstract class that all tests inherit from.
220//
221// In Google Test, a unit test program contains one or many TestSuites, and
222// each TestSuite contains one or many Tests.
223//
224// When you define a test using the TEST macro, you don't need to
225// explicitly derive from Test - the TEST macro automatically does
226// this for you.
227//
228// The only time you derive from Test is when defining a test fixture
229// to be used in a TEST_F. For example:
230//
231// class FooTest : public testing::Test {
232// protected:
233// void SetUp() override { ... }
234// void TearDown() override { ... }
235// ...
236// };
237//
238// TEST_F(FooTest, Bar) { ... }
239// TEST_F(FooTest, Baz) { ... }
240//
241// Test is not copyable.
242class GTEST_API___attribute__((visibility("default"))) Test {
243 public:
244 friend class TestInfo;
245
246 // The d'tor is virtual as we intend to inherit from Test.
247 virtual ~Test();
248
249 // Sets up the stuff shared by all tests in this test suite.
250 //
251 // Google Test will call Foo::SetUpTestSuite() before running the first
252 // test in test suite Foo. Hence a sub-class can define its own
253 // SetUpTestSuite() method to shadow the one defined in the super
254 // class.
255 static void SetUpTestSuite() {}
256
257 // Tears down the stuff shared by all tests in this test suite.
258 //
259 // Google Test will call Foo::TearDownTestSuite() after running the last
260 // test in test suite Foo. Hence a sub-class can define its own
261 // TearDownTestSuite() method to shadow the one defined in the super
262 // class.
263 static void TearDownTestSuite() {}
264
265 // Legacy API is deprecated but still available. Use SetUpTestSuite and
266 // TearDownTestSuite instead.
267#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
268 static void TearDownTestCase() {}
269 static void SetUpTestCase() {}
270#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
271
272 // Returns true if and only if the current test has a fatal failure.
273 static bool HasFatalFailure();
274
275 // Returns true if and only if the current test has a non-fatal failure.
276 static bool HasNonfatalFailure();
277
278 // Returns true if and only if the current test was skipped.
279 static bool IsSkipped();
280
281 // Returns true if and only if the current test has a (either fatal or
282 // non-fatal) failure.
283 static bool HasFailure() { return HasFatalFailure() || HasNonfatalFailure(); }
284
285 // Logs a property for the current test, test suite, or for the entire
286 // invocation of the test program when used outside of the context of a
287 // test suite. Only the last value for a given key is remembered. These
288 // are public static so they can be called from utility functions that are
289 // not members of the test fixture. Calls to RecordProperty made during
290 // lifespan of the test (from the moment its constructor starts to the
291 // moment its destructor finishes) will be output in XML as attributes of
292 // the <testcase> element. Properties recorded from fixture's
293 // SetUpTestSuite or TearDownTestSuite are logged as attributes of the
294 // corresponding <testsuite> element. Calls to RecordProperty made in the
295 // global context (before or after invocation of RUN_ALL_TESTS and from
296 // SetUp/TearDown method of Environment objects registered with Google
297 // Test) will be output as attributes of the <testsuites> element.
298 static void RecordProperty(const std::string& key, const std::string& value);
299 // We do not define a custom serialization except for values that can be
300 // converted to int64_t, but other values could be logged in this way.
301 template <typename T, std::enable_if_t<std::is_convertible<T, int64_t>::value,
302 bool> = true>
303 static void RecordProperty(const std::string& key, const T& value) {
304 RecordProperty(key, (Message() << value).GetString());
305 }
306
307 protected:
308 // Creates a Test object.
309 Test();
310
311 // Sets up the test fixture.
312 virtual void SetUp();
313
314 // Tears down the test fixture.
315 virtual void TearDown();
316
317 private:
318 // Returns true if and only if the current test has the same fixture class
319 // as the first test in the current test suite.
320 static bool HasSameFixtureClass();
321
322 // Runs the test after the test fixture has been set up.
323 //
324 // A sub-class must implement this to define the test logic.
325 //
326 // DO NOT OVERRIDE THIS FUNCTION DIRECTLY IN A USER PROGRAM.
327 // Instead, use the TEST or TEST_F macro.
328 virtual void TestBody() = 0;
329
330 // Sets up, executes, and tears down the test.
331 void Run();
332
333 // Deletes self. We deliberately pick an unusual name for this
334 // internal method to avoid clashing with names used in user TESTs.
335 void DeleteSelf_() { delete this; }
336
337 const std::unique_ptr<GTEST_FLAG_SAVER_::testing::internal::GTestFlagSaver> gtest_flag_saver_;
338
339 // Often a user misspells SetUp() as Setup() and spends a long time
340 // wondering why it is never called by Google Test. The declaration of
341 // the following method is solely for catching such an error at
342 // compile time:
343 //
344 // - The return type is deliberately chosen to be not void, so it
345 // will be a conflict if void Setup() is declared in the user's
346 // test fixture.
347 //
348 // - This method is private, so it will be another compiler error
349 // if the method is called from the user's test fixture.
350 //
351 // DO NOT OVERRIDE THIS FUNCTION.
352 //
353 // If you see an error about overriding the following function or
354 // about it being private, you have mis-spelled SetUp() as Setup().
355 struct Setup_should_be_spelled_SetUp {};
356 virtual Setup_should_be_spelled_SetUp* Setup() { return nullptr; }
357
358 // We disallow copying Tests.
359 Test(const Test&) = delete;
360 Test& operator=(const Test&) = delete;
361};
362
363typedef internal::TimeInMillis TimeInMillis;
364
365// A copyable object representing a user specified test property which can be
366// output as a key/value string pair.
367//
368// Don't inherit from TestProperty as its destructor is not virtual.
369class TestProperty {
370 public:
371 // C'tor. TestProperty does NOT have a default constructor.
372 // Always use this constructor (with parameters) to create a
373 // TestProperty object.
374 TestProperty(const std::string& a_key, const std::string& a_value)
375 : key_(a_key), value_(a_value) {}
376
377 // Gets the user supplied key.
378 const char* key() const { return key_.c_str(); }
379
380 // Gets the user supplied value.
381 const char* value() const { return value_.c_str(); }
382
383 // Sets a new value, overriding the one supplied in the constructor.
384 void SetValue(const std::string& new_value) { value_ = new_value; }
385
386 private:
387 // The key supplied by the user.
388 std::string key_;
389 // The value supplied by the user.
390 std::string value_;
391};
392
393// The result of a single Test. This includes a list of
394// TestPartResults, a list of TestProperties, a count of how many
395// death tests there are in the Test, and how much time it took to run
396// the Test.
397//
398// TestResult is not copyable.
399class GTEST_API___attribute__((visibility("default"))) TestResult {
400 public:
401 // Creates an empty TestResult.
402 TestResult();
403
404 // D'tor. Do not inherit from TestResult.
405 ~TestResult();
406
407 // Gets the number of all test parts. This is the sum of the number
408 // of successful test parts and the number of failed test parts.
409 int total_part_count() const;
410
411 // Returns the number of the test properties.
412 int test_property_count() const;
413
414 // Returns true if and only if the test passed (i.e. no test part failed).
415 bool Passed() const { return !Skipped() && !Failed(); }
416
417 // Returns true if and only if the test was skipped.
418 bool Skipped() const;
419
420 // Returns true if and only if the test failed.
421 bool Failed() const;
422
423 // Returns true if and only if the test fatally failed.
424 bool HasFatalFailure() const;
425
426 // Returns true if and only if the test has a non-fatal failure.
427 bool HasNonfatalFailure() const;
428
429 // Returns the elapsed time, in milliseconds.
430 TimeInMillis elapsed_time() const { return elapsed_time_; }
431
432 // Gets the time of the test case start, in ms from the start of the
433 // UNIX epoch.
434 TimeInMillis start_timestamp() const { return start_timestamp_; }
435
436 // Returns the i-th test part result among all the results. i can range from 0
437 // to total_part_count() - 1. If i is not in that range, aborts the program.
438 const TestPartResult& GetTestPartResult(int i) const;
439
440 // Returns the i-th test property. i can range from 0 to
441 // test_property_count() - 1. If i is not in that range, aborts the
442 // program.
443 const TestProperty& GetTestProperty(int i) const;
444
445 private:
446 friend class TestInfo;
447 friend class TestSuite;
448 friend class UnitTest;
449 friend class internal::DefaultGlobalTestPartResultReporter;
450 friend class internal::ExecDeathTest;
451 friend class internal::TestResultAccessor;
452 friend class internal::UnitTestImpl;
453 friend class internal::WindowsDeathTest;
454 friend class internal::FuchsiaDeathTest;
455
456 // Gets the vector of TestPartResults.
457 const std::vector<TestPartResult>& test_part_results() const {
458 return test_part_results_;
459 }
460
461 // Gets the vector of TestProperties.
462 const std::vector<TestProperty>& test_properties() const {
463 return test_properties_;
464 }
465
466 // Sets the start time.
467 void set_start_timestamp(TimeInMillis start) { start_timestamp_ = start; }
468
469 // Sets the elapsed time.
470 void set_elapsed_time(TimeInMillis elapsed) { elapsed_time_ = elapsed; }
471
472 // Adds a test property to the list. The property is validated and may add
473 // a non-fatal failure if invalid (e.g., if it conflicts with reserved
474 // key names). If a property is already recorded for the same key, the
475 // value will be updated, rather than storing multiple values for the same
476 // key. xml_element specifies the element for which the property is being
477 // recorded and is used for validation.
478 void RecordProperty(const std::string& xml_element,
479 const TestProperty& test_property);
480
481 // Adds a failure if the key is a reserved attribute of Google Test
482 // testsuite tags. Returns true if the property is valid.
483 // FIXME: Validate attribute names are legal and human readable.
484 static bool ValidateTestProperty(const std::string& xml_element,
485 const TestProperty& test_property);
486
487 // Adds a test part result to the list.
488 void AddTestPartResult(const TestPartResult& test_part_result);
489
490 // Returns the death test count.
491 int death_test_count() const { return death_test_count_; }
492
493 // Increments the death test count, returning the new count.
494 int increment_death_test_count() { return ++death_test_count_; }
495
496 // Clears the test part results.
497 void ClearTestPartResults();
498
499 // Clears the object.
500 void Clear();
501
502 // Protects mutable state of the property vector and of owned
503 // properties, whose values may be updated.
504 internal::Mutex test_properties_mutex_;
505
506 // The vector of TestPartResults
507 std::vector<TestPartResult> test_part_results_;
508 // The vector of TestProperties
509 std::vector<TestProperty> test_properties_;
510 // Running count of death tests.
511 int death_test_count_;
512 // The start time, in milliseconds since UNIX Epoch.
513 TimeInMillis start_timestamp_;
514 // The elapsed time, in milliseconds.
515 TimeInMillis elapsed_time_;
516
517 // We disallow copying TestResult.
518 TestResult(const TestResult&) = delete;
519 TestResult& operator=(const TestResult&) = delete;
520}; // class TestResult
521
522// A TestInfo object stores the following information about a test:
523//
524// Test suite name
525// Test name
526// Whether the test should be run
527// A function pointer that creates the test object when invoked
528// Test result
529//
530// The constructor of TestInfo registers itself with the UnitTest
531// singleton such that the RUN_ALL_TESTS() macro knows which tests to
532// run.
533class GTEST_API___attribute__((visibility("default"))) TestInfo {
534 public:
535 // Destructs a TestInfo object. This function is not virtual, so
536 // don't inherit from TestInfo.
537 ~TestInfo();
538
539 // Returns the test suite name.
540 const char* test_suite_name() const { return test_suite_name_.c_str(); }
541
542// Legacy API is deprecated but still available
543#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
544 const char* test_case_name() const { return test_suite_name(); }
545#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
546
547 // Returns the test name.
548 const char* name() const { return name_.c_str(); }
549
550 // Returns the name of the parameter type, or NULL if this is not a typed
551 // or a type-parameterized test.
552 const char* type_param() const {
553 if (type_param_ != nullptr) return type_param_->c_str();
554 return nullptr;
555 }
556
557 // Returns the text representation of the value parameter, or NULL if this
558 // is not a value-parameterized test.
559 const char* value_param() const {
560 if (value_param_ != nullptr) return value_param_->c_str();
561 return nullptr;
562 }
563
564 // Returns the file name where this test is defined.
565 const char* file() const { return location_.file.c_str(); }
566
567 // Returns the line where this test is defined.
568 int line() const { return location_.line; }
569
570 // Return true if this test should not be run because it's in another shard.
571 bool is_in_another_shard() const { return is_in_another_shard_; }
572
573 // Returns true if this test should run, that is if the test is not
574 // disabled (or it is disabled but the also_run_disabled_tests flag has
575 // been specified) and its full name matches the user-specified filter.
576 //
577 // Google Test allows the user to filter the tests by their full names.
578 // The full name of a test Bar in test suite Foo is defined as
579 // "Foo.Bar". Only the tests that match the filter will run.
580 //
581 // A filter is a colon-separated list of glob (not regex) patterns,
582 // optionally followed by a '-' and a colon-separated list of
583 // negative patterns (tests to exclude). A test is run if it
584 // matches one of the positive patterns and does not match any of
585 // the negative patterns.
586 //
587 // For example, *A*:Foo.* is a filter that matches any string that
588 // contains the character 'A' or starts with "Foo.".
589 bool should_run() const { return should_run_; }
590
591 // Returns true if and only if this test will appear in the XML report.
592 bool is_reportable() const {
593 // The XML report includes tests matching the filter, excluding those
594 // run in other shards.
595 return matches_filter_ && !is_in_another_shard_;
596 }
597
598 // Returns the result of the test.
599 const TestResult* result() const { return &result_; }
600
601 private:
602#ifdef GTEST_HAS_DEATH_TEST1
603 friend class internal::DefaultDeathTestFactory;
604#endif // GTEST_HAS_DEATH_TEST
605 friend class Test;
606 friend class TestSuite;
607 friend class internal::UnitTestImpl;
608 friend class internal::StreamingListenerTest;
609 friend TestInfo* internal::MakeAndRegisterTestInfo(
610 std::string test_suite_name, const char* name, const char* type_param,
611 const char* value_param, internal::CodeLocation code_location,
612 internal::TypeId fixture_class_id, internal::SetUpTestSuiteFunc set_up_tc,
613 internal::TearDownTestSuiteFunc tear_down_tc,
614 internal::TestFactoryBase* factory);
615
616 // Constructs a TestInfo object. The newly constructed instance assumes
617 // ownership of the factory object.
618 TestInfo(std::string test_suite_name, std::string name,
619 const char* a_type_param, // NULL if not a type-parameterized test
620 const char* a_value_param, // NULL if not a value-parameterized test
621 internal::CodeLocation a_code_location,
622 internal::TypeId fixture_class_id,
623 internal::TestFactoryBase* factory);
624
625 // Increments the number of death tests encountered in this test so
626 // far.
627 int increment_death_test_count() {
628 return result_.increment_death_test_count();
629 }
630
631 // Creates the test object, runs it, records its result, and then
632 // deletes it.
633 void Run();
634
635 // Skip and records the test result for this object.
636 void Skip();
637
638 static void ClearTestResult(TestInfo* test_info) {
639 test_info->result_.Clear();
640 }
641
642 // These fields are immutable properties of the test.
643 const std::string test_suite_name_; // test suite name
644 const std::string name_; // Test name
645 // Name of the parameter type, or NULL if this is not a typed or a
646 // type-parameterized test.
647 const std::unique_ptr<const ::std::string> type_param_;
648 // Text representation of the value parameter, or NULL if this is not a
649 // value-parameterized test.
650 const std::unique_ptr<const ::std::string> value_param_;
651 internal::CodeLocation location_;
652 const internal::TypeId fixture_class_id_; // ID of the test fixture class
653 bool should_run_; // True if and only if this test should run
654 bool is_disabled_; // True if and only if this test is disabled
655 bool matches_filter_; // True if this test matches the
656 // user-specified filter.
657 bool is_in_another_shard_; // Will be run in another shard.
658 internal::TestFactoryBase* const factory_; // The factory that creates
659 // the test object
660
661 // This field is mutable and needs to be reset before running the
662 // test for the second time.
663 TestResult result_;
664
665 TestInfo(const TestInfo&) = delete;
666 TestInfo& operator=(const TestInfo&) = delete;
667};
668
669// A test suite, which consists of a vector of TestInfos.
670//
671// TestSuite is not copyable.
672class GTEST_API___attribute__((visibility("default"))) TestSuite {
673 public:
674 // Creates a TestSuite with the given name.
675 //
676 // TestSuite does NOT have a default constructor. Always use this
677 // constructor to create a TestSuite object.
678 //
679 // Arguments:
680 //
681 // name: name of the test suite
682 // a_type_param: the name of the test's type parameter, or NULL if
683 // this is not a type-parameterized test.
684 // set_up_tc: pointer to the function that sets up the test suite
685 // tear_down_tc: pointer to the function that tears down the test suite
686 TestSuite(const std::string& name, const char* a_type_param,
687 internal::SetUpTestSuiteFunc set_up_tc,
688 internal::TearDownTestSuiteFunc tear_down_tc);
689
690 // Destructor of TestSuite.
691 virtual ~TestSuite();
692
693 // Gets the name of the TestSuite.
694 const char* name() const { return name_.c_str(); }
695
696 // Returns the name of the parameter type, or NULL if this is not a
697 // type-parameterized test suite.
698 const char* type_param() const {
699 if (type_param_ != nullptr) return type_param_->c_str();
700 return nullptr;
701 }
702
703 // Returns true if any test in this test suite should run.
704 bool should_run() const { return should_run_; }
705
706 // Gets the number of successful tests in this test suite.
707 int successful_test_count() const;
708
709 // Gets the number of skipped tests in this test suite.
710 int skipped_test_count() const;
711
712 // Gets the number of failed tests in this test suite.
713 int failed_test_count() const;
714
715 // Gets the number of disabled tests that will be reported in the XML report.
716 int reportable_disabled_test_count() const;
717
718 // Gets the number of disabled tests in this test suite.
719 int disabled_test_count() const;
720
721 // Gets the number of tests to be printed in the XML report.
722 int reportable_test_count() const;
723
724 // Get the number of tests in this test suite that should run.
725 int test_to_run_count() const;
726
727 // Gets the number of all tests in this test suite.
728 int total_test_count() const;
729
730 // Returns true if and only if the test suite passed.
731 bool Passed() const { return !Failed(); }
732
733 // Returns true if and only if the test suite failed.
734 bool Failed() const {
735 return failed_test_count() > 0 || ad_hoc_test_result().Failed();
736 }
737
738 // Returns the elapsed time, in milliseconds.
739 TimeInMillis elapsed_time() const { return elapsed_time_; }
740
741 // Gets the time of the test suite start, in ms from the start of the
742 // UNIX epoch.
743 TimeInMillis start_timestamp() const { return start_timestamp_; }
744
745 // Returns the i-th test among all the tests. i can range from 0 to
746 // total_test_count() - 1. If i is not in that range, returns NULL.
747 const TestInfo* GetTestInfo(int i) const;
748
749 // Returns the TestResult that holds test properties recorded during
750 // execution of SetUpTestSuite and TearDownTestSuite.
751 const TestResult& ad_hoc_test_result() const { return ad_hoc_test_result_; }
752
753 private:
754 friend class Test;
755 friend class internal::UnitTestImpl;
756
757 // Gets the (mutable) vector of TestInfos in this TestSuite.
758 std::vector<TestInfo*>& test_info_list() { return test_info_list_; }
759
760 // Gets the (immutable) vector of TestInfos in this TestSuite.
761 const std::vector<TestInfo*>& test_info_list() const {
762 return test_info_list_;
763 }
764
765 // Returns the i-th test among all the tests. i can range from 0 to
766 // total_test_count() - 1. If i is not in that range, returns NULL.
767 TestInfo* GetMutableTestInfo(int i);
768
769 // Sets the should_run member.
770 void set_should_run(bool should) { should_run_ = should; }
771
772 // Adds a TestInfo to this test suite. Will delete the TestInfo upon
773 // destruction of the TestSuite object.
774 void AddTestInfo(TestInfo* test_info);
775
776 // Clears the results of all tests in this test suite.
777 void ClearResult();
778
779 // Clears the results of all tests in the given test suite.
780 static void ClearTestSuiteResult(TestSuite* test_suite) {
781 test_suite->ClearResult();
782 }
783
784 // Runs every test in this TestSuite.
785 void Run();
786
787 // Skips the execution of tests under this TestSuite
788 void Skip();
789
790 // Runs SetUpTestSuite() for this TestSuite. This wrapper is needed
791 // for catching exceptions thrown from SetUpTestSuite().
792 void RunSetUpTestSuite() {
793 if (set_up_tc_ != nullptr) {
794 (*set_up_tc_)();
795 }
796 }
797
798 // Runs TearDownTestSuite() for this TestSuite. This wrapper is
799 // needed for catching exceptions thrown from TearDownTestSuite().
800 void RunTearDownTestSuite() {
801 if (tear_down_tc_ != nullptr) {
802 (*tear_down_tc_)();
803 }
804 }
805
806 // Returns true if and only if test passed.
807 static bool TestPassed(const TestInfo* test_info) {
808 return test_info->should_run() && test_info->result()->Passed();
809 }
810
811 // Returns true if and only if test skipped.
812 static bool TestSkipped(const TestInfo* test_info) {
813 return test_info->should_run() && test_info->result()->Skipped();
814 }
815
816 // Returns true if and only if test failed.
817 static bool TestFailed(const TestInfo* test_info) {
818 return test_info->should_run() && test_info->result()->Failed();
819 }
820
821 // Returns true if and only if the test is disabled and will be reported in
822 // the XML report.
823 static bool TestReportableDisabled(const TestInfo* test_info) {
824 return test_info->is_reportable() && test_info->is_disabled_;
825 }
826
827 // Returns true if and only if test is disabled.
828 static bool TestDisabled(const TestInfo* test_info) {
829 return test_info->is_disabled_;
830 }
831
832 // Returns true if and only if this test will appear in the XML report.
833 static bool TestReportable(const TestInfo* test_info) {
834 return test_info->is_reportable();
835 }
836
837 // Returns true if the given test should run.
838 static bool ShouldRunTest(const TestInfo* test_info) {
839 return test_info->should_run();
840 }
841
842 // Shuffles the tests in this test suite.
843 void ShuffleTests(internal::Random* random);
844
845 // Restores the test order to before the first shuffle.
846 void UnshuffleTests();
847
848 // Name of the test suite.
849 std::string name_;
850 // Name of the parameter type, or NULL if this is not a typed or a
851 // type-parameterized test.
852 const std::unique_ptr<const ::std::string> type_param_;
853 // The vector of TestInfos in their original order. It owns the
854 // elements in the vector.
855 std::vector<TestInfo*> test_info_list_;
856 // Provides a level of indirection for the test list to allow easy
857 // shuffling and restoring the test order. The i-th element in this
858 // vector is the index of the i-th test in the shuffled test list.
859 std::vector<int> test_indices_;
860 // Pointer to the function that sets up the test suite.
861 internal::SetUpTestSuiteFunc set_up_tc_;
862 // Pointer to the function that tears down the test suite.
863 internal::TearDownTestSuiteFunc tear_down_tc_;
864 // True if and only if any test in this test suite should run.
865 bool should_run_;
866 // The start time, in milliseconds since UNIX Epoch.
867 TimeInMillis start_timestamp_;
868 // Elapsed time, in milliseconds.
869 TimeInMillis elapsed_time_;
870 // Holds test properties recorded during execution of SetUpTestSuite and
871 // TearDownTestSuite.
872 TestResult ad_hoc_test_result_;
873
874 // We disallow copying TestSuites.
875 TestSuite(const TestSuite&) = delete;
876 TestSuite& operator=(const TestSuite&) = delete;
877};
878
879// An Environment object is capable of setting up and tearing down an
880// environment. You should subclass this to define your own
881// environment(s).
882//
883// An Environment object does the set-up and tear-down in virtual
884// methods SetUp() and TearDown() instead of the constructor and the
885// destructor, as:
886//
887// 1. You cannot safely throw from a destructor. This is a problem
888// as in some cases Google Test is used where exceptions are enabled, and
889// we may want to implement ASSERT_* using exceptions where they are
890// available.
891// 2. You cannot use ASSERT_* directly in a constructor or
892// destructor.
893class Environment {
894 public:
895 // The d'tor is virtual as we need to subclass Environment.
896 virtual ~Environment() = default;
897
898 // Override this to define how to set up the environment.
899 virtual void SetUp() {}
900
901 // Override this to define how to tear down the environment.
902 virtual void TearDown() {}
903
904 private:
905 // If you see an error about overriding the following function or
906 // about it being private, you have mis-spelled SetUp() as Setup().
907 struct Setup_should_be_spelled_SetUp {};
908 virtual Setup_should_be_spelled_SetUp* Setup() { return nullptr; }
909};
910
911#if GTEST_HAS_EXCEPTIONS1
912
913// Exception which can be thrown from TestEventListener::OnTestPartResult.
914class GTEST_API___attribute__((visibility("default"))) AssertionException
915 : public internal::GoogleTestFailureException {
916 public:
917 explicit AssertionException(const TestPartResult& result)
918 : GoogleTestFailureException(result) {}
919};
920
921#endif // GTEST_HAS_EXCEPTIONS
922
923// The interface for tracing execution of tests. The methods are organized in
924// the order the corresponding events are fired.
925class TestEventListener {
926 public:
927 virtual ~TestEventListener() = default;
928
929 // Fired before any test activity starts.
930 virtual void OnTestProgramStart(const UnitTest& unit_test) = 0;
931
932 // Fired before each iteration of tests starts. There may be more than
933 // one iteration if GTEST_FLAG(repeat) is set. iteration is the iteration
934 // index, starting from 0.
935 virtual void OnTestIterationStart(const UnitTest& unit_test,
936 int iteration) = 0;
937
938 // Fired before environment set-up for each iteration of tests starts.
939 virtual void OnEnvironmentsSetUpStart(const UnitTest& unit_test) = 0;
940
941 // Fired after environment set-up for each iteration of tests ends.
942 virtual void OnEnvironmentsSetUpEnd(const UnitTest& unit_test) = 0;
943
944 // Fired before the test suite starts.
945 virtual void OnTestSuiteStart(const TestSuite& /*test_suite*/) {}
946
947 // Legacy API is deprecated but still available
948#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
949 virtual void OnTestCaseStart(const TestCase& /*test_case*/) {}
950#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
951
952 // Fired before the test starts.
953 virtual void OnTestStart(const TestInfo& test_info) = 0;
954
955 // Fired when a test is disabled
956 virtual void OnTestDisabled(const TestInfo& /*test_info*/) {}
957
958 // Fired after a failed assertion or a SUCCEED() invocation.
959 // If you want to throw an exception from this function to skip to the next
960 // TEST, it must be AssertionException defined above, or inherited from it.
961 virtual void OnTestPartResult(const TestPartResult& test_part_result) = 0;
962
963 // Fired after the test ends.
964 virtual void OnTestEnd(const TestInfo& test_info) = 0;
965
966 // Fired after the test suite ends.
967 virtual void OnTestSuiteEnd(const TestSuite& /*test_suite*/) {}
968
969// Legacy API is deprecated but still available
970#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
971 virtual void OnTestCaseEnd(const TestCase& /*test_case*/) {}
972#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
973
974 // Fired before environment tear-down for each iteration of tests starts.
975 virtual void OnEnvironmentsTearDownStart(const UnitTest& unit_test) = 0;
976
977 // Fired after environment tear-down for each iteration of tests ends.
978 virtual void OnEnvironmentsTearDownEnd(const UnitTest& unit_test) = 0;
979
980 // Fired after each iteration of tests finishes.
981 virtual void OnTestIterationEnd(const UnitTest& unit_test, int iteration) = 0;
982
983 // Fired after all test activities have ended.
984 virtual void OnTestProgramEnd(const UnitTest& unit_test) = 0;
985};
986
987// The convenience class for users who need to override just one or two
988// methods and are not concerned that a possible change to a signature of
989// the methods they override will not be caught during the build. For
990// comments about each method please see the definition of TestEventListener
991// above.
992class EmptyTestEventListener : public TestEventListener {
993 public:
994 void OnTestProgramStart(const UnitTest& /*unit_test*/) override {}
995 void OnTestIterationStart(const UnitTest& /*unit_test*/,
996 int /*iteration*/) override {}
997 void OnEnvironmentsSetUpStart(const UnitTest& /*unit_test*/) override {}
998 void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override {}
999 void OnTestSuiteStart(const TestSuite& /*test_suite*/) override {}
1000// Legacy API is deprecated but still available
1001#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
1002 void OnTestCaseStart(const TestCase& /*test_case*/) override {}
1003#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
1004
1005 void OnTestStart(const TestInfo& /*test_info*/) override {}
1006 void OnTestDisabled(const TestInfo& /*test_info*/) override {}
1007 void OnTestPartResult(const TestPartResult& /*test_part_result*/) override {}
1008 void OnTestEnd(const TestInfo& /*test_info*/) override {}
1009 void OnTestSuiteEnd(const TestSuite& /*test_suite*/) override {}
1010#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
1011 void OnTestCaseEnd(const TestCase& /*test_case*/) override {}
1012#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
1013
1014 void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) override {}
1015 void OnEnvironmentsTearDownEnd(const UnitTest& /*unit_test*/) override {}
1016 void OnTestIterationEnd(const UnitTest& /*unit_test*/,
1017 int /*iteration*/) override {}
1018 void OnTestProgramEnd(const UnitTest& /*unit_test*/) override {}
1019};
1020
1021// TestEventListeners lets users add listeners to track events in Google Test.
1022class GTEST_API___attribute__((visibility("default"))) TestEventListeners {
1023 public:
1024 TestEventListeners();
1025 ~TestEventListeners();
1026
1027 // Appends an event listener to the end of the list. Google Test assumes
1028 // the ownership of the listener (i.e. it will delete the listener when
1029 // the test program finishes).
1030 void Append(TestEventListener* listener);
1031
1032 // Removes the given event listener from the list and returns it. It then
1033 // becomes the caller's responsibility to delete the listener. Returns
1034 // NULL if the listener is not found in the list.
1035 TestEventListener* Release(TestEventListener* listener);
1036
1037 // Returns the standard listener responsible for the default console
1038 // output. Can be removed from the listeners list to shut down default
1039 // console output. Note that removing this object from the listener list
1040 // with Release transfers its ownership to the caller and makes this
1041 // function return NULL the next time.
1042 TestEventListener* default_result_printer() const {
1043 return default_result_printer_;
1044 }
1045
1046 // Returns the standard listener responsible for the default XML output
1047 // controlled by the --gtest_output=xml flag. Can be removed from the
1048 // listeners list by users who want to shut down the default XML output
1049 // controlled by this flag and substitute it with custom one. Note that
1050 // removing this object from the listener list with Release transfers its
1051 // ownership to the caller and makes this function return NULL the next
1052 // time.
1053 TestEventListener* default_xml_generator() const {
1054 return default_xml_generator_;
1055 }
1056
1057 // Controls whether events will be forwarded by the repeater to the
1058 // listeners in the list.
1059 void SuppressEventForwarding(bool);
1060
1061 private:
1062 friend class TestSuite;
1063 friend class TestInfo;
1064 friend class internal::DefaultGlobalTestPartResultReporter;
1065 friend class internal::NoExecDeathTest;
1066 friend class internal::TestEventListenersAccessor;
1067 friend class internal::UnitTestImpl;
1068
1069 // Returns repeater that broadcasts the TestEventListener events to all
1070 // subscribers.
1071 TestEventListener* repeater();
1072
1073 // Sets the default_result_printer attribute to the provided listener.
1074 // The listener is also added to the listener list and previous
1075 // default_result_printer is removed from it and deleted. The listener can
1076 // also be NULL in which case it will not be added to the list. Does
1077 // nothing if the previous and the current listener objects are the same.
1078 void SetDefaultResultPrinter(TestEventListener* listener);
1079
1080 // Sets the default_xml_generator attribute to the provided listener. The
1081 // listener is also added to the listener list and previous
1082 // default_xml_generator is removed from it and deleted. The listener can
1083 // also be NULL in which case it will not be added to the list. Does
1084 // nothing if the previous and the current listener objects are the same.
1085 void SetDefaultXmlGenerator(TestEventListener* listener);
1086
1087 // Controls whether events will be forwarded by the repeater to the
1088 // listeners in the list.
1089 bool EventForwardingEnabled() const;
1090
1091 // The actual list of listeners.
1092 internal::TestEventRepeater* repeater_;
1093 // Listener responsible for the standard result output.
1094 TestEventListener* default_result_printer_;
1095 // Listener responsible for the creation of the XML output file.
1096 TestEventListener* default_xml_generator_;
1097
1098 // We disallow copying TestEventListeners.
1099 TestEventListeners(const TestEventListeners&) = delete;
1100 TestEventListeners& operator=(const TestEventListeners&) = delete;
1101};
1102
1103// A UnitTest consists of a vector of TestSuites.
1104//
1105// This is a singleton class. The only instance of UnitTest is
1106// created when UnitTest::GetInstance() is first called. This
1107// instance is never deleted.
1108//
1109// UnitTest is not copyable.
1110//
1111// This class is thread-safe as long as the methods are called
1112// according to their specification.
1113class GTEST_API___attribute__((visibility("default"))) UnitTest {
1114 public:
1115 // Gets the singleton UnitTest object. The first time this method
1116 // is called, a UnitTest object is constructed and returned.
1117 // Consecutive calls will return the same object.
1118 static UnitTest* GetInstance();
1119
1120 // Runs all tests in this UnitTest object and prints the result.
1121 // Returns 0 if successful, or 1 otherwise.
1122 //
1123 // This method can only be called from the main thread.
1124 //
1125 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1126 int Run() GTEST_MUST_USE_RESULT___attribute__((warn_unused_result));
1127
1128 // Returns the working directory when the first TEST() or TEST_F()
1129 // was executed. The UnitTest object owns the string.
1130 const char* original_working_dir() const;
1131
1132 // Returns the TestSuite object for the test that's currently running,
1133 // or NULL if no test is running.
1134 const TestSuite* current_test_suite() const GTEST_LOCK_EXCLUDED_(mutex_);
1135
1136// Legacy API is still available but deprecated
1137#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
1138 const TestCase* current_test_case() const GTEST_LOCK_EXCLUDED_(mutex_);
1139#endif
1140
1141 // Returns the TestInfo object for the test that's currently running,
1142 // or NULL if no test is running.
1143 const TestInfo* current_test_info() const GTEST_LOCK_EXCLUDED_(mutex_);
1144
1145 // Returns the random seed used at the start of the current test run.
1146 int random_seed() const;
1147
1148 // Returns the ParameterizedTestSuiteRegistry object used to keep track of
1149 // value-parameterized tests and instantiate and register them.
1150 //
1151 // INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1152 internal::ParameterizedTestSuiteRegistry& parameterized_test_registry()
1153 GTEST_LOCK_EXCLUDED_(mutex_);
1154
1155 // Gets the number of successful test suites.
1156 int successful_test_suite_count() const;
1157
1158 // Gets the number of failed test suites.
1159 int failed_test_suite_count() const;
1160
1161 // Gets the number of all test suites.
1162 int total_test_suite_count() const;
1163
1164 // Gets the number of all test suites that contain at least one test
1165 // that should run.
1166 int test_suite_to_run_count() const;
1167
1168 // Legacy API is deprecated but still available
1169#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
1170 int successful_test_case_count() const;
1171 int failed_test_case_count() const;
1172 int total_test_case_count() const;
1173 int test_case_to_run_count() const;
1174#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
1175
1176 // Gets the number of successful tests.
1177 int successful_test_count() const;
1178
1179 // Gets the number of skipped tests.
1180 int skipped_test_count() const;
1181
1182 // Gets the number of failed tests.
1183 int failed_test_count() const;
1184
1185 // Gets the number of disabled tests that will be reported in the XML report.
1186 int reportable_disabled_test_count() const;
1187
1188 // Gets the number of disabled tests.
1189 int disabled_test_count() const;
1190
1191 // Gets the number of tests to be printed in the XML report.
1192 int reportable_test_count() const;
1193
1194 // Gets the number of all tests.
1195 int total_test_count() const;
1196
1197 // Gets the number of tests that should run.
1198 int test_to_run_count() const;
1199
1200 // Gets the time of the test program start, in ms from the start of the
1201 // UNIX epoch.
1202 TimeInMillis start_timestamp() const;
1203
1204 // Gets the elapsed time, in milliseconds.
1205 TimeInMillis elapsed_time() const;
1206
1207 // Returns true if and only if the unit test passed (i.e. all test suites
1208 // passed).
1209 bool Passed() const;
1210
1211 // Returns true if and only if the unit test failed (i.e. some test suite
1212 // failed or something outside of all tests failed).
1213 bool Failed() const;
1214
1215 // Gets the i-th test suite among all the test suites. i can range from 0 to
1216 // total_test_suite_count() - 1. If i is not in that range, returns NULL.
1217 const TestSuite* GetTestSuite(int i) const;
1218
1219// Legacy API is deprecated but still available
1220#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
1221 const TestCase* GetTestCase(int i) const;
1222#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
1223
1224 // Returns the TestResult containing information on test failures and
1225 // properties logged outside of individual test suites.
1226 const TestResult& ad_hoc_test_result() const;
1227
1228 // Returns the list of event listeners that can be used to track events
1229 // inside Google Test.
1230 TestEventListeners& listeners();
1231
1232 private:
1233 // Registers and returns a global test environment. When a test
1234 // program is run, all global test environments will be set-up in
1235 // the order they were registered. After all tests in the program
1236 // have finished, all global test environments will be torn-down in
1237 // the *reverse* order they were registered.
1238 //
1239 // The UnitTest object takes ownership of the given environment.
1240 //
1241 // This method can only be called from the main thread.
1242 Environment* AddEnvironment(Environment* env);
1243
1244 // Adds a TestPartResult to the current TestResult object. All
1245 // Google Test assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc)
1246 // eventually call this to report their results. The user code
1247 // should use the assertion macros instead of calling this directly.
1248 void AddTestPartResult(TestPartResult::Type result_type,
1249 const char* file_name, int line_number,
1250 const std::string& message,
1251 const std::string& os_stack_trace)
1252 GTEST_LOCK_EXCLUDED_(mutex_);
1253
1254 // Adds a TestProperty to the current TestResult object when invoked from
1255 // inside a test, to current TestSuite's ad_hoc_test_result_ when invoked
1256 // from SetUpTestSuite or TearDownTestSuite, or to the global property set
1257 // when invoked elsewhere. If the result already contains a property with
1258 // the same key, the value will be updated.
1259 void RecordProperty(const std::string& key, const std::string& value);
1260
1261 // Gets the i-th test suite among all the test suites. i can range from 0 to
1262 // total_test_suite_count() - 1. If i is not in that range, returns NULL.
1263 TestSuite* GetMutableTestSuite(int i);
1264
1265 // Invokes OsStackTrackGetterInterface::UponLeavingGTest. UponLeavingGTest()
1266 // should be called immediately before Google Test calls user code. It saves
1267 // some information about the current stack that CurrentStackTrace() will use
1268 // to find and hide Google Test stack frames.
1269 void UponLeavingGTest();
1270
1271 // Sets the TestSuite object for the test that's currently running.
1272 void set_current_test_suite(TestSuite* a_current_test_suite)
1273 GTEST_LOCK_EXCLUDED_(mutex_);
1274
1275 // Sets the TestInfo object for the test that's currently running.
1276 void set_current_test_info(TestInfo* a_current_test_info)
1277 GTEST_LOCK_EXCLUDED_(mutex_);
1278
1279 // Accessors for the implementation object.
1280 internal::UnitTestImpl* impl() { return impl_; }
1281 const internal::UnitTestImpl* impl() const { return impl_; }
1282
1283 // These classes and functions are friends as they need to access private
1284 // members of UnitTest.
1285 friend class ScopedTrace;
1286 friend class Test;
1287 friend class TestInfo;
1288 friend class TestSuite;
1289 friend class internal::AssertHelper;
1290 friend class internal::StreamingListenerTest;
1291 friend class internal::UnitTestRecordPropertyTestHelper;
1292 friend Environment* AddGlobalTestEnvironment(Environment* env);
1293 friend std::set<std::string>* internal::GetIgnoredParameterizedTestSuites();
1294 friend internal::UnitTestImpl* internal::GetUnitTestImpl();
1295 friend void internal::ReportFailureInUnknownLocation(
1296 TestPartResult::Type result_type, const std::string& message);
1297
1298 // Creates an empty UnitTest.
1299 UnitTest();
1300
1301 // D'tor
1302 virtual ~UnitTest();
1303
1304 // Pushes a trace defined by SCOPED_TRACE() on to the per-thread
1305 // Google Test trace stack.
1306 void PushGTestTrace(const internal::TraceInfo& trace)
1307 GTEST_LOCK_EXCLUDED_(mutex_);
1308
1309 // Pops a trace from the per-thread Google Test trace stack.
1310 void PopGTestTrace() GTEST_LOCK_EXCLUDED_(mutex_);
1311
1312 // Protects mutable state in *impl_. This is mutable as some const
1313 // methods need to lock it too.
1314 mutable internal::Mutex mutex_;
1315
1316 // Opaque implementation object. This field is never changed once
1317 // the object is constructed. We don't mark it as const here, as
1318 // doing so will cause a warning in the constructor of UnitTest.
1319 // Mutable state in *impl_ is protected by mutex_.
1320 internal::UnitTestImpl* impl_;
1321
1322 // We disallow copying UnitTest.
1323 UnitTest(const UnitTest&) = delete;
1324 UnitTest& operator=(const UnitTest&) = delete;
1325};
1326
1327// A convenient wrapper for adding an environment for the test
1328// program.
1329//
1330// You should call this before RUN_ALL_TESTS() is called, probably in
1331// main(). If you use gtest_main, you need to call this before main()
1332// starts for it to take effect. For example, you can define a global
1333// variable like this:
1334//
1335// testing::Environment* const foo_env =
1336// testing::AddGlobalTestEnvironment(new FooEnvironment);
1337//
1338// However, we strongly recommend you to write your own main() and
1339// call AddGlobalTestEnvironment() there, as relying on initialization
1340// of global variables makes the code harder to read and may cause
1341// problems when you register multiple environments from different
1342// translation units and the environments have dependencies among them
1343// (remember that the compiler doesn't guarantee the order in which
1344// global variables from different translation units are initialized).
1345inline Environment* AddGlobalTestEnvironment(Environment* env) {
1346 return UnitTest::GetInstance()->AddEnvironment(env);
1347}
1348
1349// Initializes Google Test. This must be called before calling
1350// RUN_ALL_TESTS(). In particular, it parses a command line for the
1351// flags that Google Test recognizes. Whenever a Google Test flag is
1352// seen, it is removed from argv, and *argc is decremented.
1353//
1354// No value is returned. Instead, the Google Test flag variables are
1355// updated.
1356//
1357// Calling the function for the second time has no user-visible effect.
1358GTEST_API___attribute__((visibility("default"))) void InitGoogleTest(int* argc, char** argv);
1359
1360// This overloaded version can be used in Windows programs compiled in
1361// UNICODE mode.
1362GTEST_API___attribute__((visibility("default"))) void InitGoogleTest(int* argc, wchar_t** argv);
1363
1364// This overloaded version can be used on Arduino/embedded platforms where
1365// there is no argc/argv.
1366GTEST_API___attribute__((visibility("default"))) void InitGoogleTest();
1367
1368namespace internal {
1369
1370// Separate the error generating code from the code path to reduce the stack
1371// frame size of CmpHelperEQ. This helps reduce the overhead of some sanitizers
1372// when calling EXPECT_* in a tight loop.
1373template <typename T1, typename T2>
1374AssertionResult CmpHelperEQFailure(const char* lhs_expression,
1375 const char* rhs_expression, const T1& lhs,
1376 const T2& rhs) {
1377 return EqFailure(lhs_expression, rhs_expression,
1378 FormatForComparisonFailureMessage(lhs, rhs),
1379 FormatForComparisonFailureMessage(rhs, lhs), false);
1380}
1381
1382// This block of code defines operator==/!=
1383// to block lexical scope lookup.
1384// It prevents using invalid operator==/!= defined at namespace scope.
1385struct faketype {};
1386inline bool operator==(faketype, faketype) { return true; }
1387inline bool operator!=(faketype, faketype) { return false; }
1388
1389// The helper function for {ASSERT|EXPECT}_EQ.
1390template <typename T1, typename T2>
1391AssertionResult CmpHelperEQ(const char* lhs_expression,
1392 const char* rhs_expression, const T1& lhs,
1393 const T2& rhs) {
1394 if (lhs == rhs) {
1395 return AssertionSuccess();
1396 }
1397
1398 return CmpHelperEQFailure(lhs_expression, rhs_expression, lhs, rhs);
1399}
1400
1401class EqHelper {
1402 public:
1403 // This templatized version is for the general case.
1404 template <
1405 typename T1, typename T2,
1406 // Disable this overload for cases where one argument is a pointer
1407 // and the other is the null pointer constant.
1408 typename std::enable_if<!std::is_integral<T1>::value ||
1409 !std::is_pointer<T2>::value>::type* = nullptr>
1410 static AssertionResult Compare(const char* lhs_expression,
1411 const char* rhs_expression, const T1& lhs,
1412 const T2& rhs) {
1413 return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
1414 }
1415
1416 // With this overloaded version, we allow anonymous enums to be used
1417 // in {ASSERT|EXPECT}_EQ when compiled with gcc 4, as anonymous
1418 // enums can be implicitly cast to BiggestInt.
1419 //
1420 // Even though its body looks the same as the above version, we
1421 // cannot merge the two, as it will make anonymous enums unhappy.
1422 static AssertionResult Compare(const char* lhs_expression,
1423 const char* rhs_expression, BiggestInt lhs,
1424 BiggestInt rhs) {
1425 return CmpHelperEQ(lhs_expression, rhs_expression, lhs, rhs);
1426 }
1427
1428 template <typename T>
1429 static AssertionResult Compare(
1430 const char* lhs_expression, const char* rhs_expression,
1431 // Handle cases where '0' is used as a null pointer literal.
1432 std::nullptr_t /* lhs */, T* rhs) {
1433 // We already know that 'lhs' is a null pointer.
1434 return CmpHelperEQ(lhs_expression, rhs_expression, static_cast<T*>(nullptr),
1435 rhs);
1436 }
1437};
1438
1439// Separate the error generating code from the code path to reduce the stack
1440// frame size of CmpHelperOP. This helps reduce the overhead of some sanitizers
1441// when calling EXPECT_OP in a tight loop.
1442template <typename T1, typename T2>
1443AssertionResult CmpHelperOpFailure(const char* expr1, const char* expr2,
1444 const T1& val1, const T2& val2,
1445 const char* op) {
1446 return AssertionFailure()
1447 << "Expected: (" << expr1 << ") " << op << " (" << expr2
1448 << "), actual: " << FormatForComparisonFailureMessage(val1, val2)
1449 << " vs " << FormatForComparisonFailureMessage(val2, val1);
1450}
1451
1452// A macro for implementing the helper functions needed to implement
1453// ASSERT_?? and EXPECT_??. It is here just to avoid copy-and-paste
1454// of similar code.
1455//
1456// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1457
1458#define GTEST_IMPL_CMP_HELPER_(op_name, op) \
1459 template <typename T1, typename T2> \
1460 AssertionResult CmpHelper##op_name(const char* expr1, const char* expr2, \
1461 const T1& val1, const T2& val2) { \
1462 if (val1 op val2) { \
1463 return AssertionSuccess(); \
1464 } else { \
1465 return CmpHelperOpFailure(expr1, expr2, val1, val2, #op); \
1466 } \
1467 }
1468
1469// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1470
1471// Implements the helper function for {ASSERT|EXPECT}_NE
1472GTEST_IMPL_CMP_HELPER_(NE, !=)
30
An undefined value may be read from 'errno'
1473// Implements the helper function for {ASSERT|EXPECT}_LE
1474GTEST_IMPL_CMP_HELPER_(LE, <=)
1475// Implements the helper function for {ASSERT|EXPECT}_LT
1476GTEST_IMPL_CMP_HELPER_(LT, <)
1477// Implements the helper function for {ASSERT|EXPECT}_GE
1478GTEST_IMPL_CMP_HELPER_(GE, >=)
1479// Implements the helper function for {ASSERT|EXPECT}_GT
1480GTEST_IMPL_CMP_HELPER_(GT, >)
1481
1482#undef GTEST_IMPL_CMP_HELPER_
1483
1484// The helper function for {ASSERT|EXPECT}_STREQ.
1485//
1486// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1487GTEST_API___attribute__((visibility("default"))) AssertionResult CmpHelperSTREQ(const char* s1_expression,
1488 const char* s2_expression,
1489 const char* s1, const char* s2);
1490
1491// The helper function for {ASSERT|EXPECT}_STRCASEEQ.
1492//
1493// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1494GTEST_API___attribute__((visibility("default"))) AssertionResult CmpHelperSTRCASEEQ(const char* s1_expression,
1495 const char* s2_expression,
1496 const char* s1, const char* s2);
1497
1498// The helper function for {ASSERT|EXPECT}_STRNE.
1499//
1500// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1501GTEST_API___attribute__((visibility("default"))) AssertionResult CmpHelperSTRNE(const char* s1_expression,
1502 const char* s2_expression,
1503 const char* s1, const char* s2);
1504
1505// The helper function for {ASSERT|EXPECT}_STRCASENE.
1506//
1507// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1508GTEST_API___attribute__((visibility("default"))) AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
1509 const char* s2_expression,
1510 const char* s1, const char* s2);
1511
1512// Helper function for *_STREQ on wide strings.
1513//
1514// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1515GTEST_API___attribute__((visibility("default"))) AssertionResult CmpHelperSTREQ(const char* s1_expression,
1516 const char* s2_expression,
1517 const wchar_t* s1, const wchar_t* s2);
1518
1519// Helper function for *_STRNE on wide strings.
1520//
1521// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1522GTEST_API___attribute__((visibility("default"))) AssertionResult CmpHelperSTRNE(const char* s1_expression,
1523 const char* s2_expression,
1524 const wchar_t* s1, const wchar_t* s2);
1525
1526} // namespace internal
1527
1528// IsSubstring() and IsNotSubstring() are intended to be used as the
1529// first argument to {EXPECT,ASSERT}_PRED_FORMAT2(), not by
1530// themselves. They check whether needle is a substring of haystack
1531// (NULL is considered a substring of itself only), and return an
1532// appropriate error message when they fail.
1533//
1534// The {needle,haystack}_expr arguments are the stringified
1535// expressions that generated the two real arguments.
1536GTEST_API___attribute__((visibility("default"))) AssertionResult IsSubstring(const char* needle_expr,
1537 const char* haystack_expr,
1538 const char* needle,
1539 const char* haystack);
1540GTEST_API___attribute__((visibility("default"))) AssertionResult IsSubstring(const char* needle_expr,
1541 const char* haystack_expr,
1542 const wchar_t* needle,
1543 const wchar_t* haystack);
1544GTEST_API___attribute__((visibility("default"))) AssertionResult IsNotSubstring(const char* needle_expr,
1545 const char* haystack_expr,
1546 const char* needle,
1547 const char* haystack);
1548GTEST_API___attribute__((visibility("default"))) AssertionResult IsNotSubstring(const char* needle_expr,
1549 const char* haystack_expr,
1550 const wchar_t* needle,
1551 const wchar_t* haystack);
1552GTEST_API___attribute__((visibility("default"))) AssertionResult IsSubstring(const char* needle_expr,
1553 const char* haystack_expr,
1554 const ::std::string& needle,
1555 const ::std::string& haystack);
1556GTEST_API___attribute__((visibility("default"))) AssertionResult IsNotSubstring(const char* needle_expr,
1557 const char* haystack_expr,
1558 const ::std::string& needle,
1559 const ::std::string& haystack);
1560
1561#if GTEST_HAS_STD_WSTRING1
1562GTEST_API___attribute__((visibility("default"))) AssertionResult IsSubstring(const char* needle_expr,
1563 const char* haystack_expr,
1564 const ::std::wstring& needle,
1565 const ::std::wstring& haystack);
1566GTEST_API___attribute__((visibility("default"))) AssertionResult IsNotSubstring(const char* needle_expr,
1567 const char* haystack_expr,
1568 const ::std::wstring& needle,
1569 const ::std::wstring& haystack);
1570#endif // GTEST_HAS_STD_WSTRING
1571
1572namespace internal {
1573
1574// Helper template function for comparing floating-points.
1575//
1576// Template parameter:
1577//
1578// RawType: the raw floating-point type (either float or double)
1579//
1580// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1581template <typename RawType>
1582AssertionResult CmpHelperFloatingPointEQ(const char* lhs_expression,
1583 const char* rhs_expression,
1584 RawType lhs_value, RawType rhs_value) {
1585 const FloatingPoint<RawType> lhs(lhs_value), rhs(rhs_value);
1586
1587 if (lhs.AlmostEquals(rhs)) {
1588 return AssertionSuccess();
1589 }
1590
1591 ::std::stringstream lhs_ss;
1592 lhs_ss.precision(std::numeric_limits<RawType>::digits10 + 2);
1593 lhs_ss << lhs_value;
1594
1595 ::std::stringstream rhs_ss;
1596 rhs_ss.precision(std::numeric_limits<RawType>::digits10 + 2);
1597 rhs_ss << rhs_value;
1598
1599 return EqFailure(lhs_expression, rhs_expression,
1600 StringStreamToString(&lhs_ss), StringStreamToString(&rhs_ss),
1601 false);
1602}
1603
1604// Helper function for implementing ASSERT_NEAR.
1605//
1606// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1607GTEST_API___attribute__((visibility("default"))) AssertionResult DoubleNearPredFormat(const char* expr1,
1608 const char* expr2,
1609 const char* abs_error_expr,
1610 double val1, double val2,
1611 double abs_error);
1612
1613// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE.
1614// A class that enables one to stream messages to assertion macros
1615class GTEST_API___attribute__((visibility("default"))) AssertHelper {
1616 public:
1617 // Constructor.
1618 AssertHelper(TestPartResult::Type type, const char* file, int line,
1619 const char* message);
1620 ~AssertHelper();
1621
1622 // Message assignment is a semantic trick to enable assertion
1623 // streaming; see the GTEST_MESSAGE_ macro below.
1624 void operator=(const Message& message) const;
1625
1626 private:
1627 // We put our data in a struct so that the size of the AssertHelper class can
1628 // be as small as possible. This is important because gcc is incapable of
1629 // re-using stack space even for temporary variables, so every EXPECT_EQ
1630 // reserves stack space for another AssertHelper.
1631 struct AssertHelperData {
1632 AssertHelperData(TestPartResult::Type t, const char* srcfile, int line_num,
1633 const char* msg)
1634 : type(t), file(srcfile), line(line_num), message(msg) {}
1635
1636 TestPartResult::Type const type;
1637 const char* const file;
1638 int const line;
1639 std::string const message;
1640
1641 private:
1642 AssertHelperData(const AssertHelperData&) = delete;
1643 AssertHelperData& operator=(const AssertHelperData&) = delete;
1644 };
1645
1646 AssertHelperData* const data_;
1647
1648 AssertHelper(const AssertHelper&) = delete;
1649 AssertHelper& operator=(const AssertHelper&) = delete;
1650};
1651
1652} // namespace internal
1653
1654// The pure interface class that all value-parameterized tests inherit from.
1655// A value-parameterized class must inherit from both ::testing::Test and
1656// ::testing::WithParamInterface. In most cases that just means inheriting
1657// from ::testing::TestWithParam, but more complicated test hierarchies
1658// may need to inherit from Test and WithParamInterface at different levels.
1659//
1660// This interface has support for accessing the test parameter value via
1661// the GetParam() method.
1662//
1663// Use it with one of the parameter generator defining functions, like Range(),
1664// Values(), ValuesIn(), Bool(), Combine(), and ConvertGenerator<T>().
1665//
1666// class FooTest : public ::testing::TestWithParam<int> {
1667// protected:
1668// FooTest() {
1669// // Can use GetParam() here.
1670// }
1671// ~FooTest() override {
1672// // Can use GetParam() here.
1673// }
1674// void SetUp() override {
1675// // Can use GetParam() here.
1676// }
1677// void TearDown override {
1678// // Can use GetParam() here.
1679// }
1680// };
1681// TEST_P(FooTest, DoesBar) {
1682// // Can use GetParam() method here.
1683// Foo foo;
1684// ASSERT_TRUE(foo.DoesBar(GetParam()));
1685// }
1686// INSTANTIATE_TEST_SUITE_P(OneToTenRange, FooTest, ::testing::Range(1, 10));
1687
1688template <typename T>
1689class WithParamInterface {
1690 public:
1691 typedef T ParamType;
1692 virtual ~WithParamInterface() = default;
1693
1694 // The current parameter value. Is also available in the test fixture's
1695 // constructor.
1696 static const ParamType& GetParam() {
1697 GTEST_CHECK_(parameter_ != nullptr)switch (0) case 0: default: if (::testing::internal::IsTrue(parameter_
!= nullptr)) ; else ::testing::internal::GTestLog(::testing::
internal::GTEST_FATAL, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1697) .GetStream() << "Condition " "parameter_ != nullptr"
" failed. "
1698 << "GetParam() can only be called inside a value-parameterized test "
1699 << "-- did you intend to write TEST_P instead of TEST_F?";
1700 return *parameter_;
1701 }
1702
1703 private:
1704 // Sets parameter value. The caller is responsible for making sure the value
1705 // remains alive and unchanged throughout the current test.
1706 static void SetParam(const ParamType* parameter) { parameter_ = parameter; }
1707
1708 // Static value used for accessing parameter during a test lifetime.
1709 static const ParamType* parameter_;
1710
1711 // TestClass must be a subclass of WithParamInterface<T> and Test.
1712 template <class TestClass>
1713 friend class internal::ParameterizedTestFactory;
1714};
1715
1716template <typename T>
1717const T* WithParamInterface<T>::parameter_ = nullptr;
1718
1719// Most value-parameterized classes can ignore the existence of
1720// WithParamInterface, and can just inherit from ::testing::TestWithParam.
1721
1722template <typename T>
1723class TestWithParam : public Test, public WithParamInterface<T> {};
1724
1725// Macros for indicating success/failure in test code.
1726
1727// Skips test in runtime.
1728// Skipping test aborts current function.
1729// Skipped tests are neither successful nor failed.
1730#define GTEST_SKIP()return ::testing::internal::AssertHelper(::testing::TestPartResult
::kSkip, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1730, "") = ::testing::Message()
GTEST_SKIP_("")return ::testing::internal::AssertHelper(::testing::TestPartResult
::kSkip, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1730, "") = ::testing::Message()
1731
1732// ADD_FAILURE unconditionally adds a failure to the current test.
1733// SUCCEED generates a success - it doesn't automatically make the
1734// current test successful, as a test is only successful when it has
1735// no failure.
1736//
1737// EXPECT_* verifies that a certain condition is satisfied. If not,
1738// it behaves like ADD_FAILURE. In particular:
1739//
1740// EXPECT_TRUE verifies that a Boolean condition is true.
1741// EXPECT_FALSE verifies that a Boolean condition is false.
1742//
1743// FAIL and ASSERT_* are similar to ADD_FAILURE and EXPECT_*, except
1744// that they will also abort the current function on failure. People
1745// usually want the fail-fast behavior of FAIL and ASSERT_*, but those
1746// writing data-driven tests often find themselves using ADD_FAILURE
1747// and EXPECT_* more.
1748
1749// Generates a nonfatal failure with a generic message.
1750#define ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1750, "Failed") = ::testing::Message()
GTEST_NONFATAL_FAILURE_("Failed")::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1750, "Failed") = ::testing::Message()
1751
1752// Generates a nonfatal failure at the given source file location with
1753// a generic message.
1754#define ADD_FAILURE_AT(file, line)::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, file, line, "Failed") = ::testing::Message(
)
\
1755 GTEST_MESSAGE_AT_(file, line, "Failed", \::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, file, line, "Failed") = ::testing::Message(
)
1756 ::testing::TestPartResult::kNonFatalFailure)::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, file, line, "Failed") = ::testing::Message(
)
1757
1758// Generates a fatal failure with a generic message.
1759#define GTEST_FAIL()return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1759, "Failed") = ::testing::Message()
GTEST_FATAL_FAILURE_("Failed")return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1759, "Failed") = ::testing::Message()
1760
1761// Like GTEST_FAIL(), but at the given source file location.
1762#define GTEST_FAIL_AT(file, line)return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, file, line, "Failed") = ::testing::Message()
\
1763 return GTEST_MESSAGE_AT_(file, line, "Failed", \::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, file, line, "Failed") = ::testing::Message()
1764 ::testing::TestPartResult::kFatalFailure)::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, file, line, "Failed") = ::testing::Message()
1765
1766// Define this macro to 1 to omit the definition of FAIL(), which is a
1767// generic name and clashes with some other libraries.
1768#if !(defined(GTEST_DONT_DEFINE_FAIL) && GTEST_DONT_DEFINE_FAIL)
1769#define FAIL()return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1769, "Failed") = ::testing::Message()
GTEST_FAIL()return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1769, "Failed") = ::testing::Message()
1770#define FAIL_AT(file, line)return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, file, line, "Failed") = ::testing::Message()
GTEST_FAIL_AT(file, line)return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, file, line, "Failed") = ::testing::Message()
1771#endif
1772
1773// Generates a success with a generic message.
1774#define GTEST_SUCCEED()::testing::internal::AssertHelper(::testing::TestPartResult::
kSuccess, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1774, "Succeeded") = ::testing::Message()
GTEST_SUCCESS_("Succeeded")::testing::internal::AssertHelper(::testing::TestPartResult::
kSuccess, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1774, "Succeeded") = ::testing::Message()
1775
1776// Define this macro to 1 to omit the definition of SUCCEED(), which
1777// is a generic name and clashes with some other libraries.
1778#if !(defined(GTEST_DONT_DEFINE_SUCCEED) && GTEST_DONT_DEFINE_SUCCEED)
1779#define SUCCEED()::testing::internal::AssertHelper(::testing::TestPartResult::
kSuccess, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1779, "Succeeded") = ::testing::Message()
GTEST_SUCCEED()::testing::internal::AssertHelper(::testing::TestPartResult::
kSuccess, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1779, "Succeeded") = ::testing::Message()
1780#endif
1781
1782// Macros for testing exceptions.
1783//
1784// * {ASSERT|EXPECT}_THROW(statement, expected_exception):
1785// Tests that the statement throws the expected exception.
1786// * {ASSERT|EXPECT}_NO_THROW(statement):
1787// Tests that the statement doesn't throw any exception.
1788// * {ASSERT|EXPECT}_ANY_THROW(statement):
1789// Tests that the statement throws an exception.
1790
1791#define EXPECT_THROW(statement, expected_exception)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { statement; } else static_assert
(true, ""); } catch (expected_exception const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
expected_exception>::type>::type, std::exception>::
value, const ::testing::internal::NeverThrown&, const std
::exception&>::type e) { gtest_msg.value = "Expected: "
"statement" " throws an exception of type " "expected_exception"
".\n Actual: it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testthrow_1791; } catch (...) { gtest_msg.value =
"Expected: " "statement" " throws an exception of type " "expected_exception"
".\n Actual: it throws a different type."; goto gtest_label_testthrow_1791
; } if (!gtest_caught_expected) { gtest_msg.value = "Expected: "
"statement" " throws an exception of type " "expected_exception"
".\n Actual: it throws nothing."; goto gtest_label_testthrow_1791
; } } else gtest_label_testthrow_1791 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1791, gtest_msg.value.c_str()) = ::testing::Message()
\
1792 GTEST_TEST_THROW_(statement, expected_exception, GTEST_NONFATAL_FAILURE_)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { statement; } else static_assert
(true, ""); } catch (expected_exception const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
expected_exception>::type>::type, std::exception>::
value, const ::testing::internal::NeverThrown&, const std
::exception&>::type e) { gtest_msg.value = "Expected: "
"statement" " throws an exception of type " "expected_exception"
".\n Actual: it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testthrow_1792; } catch (...) { gtest_msg.value =
"Expected: " "statement" " throws an exception of type " "expected_exception"
".\n Actual: it throws a different type."; goto gtest_label_testthrow_1792
; } if (!gtest_caught_expected) { gtest_msg.value = "Expected: "
"statement" " throws an exception of type " "expected_exception"
".\n Actual: it throws nothing."; goto gtest_label_testthrow_1792
; } } else gtest_label_testthrow_1792 : ::testing::internal::
AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1792, gtest_msg.value.c_str()) = ::testing::Message()
1793#define EXPECT_NO_THROW(statement)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
statement; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_1793; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1793
; } } else gtest_label_testnothrow_1793 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1793, ("Expected: " "statement" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
\
1794 GTEST_TEST_NO_THROW_(statement, GTEST_NONFATAL_FAILURE_)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
statement; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_1794; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1794
; } } else gtest_label_testnothrow_1794 : ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1794, ("Expected: " "statement" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
1795#define EXPECT_ANY_THROW(statement)switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { bool gtest_caught_any = false; try { if (::testing::internal
::AlwaysTrue()) { statement; } else static_assert(true, ""); }
catch (...) { gtest_caught_any = true; } if (!gtest_caught_any
) { goto gtest_label_testanythrow_1795; } } else gtest_label_testanythrow_1795
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1795, "Expected: " "statement" " throws an exception.\n" " Actual: it doesn't."
) = ::testing::Message()
\
1796 GTEST_TEST_ANY_THROW_(statement, GTEST_NONFATAL_FAILURE_)switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { bool gtest_caught_any = false; try { if (::testing::internal
::AlwaysTrue()) { statement; } else static_assert(true, ""); }
catch (...) { gtest_caught_any = true; } if (!gtest_caught_any
) { goto gtest_label_testanythrow_1796; } } else gtest_label_testanythrow_1796
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1796, "Expected: " "statement" " throws an exception.\n" " Actual: it doesn't."
) = ::testing::Message()
1797#define ASSERT_THROW(statement, expected_exception)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { statement; } else static_assert
(true, ""); } catch (expected_exception const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
expected_exception>::type>::type, std::exception>::
value, const ::testing::internal::NeverThrown&, const std
::exception&>::type e) { gtest_msg.value = "Expected: "
"statement" " throws an exception of type " "expected_exception"
".\n Actual: it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testthrow_1797; } catch (...) { gtest_msg.value =
"Expected: " "statement" " throws an exception of type " "expected_exception"
".\n Actual: it throws a different type."; goto gtest_label_testthrow_1797
; } if (!gtest_caught_expected) { gtest_msg.value = "Expected: "
"statement" " throws an exception of type " "expected_exception"
".\n Actual: it throws nothing."; goto gtest_label_testthrow_1797
; } } else gtest_label_testthrow_1797 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1797, gtest_msg.value.c_str()) = ::testing::Message()
\
1798 GTEST_TEST_THROW_(statement, expected_exception, GTEST_FATAL_FAILURE_)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { bool gtest_caught_expected = false; try { if (
::testing::internal::AlwaysTrue()) { statement; } else static_assert
(true, ""); } catch (expected_exception const&) { gtest_caught_expected
= true; } catch (typename std::conditional< std::is_same<
typename std::remove_cv<typename std::remove_reference<
expected_exception>::type>::type, std::exception>::
value, const ::testing::internal::NeverThrown&, const std
::exception&>::type e) { gtest_msg.value = "Expected: "
"statement" " throws an exception of type " "expected_exception"
".\n Actual: it throws "; gtest_msg.value += ::testing::internal
::GetTypeName(typeid(e)); gtest_msg.value += " with description \""
; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto
gtest_label_testthrow_1798; } catch (...) { gtest_msg.value =
"Expected: " "statement" " throws an exception of type " "expected_exception"
".\n Actual: it throws a different type."; goto gtest_label_testthrow_1798
; } if (!gtest_caught_expected) { gtest_msg.value = "Expected: "
"statement" " throws an exception of type " "expected_exception"
".\n Actual: it throws nothing."; goto gtest_label_testthrow_1798
; } } else gtest_label_testthrow_1798 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1798, gtest_msg.value.c_str()) = ::testing::Message()
1799#define ASSERT_NO_THROW(statement)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
statement; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_1799; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1799
; } } else gtest_label_testnothrow_1799 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1799, ("Expected: " "statement" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
\
1800 GTEST_TEST_NO_THROW_(statement, GTEST_FATAL_FAILURE_)switch (0) case 0: default: if (::testing::internal::TrueWithString
gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) {
statement; } else static_assert(true, ""); } catch (std::exception
const& e) { gtest_msg.value = "it throws "; gtest_msg.value
+= ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value
+= " with description \""; gtest_msg.value += e.what(); gtest_msg
.value += "\"."; goto gtest_label_testnothrow_1800; } catch (
...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1800
; } } else gtest_label_testnothrow_1800 : return ::testing::internal
::AssertHelper(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1800, ("Expected: " "statement" " doesn't throw an exception.\n"
" Actual: " + gtest_msg.value) .c_str()) = ::testing::Message
()
1801#define ASSERT_ANY_THROW(statement)switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { bool gtest_caught_any = false; try { if (::testing::internal
::AlwaysTrue()) { statement; } else static_assert(true, ""); }
catch (...) { gtest_caught_any = true; } if (!gtest_caught_any
) { goto gtest_label_testanythrow_1801; } } else gtest_label_testanythrow_1801
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1801, "Expected: " "statement" " throws an exception.\n" " Actual: it doesn't."
) = ::testing::Message()
\
1802 GTEST_TEST_ANY_THROW_(statement, GTEST_FATAL_FAILURE_)switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { bool gtest_caught_any = false; try { if (::testing::internal
::AlwaysTrue()) { statement; } else static_assert(true, ""); }
catch (...) { gtest_caught_any = true; } if (!gtest_caught_any
) { goto gtest_label_testanythrow_1802; } } else gtest_label_testanythrow_1802
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1802, "Expected: " "statement" " throws an exception.\n" " Actual: it doesn't."
) = ::testing::Message()
1803
1804// Boolean assertions. Condition can be either a Boolean expression or an
1805// AssertionResult. For more information on how to use AssertionResult with
1806// these macros see comments on that class.
1807#define GTEST_EXPECT_TRUE(condition)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(condition)) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "/usr/src/googletest/googletest/include/gtest/gtest.h", 1807
, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "condition", "false", "true") .c_str()) = ::testing::Message
()
\
1808 GTEST_TEST_BOOLEAN_(condition, #condition, false, true, \switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(condition)) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "/usr/src/googletest/googletest/include/gtest/gtest.h", 1809
, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, #condition, "false", "true") .c_str()) = ::testing::Message
()
1809 GTEST_NONFATAL_FAILURE_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(condition)) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "/usr/src/googletest/googletest/include/gtest/gtest.h", 1809
, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, #condition, "false", "true") .c_str()) = ::testing::Message
()
1810#define GTEST_EXPECT_FALSE(condition)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(condition))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1810, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "condition", "true", "false") .c_str()) = ::testing::Message
()
\
1811 GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(condition))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1812, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, #condition, "true", "false") .c_str()) = ::testing::Message
()
1812 GTEST_NONFATAL_FAILURE_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(condition))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1812, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, #condition, "true", "false") .c_str()) = ::testing::Message
()
1813#define GTEST_ASSERT_TRUE(condition)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(condition)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1813, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "condition", "false", "true") .c_str()) = ::testing::Message
()
\
1814 GTEST_TEST_BOOLEAN_(condition, #condition, false, true, GTEST_FATAL_FAILURE_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(condition)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1814, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, #condition, "false", "true") .c_str()) = ::testing::Message
()
1815#define GTEST_ASSERT_FALSE(condition)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(condition))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1815, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "condition", "true", "false") .c_str()) = ::testing::Message
()
\
1816 GTEST_TEST_BOOLEAN_(!(condition), #condition, true, false, \switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(condition))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1817, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, #condition, "true", "false") .c_str()) = ::testing::Message
()
1817 GTEST_FATAL_FAILURE_)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(condition))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1817, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, #condition, "true", "false") .c_str()) = ::testing::Message
()
1818
1819// Define these macros to 1 to omit the definition of the corresponding
1820// EXPECT or ASSERT, which clashes with some users' own code.
1821
1822#if !(defined(GTEST_DONT_DEFINE_EXPECT_TRUE) && GTEST_DONT_DEFINE_EXPECT_TRUE)
1823#define EXPECT_TRUE(condition)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(condition)) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "/usr/src/googletest/googletest/include/gtest/gtest.h", 1823
, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "condition", "false", "true") .c_str()) = ::testing::Message
()
GTEST_EXPECT_TRUE(condition)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(condition)) ; else ::
testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "/usr/src/googletest/googletest/include/gtest/gtest.h", 1823
, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "condition", "false", "true") .c_str()) = ::testing::Message
()
1824#endif
1825
1826#if !(defined(GTEST_DONT_DEFINE_EXPECT_FALSE) && GTEST_DONT_DEFINE_EXPECT_FALSE)
1827#define EXPECT_FALSE(condition)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(condition))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1827, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "condition", "true", "false") .c_str()) = ::testing::Message
()
GTEST_EXPECT_FALSE(condition)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(condition))) ; else
::testing::internal::AssertHelper(::testing::TestPartResult::
kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1827, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "condition", "true", "false") .c_str()) = ::testing::Message
()
1828#endif
1829
1830#if !(defined(GTEST_DONT_DEFINE_ASSERT_TRUE) && GTEST_DONT_DEFINE_ASSERT_TRUE)
1831#define ASSERT_TRUE(condition)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(condition)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1831, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "condition", "false", "true") .c_str()) = ::testing::Message
()
GTEST_ASSERT_TRUE(condition)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(condition)) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1831, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "condition", "false", "true") .c_str()) = ::testing::Message
()
1832#endif
1833
1834#if !(defined(GTEST_DONT_DEFINE_ASSERT_FALSE) && GTEST_DONT_DEFINE_ASSERT_FALSE)
1835#define ASSERT_FALSE(condition)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(condition))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1835, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "condition", "true", "false") .c_str()) = ::testing::Message
()
GTEST_ASSERT_FALSE(condition)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar_ = ::testing::AssertionResult(!(condition))) ; else
return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1835, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_
, "condition", "true", "false") .c_str()) = ::testing::Message
()
1836#endif
1837
1838// Macros for testing equalities and inequalities.
1839//
1840// * {ASSERT|EXPECT}_EQ(v1, v2): Tests that v1 == v2
1841// * {ASSERT|EXPECT}_NE(v1, v2): Tests that v1 != v2
1842// * {ASSERT|EXPECT}_LT(v1, v2): Tests that v1 < v2
1843// * {ASSERT|EXPECT}_LE(v1, v2): Tests that v1 <= v2
1844// * {ASSERT|EXPECT}_GT(v1, v2): Tests that v1 > v2
1845// * {ASSERT|EXPECT}_GE(v1, v2): Tests that v1 >= v2
1846//
1847// When they are not, Google Test prints both the tested expressions and
1848// their actual values. The values must be compatible built-in types,
1849// or you will get a compiler error. By "compatible" we mean that the
1850// values can be compared by the respective operator.
1851//
1852// Note:
1853//
1854// 1. It is possible to make a user-defined type work with
1855// {ASSERT|EXPECT}_??(), but that requires overloading the
1856// comparison operators and is thus discouraged by the Google C++
1857// Usage Guide. Therefore, you are advised to use the
1858// {ASSERT|EXPECT}_TRUE() macro to assert that two objects are
1859// equal.
1860//
1861// 2. The {ASSERT|EXPECT}_??() macros do pointer comparisons on
1862// pointers (in particular, C strings). Therefore, if you use it
1863// with two C strings, you are testing how their locations in memory
1864// are related, not how their content is related. To compare two C
1865// strings by content, use {ASSERT|EXPECT}_STR*().
1866//
1867// 3. {ASSERT|EXPECT}_EQ(v1, v2) is preferred to
1868// {ASSERT|EXPECT}_TRUE(v1 == v2), as the former tells you
1869// what the actual value is when it fails, and similarly for the
1870// other comparisons.
1871//
1872// 4. Do not depend on the order in which {ASSERT|EXPECT}_??()
1873// evaluate their arguments, which is undefined.
1874//
1875// 5. These macros evaluate their arguments exactly once.
1876//
1877// Examples:
1878//
1879// EXPECT_NE(Foo(), 5);
1880// EXPECT_EQ(a_pointer, NULL);
1881// ASSERT_LT(i, array_size);
1882// ASSERT_GT(records.size(), 0) << "There is no record left.";
1883
1884#define EXPECT_EQ(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("val1", "val2"
, val1, val2))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1884, gtest_ar.failure_message()) = ::testing::Message()
\
1885 EXPECT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("val1", "val2"
, val1, val2))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1885, gtest_ar.failure_message()) = ::testing::Message()
1886#define EXPECT_NE(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("val1", "val2",
val1, val2))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1886, gtest_ar.failure_message()) = ::testing::Message()
\
1887 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("val1", "val2",
val1, val2))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1887, gtest_ar.failure_message()) = ::testing::Message()
1888#define EXPECT_LE(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLE("val1", "val2",
val1, val2))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1888, gtest_ar.failure_message()) = ::testing::Message()
\
1889 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLE("val1", "val2",
val1, val2))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1889, gtest_ar.failure_message()) = ::testing::Message()
1890#define EXPECT_LT(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLT("val1", "val2",
val1, val2))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1890, gtest_ar.failure_message()) = ::testing::Message()
\
1891 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLT("val1", "val2",
val1, val2))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1891, gtest_ar.failure_message()) = ::testing::Message()
1892#define EXPECT_GE(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("val1", "val2",
val1, val2))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1892, gtest_ar.failure_message()) = ::testing::Message()
\
1893 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("val1", "val2",
val1, val2))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1893, gtest_ar.failure_message()) = ::testing::Message()
1894#define EXPECT_GT(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGT("val1", "val2",
val1, val2))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1894, gtest_ar.failure_message()) = ::testing::Message()
\
1895 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGT("val1", "val2",
val1, val2))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1895, gtest_ar.failure_message()) = ::testing::Message()
1896
1897#define GTEST_ASSERT_EQ(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("val1", "val2"
, val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1897, gtest_ar.failure_message()) = ::testing::Message()
\
1898 ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("val1", "val2"
, val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1898, gtest_ar.failure_message()) = ::testing::Message()
1899#define GTEST_ASSERT_NE(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1899, gtest_ar.failure_message()) = ::testing::Message()
\
1900 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1900, gtest_ar.failure_message()) = ::testing::Message()
1901#define GTEST_ASSERT_LE(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLE("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1901, gtest_ar.failure_message()) = ::testing::Message()
\
1902 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLE("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1902, gtest_ar.failure_message()) = ::testing::Message()
1903#define GTEST_ASSERT_LT(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLT("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1903, gtest_ar.failure_message()) = ::testing::Message()
\
1904 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLT("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1904, gtest_ar.failure_message()) = ::testing::Message()
1905#define GTEST_ASSERT_GE(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1905, gtest_ar.failure_message()) = ::testing::Message()
\
1906 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1906, gtest_ar.failure_message()) = ::testing::Message()
1907#define GTEST_ASSERT_GT(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGT("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1907, gtest_ar.failure_message()) = ::testing::Message()
\
1908 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGT("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1908, gtest_ar.failure_message()) = ::testing::Message()
1909
1910// Define macro GTEST_DONT_DEFINE_ASSERT_XY to 1 to omit the definition of
1911// ASSERT_XY(), which clashes with some users' own code.
1912
1913#if !(defined(GTEST_DONT_DEFINE_ASSERT_EQ) && GTEST_DONT_DEFINE_ASSERT_EQ)
1914#define ASSERT_EQ(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("val1", "val2"
, val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1914, gtest_ar.failure_message()) = ::testing::Message()
GTEST_ASSERT_EQ(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::EqHelper::Compare("val1", "val2"
, val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1914, gtest_ar.failure_message()) = ::testing::Message()
1915#endif
1916
1917#if !(defined(GTEST_DONT_DEFINE_ASSERT_NE) && GTEST_DONT_DEFINE_ASSERT_NE)
1918#define ASSERT_NE(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1918, gtest_ar.failure_message()) = ::testing::Message()
GTEST_ASSERT_NE(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperNE("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1918, gtest_ar.failure_message()) = ::testing::Message()
1919#endif
1920
1921#if !(defined(GTEST_DONT_DEFINE_ASSERT_LE) && GTEST_DONT_DEFINE_ASSERT_LE)
1922#define ASSERT_LE(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLE("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1922, gtest_ar.failure_message()) = ::testing::Message()
GTEST_ASSERT_LE(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLE("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1922, gtest_ar.failure_message()) = ::testing::Message()
1923#endif
1924
1925#if !(defined(GTEST_DONT_DEFINE_ASSERT_LT) && GTEST_DONT_DEFINE_ASSERT_LT)
1926#define ASSERT_LT(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLT("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1926, gtest_ar.failure_message()) = ::testing::Message()
GTEST_ASSERT_LT(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperLT("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1926, gtest_ar.failure_message()) = ::testing::Message()
1927#endif
1928
1929#if !(defined(GTEST_DONT_DEFINE_ASSERT_GE) && GTEST_DONT_DEFINE_ASSERT_GE)
1930#define ASSERT_GE(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1930, gtest_ar.failure_message()) = ::testing::Message()
GTEST_ASSERT_GE(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGE("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1930, gtest_ar.failure_message()) = ::testing::Message()
1931#endif
1932
1933#if !(defined(GTEST_DONT_DEFINE_ASSERT_GT) && GTEST_DONT_DEFINE_ASSERT_GT)
1934#define ASSERT_GT(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGT("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1934, gtest_ar.failure_message()) = ::testing::Message()
GTEST_ASSERT_GT(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperGT("val1", "val2",
val1, val2))) ; else return ::testing::internal::AssertHelper
(::testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1934, gtest_ar.failure_message()) = ::testing::Message()
1935#endif
1936
1937// C-string Comparisons. All tests treat NULL and any non-NULL string
1938// as different. Two NULLs are equal.
1939//
1940// * {ASSERT|EXPECT}_STREQ(s1, s2): Tests that s1 == s2
1941// * {ASSERT|EXPECT}_STRNE(s1, s2): Tests that s1 != s2
1942// * {ASSERT|EXPECT}_STRCASEEQ(s1, s2): Tests that s1 == s2, ignoring case
1943// * {ASSERT|EXPECT}_STRCASENE(s1, s2): Tests that s1 != s2, ignoring case
1944//
1945// For wide or narrow string objects, you can use the
1946// {ASSERT|EXPECT}_??() macros.
1947//
1948// Don't depend on the order in which the arguments are evaluated,
1949// which is undefined.
1950//
1951// These macros evaluate their arguments exactly once.
1952
1953#define EXPECT_STREQ(s1, s2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperSTREQ("s1", "s2", s1
, s2))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1953, gtest_ar.failure_message()) = ::testing::Message()
\
1954 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperSTREQ("s1", "s2", s1
, s2))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1954, gtest_ar.failure_message()) = ::testing::Message()
1955#define EXPECT_STRNE(s1, s2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperSTRNE("s1", "s2", s1
, s2))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1955, gtest_ar.failure_message()) = ::testing::Message()
\
1956 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperSTRNE("s1", "s2", s1
, s2))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1956, gtest_ar.failure_message()) = ::testing::Message()
1957#define EXPECT_STRCASEEQ(s1, s2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperSTRCASEEQ("s1", "s2"
, s1, s2))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1957, gtest_ar.failure_message()) = ::testing::Message()
\
1958 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperSTRCASEEQ("s1", "s2"
, s1, s2))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1958, gtest_ar.failure_message()) = ::testing::Message()
1959#define EXPECT_STRCASENE(s1, s2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperSTRCASENE("s1", "s2"
, s1, s2))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1959, gtest_ar.failure_message()) = ::testing::Message()
\
1960 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperSTRCASENE("s1", "s2"
, s1, s2))) ; else ::testing::internal::AssertHelper(::testing
::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1960, gtest_ar.failure_message()) = ::testing::Message()
1961
1962#define ASSERT_STREQ(s1, s2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperSTREQ("s1", "s2", s1
, s2))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1962, gtest_ar.failure_message()) = ::testing::Message()
\
1963 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTREQ, s1, s2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperSTREQ("s1", "s2", s1
, s2))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1963, gtest_ar.failure_message()) = ::testing::Message()
1964#define ASSERT_STRNE(s1, s2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperSTRNE("s1", "s2", s1
, s2))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1964, gtest_ar.failure_message()) = ::testing::Message()
\
1965 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRNE, s1, s2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperSTRNE("s1", "s2", s1
, s2))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1965, gtest_ar.failure_message()) = ::testing::Message()
1966#define ASSERT_STRCASEEQ(s1, s2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperSTRCASEEQ("s1", "s2"
, s1, s2))) ; else return ::testing::internal::AssertHelper(::
testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1966, gtest_ar.failure_message()) = ::testing::Message()
\
1967 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASEEQ, s1, s2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperSTRCASEEQ("s1", "s2"
, s1, s2))) ; else return ::testing::internal::AssertHelper(::
testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1967, gtest_ar.failure_message()) = ::testing::Message()
1968#define ASSERT_STRCASENE(s1, s2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperSTRCASENE("s1", "s2"
, s1, s2))) ; else return ::testing::internal::AssertHelper(::
testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1968, gtest_ar.failure_message()) = ::testing::Message()
\
1969 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperSTRCASENE, s1, s2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperSTRCASENE("s1", "s2"
, s1, s2))) ; else return ::testing::internal::AssertHelper(::
testing::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1969, gtest_ar.failure_message()) = ::testing::Message()
1970
1971// Macros for comparing floating-point numbers.
1972//
1973// * {ASSERT|EXPECT}_FLOAT_EQ(val1, val2):
1974// Tests that two float values are almost equal.
1975// * {ASSERT|EXPECT}_DOUBLE_EQ(val1, val2):
1976// Tests that two double values are almost equal.
1977// * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error):
1978// Tests that v1 and v2 are within the given distance to each other.
1979//
1980// Google Test uses ULP-based comparison to automatically pick a default
1981// error bound that is appropriate for the operands. See the
1982// FloatingPoint template class in gtest-internal.h if you are
1983// interested in the implementation details.
1984
1985#define EXPECT_FLOAT_EQ(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperFloatingPointEQ<
float>("val1", "val2", val1, val2))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1985, gtest_ar.failure_message()) = ::testing::Message()
\
1986 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperFloatingPointEQ<
float>("val1", "val2", val1, val2))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1987, gtest_ar.failure_message()) = ::testing::Message()
1987 val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperFloatingPointEQ<
float>("val1", "val2", val1, val2))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1987, gtest_ar.failure_message()) = ::testing::Message()
1988
1989#define EXPECT_DOUBLE_EQ(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperFloatingPointEQ<
double>("val1", "val2", val1, val2))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1989, gtest_ar.failure_message()) = ::testing::Message()
\
1990 EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperFloatingPointEQ<
double>("val1", "val2", val1, val2))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1991, gtest_ar.failure_message()) = ::testing::Message()
1991 val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperFloatingPointEQ<
double>("val1", "val2", val1, val2))) ; else ::testing::internal
::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 1991, gtest_ar.failure_message()) = ::testing::Message()
1992
1993#define ASSERT_FLOAT_EQ(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperFloatingPointEQ<
float>("val1", "val2", val1, val2))) ; else return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/usr/src/googletest/googletest/include/gtest/gtest.h", 1993
, gtest_ar.failure_message()) = ::testing::Message()
\
1994 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<float>, \switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperFloatingPointEQ<
float>("val1", "val2", val1, val2))) ; else return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/usr/src/googletest/googletest/include/gtest/gtest.h", 1995
, gtest_ar.failure_message()) = ::testing::Message()
1995 val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperFloatingPointEQ<
float>("val1", "val2", val1, val2))) ; else return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/usr/src/googletest/googletest/include/gtest/gtest.h", 1995
, gtest_ar.failure_message()) = ::testing::Message()
1996
1997#define ASSERT_DOUBLE_EQ(val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperFloatingPointEQ<
double>("val1", "val2", val1, val2))) ; else return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/usr/src/googletest/googletest/include/gtest/gtest.h", 1997
, gtest_ar.failure_message()) = ::testing::Message()
\
1998 ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperFloatingPointEQ<double>, \switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperFloatingPointEQ<
double>("val1", "val2", val1, val2))) ; else return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/usr/src/googletest/googletest/include/gtest/gtest.h", 1999
, gtest_ar.failure_message()) = ::testing::Message()
1999 val1, val2)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::CmpHelperFloatingPointEQ<
double>("val1", "val2", val1, val2))) ; else return ::testing
::internal::AssertHelper(::testing::TestPartResult::kFatalFailure
, "/usr/src/googletest/googletest/include/gtest/gtest.h", 1999
, gtest_ar.failure_message()) = ::testing::Message()
2000
2001#define EXPECT_NEAR(val1, val2, abs_error)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::DoubleNearPredFormat("val1"
, "val2", "abs_error", val1, val2, abs_error))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "/usr/src/googletest/googletest/include/gtest/gtest.h", 2001
, gtest_ar.failure_message()) = ::testing::Message()
\
2002 EXPECT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, val1, val2, \switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::DoubleNearPredFormat("val1"
, "val2", "abs_error", val1, val2, abs_error))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "/usr/src/googletest/googletest/include/gtest/gtest.h", 2003
, gtest_ar.failure_message()) = ::testing::Message()
2003 abs_error)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::DoubleNearPredFormat("val1"
, "val2", "abs_error", val1, val2, abs_error))) ; else ::testing
::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure
, "/usr/src/googletest/googletest/include/gtest/gtest.h", 2003
, gtest_ar.failure_message()) = ::testing::Message()
2004
2005#define ASSERT_NEAR(val1, val2, abs_error)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::DoubleNearPredFormat("val1"
, "val2", "abs_error", val1, val2, abs_error))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2005, gtest_ar.failure_message()) = ::testing::Message()
\
2006 ASSERT_PRED_FORMAT3(::testing::internal::DoubleNearPredFormat, val1, val2, \switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::DoubleNearPredFormat("val1"
, "val2", "abs_error", val1, val2, abs_error))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2007, gtest_ar.failure_message()) = ::testing::Message()
2007 abs_error)switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::DoubleNearPredFormat("val1"
, "val2", "abs_error", val1, val2, abs_error))) ; else return
::testing::internal::AssertHelper(::testing::TestPartResult::
kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2007, gtest_ar.failure_message()) = ::testing::Message()
2008
2009// These predicate format functions work on floating-point values, and
2010// can be used in {ASSERT|EXPECT}_PRED_FORMAT2*(), e.g.
2011//
2012// EXPECT_PRED_FORMAT2(testing::DoubleLE, Foo(), 5.0);
2013
2014// Asserts that val1 is less than, or almost equal to, val2. Fails
2015// otherwise. In particular, it fails if either val1 or val2 is NaN.
2016GTEST_API___attribute__((visibility("default"))) AssertionResult FloatLE(const char* expr1, const char* expr2,
2017 float val1, float val2);
2018GTEST_API___attribute__((visibility("default"))) AssertionResult DoubleLE(const char* expr1, const char* expr2,
2019 double val1, double val2);
2020
2021#ifdef GTEST_OS_WINDOWS
2022
2023// Macros that test for HRESULT failure and success, these are only useful
2024// on Windows, and rely on Windows SDK macros and APIs to compile.
2025//
2026// * {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED}(expr)
2027//
2028// When expr unexpectedly fails or succeeds, Google Test prints the
2029// expected result and the actual result with both a human-readable
2030// string representation of the error, if available, as well as the
2031// hex result code.
2032#define EXPECT_HRESULT_SUCCEEDED(expr) \
2033 EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::IsHRESULTSuccess("(expr)", (
expr)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2033, gtest_ar.failure_message()) = ::testing::Message()
2034
2035#define ASSERT_HRESULT_SUCCEEDED(expr) \
2036 ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTSuccess, (expr))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::IsHRESULTSuccess("(expr)", (
expr)))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2036, gtest_ar.failure_message()) = ::testing::Message()
2037
2038#define EXPECT_HRESULT_FAILED(expr) \
2039 EXPECT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::IsHRESULTFailure("(expr)", (
expr)))) ; else ::testing::internal::AssertHelper(::testing::
TestPartResult::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2039, gtest_ar.failure_message()) = ::testing::Message()
2040
2041#define ASSERT_HRESULT_FAILED(expr) \
2042 ASSERT_PRED_FORMAT1(::testing::internal::IsHRESULTFailure, (expr))switch (0) case 0: default: if (const ::testing::AssertionResult
gtest_ar = (::testing::internal::IsHRESULTFailure("(expr)", (
expr)))) ; else return ::testing::internal::AssertHelper(::testing
::TestPartResult::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2042, gtest_ar.failure_message()) = ::testing::Message()
2043
2044#endif // GTEST_OS_WINDOWS
2045
2046// Macros that execute statement and check that it doesn't generate new fatal
2047// failures in the current thread.
2048//
2049// * {ASSERT|EXPECT}_NO_FATAL_FAILURE(statement);
2050//
2051// Examples:
2052//
2053// EXPECT_NO_FATAL_FAILURE(Process());
2054// ASSERT_NO_FATAL_FAILURE(Process()) << "Process() failed";
2055//
2056#define ASSERT_NO_FATAL_FAILURE(statement)switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { const ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker
; if (::testing::internal::AlwaysTrue()) { statement; } else static_assert
(true, ""); if (gtest_fatal_failure_checker.has_new_fatal_failure
()) { goto gtest_label_testnofatal_2056; } } else gtest_label_testnofatal_2056
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2056, "Expected: " "statement" " doesn't generate new fatal "
"failures in the current thread.\n" " Actual: it does.") = ::
testing::Message()
\
2057 GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_FATAL_FAILURE_)switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { const ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker
; if (::testing::internal::AlwaysTrue()) { statement; } else static_assert
(true, ""); if (gtest_fatal_failure_checker.has_new_fatal_failure
()) { goto gtest_label_testnofatal_2057; } } else gtest_label_testnofatal_2057
: return ::testing::internal::AssertHelper(::testing::TestPartResult
::kFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2057, "Expected: " "statement" " doesn't generate new fatal "
"failures in the current thread.\n" " Actual: it does.") = ::
testing::Message()
2058#define EXPECT_NO_FATAL_FAILURE(statement)switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { const ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker
; if (::testing::internal::AlwaysTrue()) { statement; } else static_assert
(true, ""); if (gtest_fatal_failure_checker.has_new_fatal_failure
()) { goto gtest_label_testnofatal_2058; } } else gtest_label_testnofatal_2058
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2058, "Expected: " "statement" " doesn't generate new fatal "
"failures in the current thread.\n" " Actual: it does.") = ::
testing::Message()
\
2059 GTEST_TEST_NO_FATAL_FAILURE_(statement, GTEST_NONFATAL_FAILURE_)switch (0) case 0: default: if (::testing::internal::AlwaysTrue
()) { const ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker
; if (::testing::internal::AlwaysTrue()) { statement; } else static_assert
(true, ""); if (gtest_fatal_failure_checker.has_new_fatal_failure
()) { goto gtest_label_testnofatal_2059; } } else gtest_label_testnofatal_2059
: ::testing::internal::AssertHelper(::testing::TestPartResult
::kNonFatalFailure, "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2059, "Expected: " "statement" " doesn't generate new fatal "
"failures in the current thread.\n" " Actual: it does.") = ::
testing::Message()
2060
2061// Causes a trace (including the given source file path and line number,
2062// and the given message) to be included in every test failure message generated
2063// by code in the scope of the lifetime of an instance of this class. The effect
2064// is undone with the destruction of the instance.
2065//
2066// The message argument can be anything streamable to std::ostream.
2067//
2068// Example:
2069// testing::ScopedTrace trace("file.cc", 123, "message");
2070//
2071class GTEST_API___attribute__((visibility("default"))) ScopedTrace {
2072 public:
2073 // The c'tor pushes the given source file location and message onto
2074 // a trace stack maintained by Google Test.
2075
2076 // Template version. Uses Message() to convert the values into strings.
2077 // Slow, but flexible.
2078 template <typename T>
2079 ScopedTrace(const char* file, int line, const T& message) {
2080 PushTrace(file, line, (Message() << message).GetString());
2081 }
2082
2083 // Optimize for some known types.
2084 ScopedTrace(const char* file, int line, const char* message) {
2085 PushTrace(file, line, message ? message : "(null)");
2086 }
2087
2088 ScopedTrace(const char* file, int line, const std::string& message) {
2089 PushTrace(file, line, message);
2090 }
2091
2092 // The d'tor pops the info pushed by the c'tor.
2093 //
2094 // Note that the d'tor is not virtual in order to be efficient.
2095 // Don't inherit from ScopedTrace!
2096 ~ScopedTrace();
2097
2098 private:
2099 void PushTrace(const char* file, int line, std::string message);
2100
2101 ScopedTrace(const ScopedTrace&) = delete;
2102 ScopedTrace& operator=(const ScopedTrace&) = delete;
2103};
2104
2105// Causes a trace (including the source file path, the current line
2106// number, and the given message) to be included in every test failure
2107// message generated by code in the current scope. The effect is
2108// undone when the control leaves the current scope.
2109//
2110// The message argument can be anything streamable to std::ostream.
2111//
2112// In the implementation, we include the current line number as part
2113// of the dummy variable name, thus allowing multiple SCOPED_TRACE()s
2114// to appear in the same block - as long as they are on different
2115// lines.
2116//
2117// Assuming that each thread maintains its own stack of traces.
2118// Therefore, a SCOPED_TRACE() would (correctly) only affect the
2119// assertions in its own thread.
2120#define SCOPED_TRACE(message)const ::testing::ScopedTrace gtest_trace_2120( "/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2120, (message))
\
2121 const ::testing::ScopedTrace GTEST_CONCAT_TOKEN_(gtest_trace_, __LINE__)gtest_trace_2121( \
2122 __FILE__"/usr/src/googletest/googletest/include/gtest/gtest.h", __LINE__2122, (message))
2123
2124// Compile-time assertion for type equality.
2125// StaticAssertTypeEq<type1, type2>() compiles if and only if type1 and type2
2126// are the same type. The value it returns is not interesting.
2127//
2128// Instead of making StaticAssertTypeEq a class template, we make it a
2129// function template that invokes a helper class template. This
2130// prevents a user from misusing StaticAssertTypeEq<T1, T2> by
2131// defining objects of that type.
2132//
2133// CAVEAT:
2134//
2135// When used inside a method of a class template,
2136// StaticAssertTypeEq<T1, T2>() is effective ONLY IF the method is
2137// instantiated. For example, given:
2138//
2139// template <typename T> class Foo {
2140// public:
2141// void Bar() { testing::StaticAssertTypeEq<int, T>(); }
2142// };
2143//
2144// the code:
2145//
2146// void Test1() { Foo<bool> foo; }
2147//
2148// will NOT generate a compiler error, as Foo<bool>::Bar() is never
2149// actually instantiated. Instead, you need:
2150//
2151// void Test2() { Foo<bool> foo; foo.Bar(); }
2152//
2153// to cause a compiler error.
2154template <typename T1, typename T2>
2155constexpr bool StaticAssertTypeEq() noexcept {
2156 static_assert(std::is_same<T1, T2>::value, "T1 and T2 are not the same type");
2157 return true;
2158}
2159
2160// Defines a test.
2161//
2162// The first parameter is the name of the test suite, and the second
2163// parameter is the name of the test within the test suite.
2164//
2165// The convention is to end the test suite name with "Test". For
2166// example, a test suite for the Foo class can be named FooTest.
2167//
2168// Test code should appear between braces after an invocation of
2169// this macro. Example:
2170//
2171// TEST(FooTest, InitializesCorrectly) {
2172// Foo foo;
2173// EXPECT_TRUE(foo.StatusIsOK());
2174// }
2175
2176// Note that we call GetTestTypeId() instead of GetTypeId<
2177// ::testing::Test>() here to get the type ID of testing::Test. This
2178// is to work around a suspected linker bug when using Google Test as
2179// a framework on Mac OS X. The bug causes GetTypeId<
2180// ::testing::Test>() to return different values depending on whether
2181// the call is from the Google Test framework itself or from user test
2182// code. GetTestTypeId() is guaranteed to always return the same
2183// value, as it always calls GetTypeId<>() from the Google Test
2184// framework.
2185#define GTEST_TEST(test_suite_name, test_name)static_assert(sizeof("test_suite_name") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("test_name") > 1, "test_name must not be empty"
); class test_suite_name_test_name_Test : public ::testing::Test
{ public: test_suite_name_test_name_Test() = default; ~test_suite_name_test_name_Test
() override = default; test_suite_name_test_name_Test (const test_suite_name_test_name_Test
&) = delete; test_suite_name_test_name_Test & operator
=( const test_suite_name_test_name_Test &) = delete; test_suite_name_test_name_Test
(test_suite_name_test_name_Test &&) noexcept = delete
; test_suite_name_test_name_Test & operator=( test_suite_name_test_name_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const test_suite_name_test_name_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "test_suite_name"
, "test_name", nullptr, nullptr, ::testing::internal::CodeLocation
("/usr/src/googletest/googletest/include/gtest/gtest.h", 2185
), (::testing::internal::GetTestTypeId()), ::testing::internal
::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite
("/usr/src/googletest/googletest/include/gtest/gtest.h", 2185
), ::testing::internal::SuiteApiResolver< ::testing::Test>
::GetTearDownCaseOrSuite("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2185), new ::testing::internal::TestFactoryImpl<test_suite_name_test_name_Test
>); void test_suite_name_test_name_Test::TestBody()
\
2186 GTEST_TEST_(test_suite_name, test_name, ::testing::Test, \static_assert(sizeof("test_suite_name") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("test_name") > 1, "test_name must not be empty"
); class test_suite_name_test_name_Test : public ::testing::Test
{ public: test_suite_name_test_name_Test() = default; ~test_suite_name_test_name_Test
() override = default; test_suite_name_test_name_Test (const test_suite_name_test_name_Test
&) = delete; test_suite_name_test_name_Test & operator
=( const test_suite_name_test_name_Test &) = delete; test_suite_name_test_name_Test
(test_suite_name_test_name_Test &&) noexcept = delete
; test_suite_name_test_name_Test & operator=( test_suite_name_test_name_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const test_suite_name_test_name_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "test_suite_name"
, "test_name", nullptr, nullptr, ::testing::internal::CodeLocation
("/usr/src/googletest/googletest/include/gtest/gtest.h", 2187
), (::testing::internal::GetTestTypeId()), ::testing::internal
::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite
("/usr/src/googletest/googletest/include/gtest/gtest.h", 2187
), ::testing::internal::SuiteApiResolver< ::testing::Test>
::GetTearDownCaseOrSuite("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2187), new ::testing::internal::TestFactoryImpl<test_suite_name_test_name_Test
>); void test_suite_name_test_name_Test::TestBody()
2187 ::testing::internal::GetTestTypeId())static_assert(sizeof("test_suite_name") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("test_name") > 1, "test_name must not be empty"
); class test_suite_name_test_name_Test : public ::testing::Test
{ public: test_suite_name_test_name_Test() = default; ~test_suite_name_test_name_Test
() override = default; test_suite_name_test_name_Test (const test_suite_name_test_name_Test
&) = delete; test_suite_name_test_name_Test & operator
=( const test_suite_name_test_name_Test &) = delete; test_suite_name_test_name_Test
(test_suite_name_test_name_Test &&) noexcept = delete
; test_suite_name_test_name_Test & operator=( test_suite_name_test_name_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const test_suite_name_test_name_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "test_suite_name"
, "test_name", nullptr, nullptr, ::testing::internal::CodeLocation
("/usr/src/googletest/googletest/include/gtest/gtest.h", 2187
), (::testing::internal::GetTestTypeId()), ::testing::internal
::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite
("/usr/src/googletest/googletest/include/gtest/gtest.h", 2187
), ::testing::internal::SuiteApiResolver< ::testing::Test>
::GetTearDownCaseOrSuite("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2187), new ::testing::internal::TestFactoryImpl<test_suite_name_test_name_Test
>); void test_suite_name_test_name_Test::TestBody()
2188
2189// Define this macro to 1 to omit the definition of TEST(), which
2190// is a generic name and clashes with some other libraries.
2191#if !(defined(GTEST_DONT_DEFINE_TEST) && GTEST_DONT_DEFINE_TEST)
2192#define TEST(test_suite_name, test_name)static_assert(sizeof("test_suite_name") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("test_name") > 1, "test_name must not be empty"
); class test_suite_name_test_name_Test : public ::testing::Test
{ public: test_suite_name_test_name_Test() = default; ~test_suite_name_test_name_Test
() override = default; test_suite_name_test_name_Test (const test_suite_name_test_name_Test
&) = delete; test_suite_name_test_name_Test & operator
=( const test_suite_name_test_name_Test &) = delete; test_suite_name_test_name_Test
(test_suite_name_test_name_Test &&) noexcept = delete
; test_suite_name_test_name_Test & operator=( test_suite_name_test_name_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const test_suite_name_test_name_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "test_suite_name"
, "test_name", nullptr, nullptr, ::testing::internal::CodeLocation
("/usr/src/googletest/googletest/include/gtest/gtest.h", 2192
), (::testing::internal::GetTestTypeId()), ::testing::internal
::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite
("/usr/src/googletest/googletest/include/gtest/gtest.h", 2192
), ::testing::internal::SuiteApiResolver< ::testing::Test>
::GetTearDownCaseOrSuite("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2192), new ::testing::internal::TestFactoryImpl<test_suite_name_test_name_Test
>); void test_suite_name_test_name_Test::TestBody()
GTEST_TEST(test_suite_name, test_name)static_assert(sizeof("test_suite_name") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("test_name") > 1, "test_name must not be empty"
); class test_suite_name_test_name_Test : public ::testing::Test
{ public: test_suite_name_test_name_Test() = default; ~test_suite_name_test_name_Test
() override = default; test_suite_name_test_name_Test (const test_suite_name_test_name_Test
&) = delete; test_suite_name_test_name_Test & operator
=( const test_suite_name_test_name_Test &) = delete; test_suite_name_test_name_Test
(test_suite_name_test_name_Test &&) noexcept = delete
; test_suite_name_test_name_Test & operator=( test_suite_name_test_name_Test
&&) noexcept = delete; private: void TestBody() override
; [[maybe_unused]] static ::testing::TestInfo* const test_info_
; }; ::testing::TestInfo* const test_suite_name_test_name_Test
::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "test_suite_name"
, "test_name", nullptr, nullptr, ::testing::internal::CodeLocation
("/usr/src/googletest/googletest/include/gtest/gtest.h", 2192
), (::testing::internal::GetTestTypeId()), ::testing::internal
::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite
("/usr/src/googletest/googletest/include/gtest/gtest.h", 2192
), ::testing::internal::SuiteApiResolver< ::testing::Test>
::GetTearDownCaseOrSuite("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2192), new ::testing::internal::TestFactoryImpl<test_suite_name_test_name_Test
>); void test_suite_name_test_name_Test::TestBody()
2193#endif
2194
2195// Defines a test that uses a test fixture.
2196//
2197// The first parameter is the name of the test fixture class, which
2198// also doubles as the test suite name. The second parameter is the
2199// name of the test within the test suite.
2200//
2201// A test fixture class must be declared earlier. The user should put
2202// the test code between braces after using this macro. Example:
2203//
2204// class FooTest : public testing::Test {
2205// protected:
2206// void SetUp() override { b_.AddElement(3); }
2207//
2208// Foo a_;
2209// Foo b_;
2210// };
2211//
2212// TEST_F(FooTest, InitializesCorrectly) {
2213// EXPECT_TRUE(a_.StatusIsOK());
2214// }
2215//
2216// TEST_F(FooTest, ReturnsElementCountCorrectly) {
2217// EXPECT_EQ(a_.size(), 0);
2218// EXPECT_EQ(b_.size(), 1);
2219// }
2220#define GTEST_TEST_F(test_fixture, test_name)static_assert(sizeof("test_fixture") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("test_name") > 1, "test_name must not be empty"
); class test_fixture_test_name_Test : public test_fixture { public
: test_fixture_test_name_Test() = default; ~test_fixture_test_name_Test
() override = default; test_fixture_test_name_Test (const test_fixture_test_name_Test
&) = delete; test_fixture_test_name_Test & operator=
( const test_fixture_test_name_Test &) = delete; test_fixture_test_name_Test
(test_fixture_test_name_Test &&) noexcept = delete; test_fixture_test_name_Test
& operator=( test_fixture_test_name_Test &&) noexcept
= delete; private: void TestBody() override; [[maybe_unused]
] static ::testing::TestInfo* const test_info_; }; ::testing::
TestInfo* const test_fixture_test_name_Test::test_info_ = ::testing
::internal::MakeAndRegisterTestInfo( "test_fixture", "test_name"
, nullptr, nullptr, ::testing::internal::CodeLocation("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2220), (::testing::internal::GetTypeId<test_fixture>(
)), ::testing::internal::SuiteApiResolver< test_fixture>
::GetSetUpCaseOrSuite("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2220), ::testing::internal::SuiteApiResolver< test_fixture
>::GetTearDownCaseOrSuite("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2220), new ::testing::internal::TestFactoryImpl<test_fixture_test_name_Test
>); void test_fixture_test_name_Test::TestBody()
\
2221 GTEST_TEST_(test_fixture, test_name, test_fixture, \static_assert(sizeof("test_fixture") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("test_name") > 1, "test_name must not be empty"
); class test_fixture_test_name_Test : public test_fixture { public
: test_fixture_test_name_Test() = default; ~test_fixture_test_name_Test
() override = default; test_fixture_test_name_Test (const test_fixture_test_name_Test
&) = delete; test_fixture_test_name_Test & operator=
( const test_fixture_test_name_Test &) = delete; test_fixture_test_name_Test
(test_fixture_test_name_Test &&) noexcept = delete; test_fixture_test_name_Test
& operator=( test_fixture_test_name_Test &&) noexcept
= delete; private: void TestBody() override; [[maybe_unused]
] static ::testing::TestInfo* const test_info_; }; ::testing::
TestInfo* const test_fixture_test_name_Test::test_info_ = ::testing
::internal::MakeAndRegisterTestInfo( "test_fixture", "test_name"
, nullptr, nullptr, ::testing::internal::CodeLocation("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2222), (::testing::internal::GetTypeId<test_fixture>(
)), ::testing::internal::SuiteApiResolver< test_fixture>
::GetSetUpCaseOrSuite("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2222), ::testing::internal::SuiteApiResolver< test_fixture
>::GetTearDownCaseOrSuite("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2222), new ::testing::internal::TestFactoryImpl<test_fixture_test_name_Test
>); void test_fixture_test_name_Test::TestBody()
2222 ::testing::internal::GetTypeId<test_fixture>())static_assert(sizeof("test_fixture") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("test_name") > 1, "test_name must not be empty"
); class test_fixture_test_name_Test : public test_fixture { public
: test_fixture_test_name_Test() = default; ~test_fixture_test_name_Test
() override = default; test_fixture_test_name_Test (const test_fixture_test_name_Test
&) = delete; test_fixture_test_name_Test & operator=
( const test_fixture_test_name_Test &) = delete; test_fixture_test_name_Test
(test_fixture_test_name_Test &&) noexcept = delete; test_fixture_test_name_Test
& operator=( test_fixture_test_name_Test &&) noexcept
= delete; private: void TestBody() override; [[maybe_unused]
] static ::testing::TestInfo* const test_info_; }; ::testing::
TestInfo* const test_fixture_test_name_Test::test_info_ = ::testing
::internal::MakeAndRegisterTestInfo( "test_fixture", "test_name"
, nullptr, nullptr, ::testing::internal::CodeLocation("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2222), (::testing::internal::GetTypeId<test_fixture>(
)), ::testing::internal::SuiteApiResolver< test_fixture>
::GetSetUpCaseOrSuite("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2222), ::testing::internal::SuiteApiResolver< test_fixture
>::GetTearDownCaseOrSuite("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2222), new ::testing::internal::TestFactoryImpl<test_fixture_test_name_Test
>); void test_fixture_test_name_Test::TestBody()
2223#if !(defined(GTEST_DONT_DEFINE_TEST_F) && GTEST_DONT_DEFINE_TEST_F)
2224#define TEST_F(test_fixture, test_name)static_assert(sizeof("test_fixture") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("test_name") > 1, "test_name must not be empty"
); class test_fixture_test_name_Test : public test_fixture { public
: test_fixture_test_name_Test() = default; ~test_fixture_test_name_Test
() override = default; test_fixture_test_name_Test (const test_fixture_test_name_Test
&) = delete; test_fixture_test_name_Test & operator=
( const test_fixture_test_name_Test &) = delete; test_fixture_test_name_Test
(test_fixture_test_name_Test &&) noexcept = delete; test_fixture_test_name_Test
& operator=( test_fixture_test_name_Test &&) noexcept
= delete; private: void TestBody() override; [[maybe_unused]
] static ::testing::TestInfo* const test_info_; }; ::testing::
TestInfo* const test_fixture_test_name_Test::test_info_ = ::testing
::internal::MakeAndRegisterTestInfo( "test_fixture", "test_name"
, nullptr, nullptr, ::testing::internal::CodeLocation("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2224), (::testing::internal::GetTypeId<test_fixture>(
)), ::testing::internal::SuiteApiResolver< test_fixture>
::GetSetUpCaseOrSuite("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2224), ::testing::internal::SuiteApiResolver< test_fixture
>::GetTearDownCaseOrSuite("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2224), new ::testing::internal::TestFactoryImpl<test_fixture_test_name_Test
>); void test_fixture_test_name_Test::TestBody()
GTEST_TEST_F(test_fixture, test_name)static_assert(sizeof("test_fixture") > 1, "test_suite_name must not be empty"
); static_assert(sizeof("test_name") > 1, "test_name must not be empty"
); class test_fixture_test_name_Test : public test_fixture { public
: test_fixture_test_name_Test() = default; ~test_fixture_test_name_Test
() override = default; test_fixture_test_name_Test (const test_fixture_test_name_Test
&) = delete; test_fixture_test_name_Test & operator=
( const test_fixture_test_name_Test &) = delete; test_fixture_test_name_Test
(test_fixture_test_name_Test &&) noexcept = delete; test_fixture_test_name_Test
& operator=( test_fixture_test_name_Test &&) noexcept
= delete; private: void TestBody() override; [[maybe_unused]
] static ::testing::TestInfo* const test_info_; }; ::testing::
TestInfo* const test_fixture_test_name_Test::test_info_ = ::testing
::internal::MakeAndRegisterTestInfo( "test_fixture", "test_name"
, nullptr, nullptr, ::testing::internal::CodeLocation("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2224), (::testing::internal::GetTypeId<test_fixture>(
)), ::testing::internal::SuiteApiResolver< test_fixture>
::GetSetUpCaseOrSuite("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2224), ::testing::internal::SuiteApiResolver< test_fixture
>::GetTearDownCaseOrSuite("/usr/src/googletest/googletest/include/gtest/gtest.h"
, 2224), new ::testing::internal::TestFactoryImpl<test_fixture_test_name_Test
>); void test_fixture_test_name_Test::TestBody()
2225#endif
2226
2227// Returns a path to a temporary directory, which should be writable. It is
2228// implementation-dependent whether or not the path is terminated by the
2229// directory-separator character.
2230GTEST_API___attribute__((visibility("default"))) std::string TempDir();
2231
2232// Returns a path to a directory that contains ancillary data files that might
2233// be used by tests. It is implementation dependent whether or not the path is
2234// terminated by the directory-separator character. The directory and the files
2235// in it should be considered read-only.
2236GTEST_API___attribute__((visibility("default"))) std::string SrcDir();
2237
2238GTEST_DISABLE_MSC_WARNINGS_POP_() // 4805 4100
2239
2240// Dynamically registers a test with the framework.
2241//
2242// This is an advanced API only to be used when the `TEST` macros are
2243// insufficient. The macros should be preferred when possible, as they avoid
2244// most of the complexity of calling this function.
2245//
2246// The `factory` argument is a factory callable (move-constructible) object or
2247// function pointer that creates a new instance of the Test object. It
2248// handles ownership to the caller. The signature of the callable is
2249// `Fixture*()`, where `Fixture` is the test fixture class for the test. All
2250// tests registered with the same `test_suite_name` must return the same
2251// fixture type. This is checked at runtime.
2252//
2253// The framework will infer the fixture class from the factory and will call
2254// the `SetUpTestSuite` and `TearDownTestSuite` for it.
2255//
2256// Must be called before `RUN_ALL_TESTS()` is invoked, otherwise behavior is
2257// undefined.
2258//
2259// Use case example:
2260//
2261// class MyFixture : public ::testing::Test {
2262// public:
2263// // All of these optional, just like in regular macro usage.
2264// static void SetUpTestSuite() { ... }
2265// static void TearDownTestSuite() { ... }
2266// void SetUp() override { ... }
2267// void TearDown() override { ... }
2268// };
2269//
2270// class MyTest : public MyFixture {
2271// public:
2272// explicit MyTest(int data) : data_(data) {}
2273// void TestBody() override { ... }
2274//
2275// private:
2276// int data_;
2277// };
2278//
2279// void RegisterMyTests(const std::vector<int>& values) {
2280// for (int v : values) {
2281// ::testing::RegisterTest(
2282// "MyFixture", ("Test" + std::to_string(v)).c_str(), nullptr,
2283// std::to_string(v).c_str(),
2284// __FILE__, __LINE__,
2285// // Important to use the fixture type as the return type here.
2286// [=]() -> MyFixture* { return new MyTest(v); });
2287// }
2288// }
2289// ...
2290// int main(int argc, char** argv) {
2291// ::testing::InitGoogleTest(&argc, argv);
2292// std::vector<int> values_to_test = LoadValuesFromConfig();
2293// RegisterMyTests(values_to_test);
2294// ...
2295// return RUN_ALL_TESTS();
2296// }
2297//
2298template <int&... ExplicitParameterBarrier, typename Factory>
2299TestInfo* RegisterTest(const char* test_suite_name, const char* test_name,
2300 const char* type_param, const char* value_param,
2301 const char* file, int line, Factory factory) {
2302 using TestT = typename std::remove_pointer<decltype(factory())>::type;
2303
2304 class FactoryImpl : public internal::TestFactoryBase {
2305 public:
2306 explicit FactoryImpl(Factory f) : factory_(std::move(f)) {}
2307 Test* CreateTest() override { return factory_(); }
2308
2309 private:
2310 Factory factory_;
2311 };
2312
2313 return internal::MakeAndRegisterTestInfo(
2314 test_suite_name, test_name, type_param, value_param,
2315 internal::CodeLocation(file, line), internal::GetTypeId<TestT>(),
2316 internal::SuiteApiResolver<TestT>::GetSetUpCaseOrSuite(file, line),
2317 internal::SuiteApiResolver<TestT>::GetTearDownCaseOrSuite(file, line),
2318 new FactoryImpl{std::move(factory)});
2319}
2320
2321} // namespace testing
2322
2323// Use this function in main() to run all tests. It returns 0 if all
2324// tests are successful, or 1 otherwise.
2325//
2326// RUN_ALL_TESTS() should be invoked after the command line has been
2327// parsed by InitGoogleTest(). RUN_ALL_TESTS will tear down and delete any
2328// installed environments and should only be called once per binary.
2329//
2330// This function was formerly a macro; thus, it is in the global
2331// namespace and has an all-caps name.
2332int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT___attribute__((warn_unused_result));
2333
2334inline int RUN_ALL_TESTS() { return ::testing::UnitTest::GetInstance()->Run(); }
2335
2336GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
2337
2338#endif // GOOGLETEST_INCLUDE_GTEST_GTEST_H_