| File: | usr/src/googletest/googletest/include/gtest/gtest-assertion-result.h |
| Warning: | line 161, column 18 Assigned value is uninitialized |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | // Copyright (C) 2012-2025 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/addr_utilities.h> | |||
| 10 | #include <cc/command_interpreter.h> | |||
| 11 | #include <config/http_command_config.h> | |||
| 12 | #include <config/testutils/socket_path.h> | |||
| 13 | #include <dhcp/classify.h> | |||
| 14 | #include <dhcp/docsis3_option_defs.h> | |||
| 15 | #include <dhcp/iface_mgr.h> | |||
| 16 | #include <dhcp/libdhcp++.h> | |||
| 17 | #include <dhcp/option4_addrlst.h> | |||
| 18 | #include <dhcp/option_custom.h> | |||
| 19 | #include <dhcp/option_int.h> | |||
| 20 | #include <dhcp/testutils/iface_mgr_test_config.h> | |||
| 21 | #include <dhcp4/ctrl_dhcp4_srv.h> | |||
| 22 | #include <dhcp4/dhcp4_srv.h> | |||
| 23 | #include <dhcp4/json_config_parser.h> | |||
| 24 | #include <dhcpsrv/cfg_expiration.h> | |||
| 25 | #include <dhcpsrv/cfg_hosts.h> | |||
| 26 | #include <dhcpsrv/cfg_subnets4.h> | |||
| 27 | #include <dhcpsrv/cfgmgr.h> | |||
| 28 | #include <dhcpsrv/parsers/simple_parser4.h> | |||
| 29 | #include <dhcpsrv/subnet.h> | |||
| 30 | #include <dhcpsrv/subnet_selector.h> | |||
| 31 | #include <dhcpsrv/testutils/config_result_check.h> | |||
| 32 | #include <dhcpsrv/testutils/test_config_backend_dhcp4.h> | |||
| 33 | #include <hooks/hooks_manager.h> | |||
| 34 | #include <hooks/hooks_parser.h> | |||
| 35 | #include <process/config_ctl_info.h> | |||
| 36 | #include <stats/stats_mgr.h> | |||
| 37 | #include <testutils/gtest_utils.h> | |||
| 38 | #include <testutils/log_utils.h> | |||
| 39 | #include <testutils/test_to_element.h> | |||
| 40 | #include <util/chrono_time_utils.h> | |||
| 41 | #include <util/doubles.h> | |||
| 42 | #include <util/filesystem.h> | |||
| 43 | ||||
| 44 | #include <boost/scoped_ptr.hpp> | |||
| 45 | ||||
| 46 | #include <iostream> | |||
| 47 | #include <sstream> | |||
| 48 | #include <string> | |||
| 49 | #include <vector> | |||
| 50 | ||||
| 51 | #include <arpa/inet.h> | |||
| 52 | #include <gtest/gtest.h> | |||
| 53 | #include <unistd.h> | |||
| 54 | ||||
| 55 | #include "dhcp4_test_utils.h" | |||
| 56 | #include "get_config_unittest.h" | |||
| 57 | #include "marker_file.h" | |||
| 58 | #include "test_libraries.h" | |||
| 59 | ||||
| 60 | using namespace isc; | |||
| 61 | using namespace isc::asiolink; | |||
| 62 | using namespace isc::config; | |||
| 63 | using namespace isc::config::test; | |||
| 64 | using namespace isc::data; | |||
| 65 | using namespace isc::dhcp; | |||
| 66 | using namespace isc::dhcp::test; | |||
| 67 | using namespace isc::hooks; | |||
| 68 | using namespace isc::test; | |||
| 69 | using namespace isc::util; | |||
| 70 | using namespace std; | |||
| 71 | ||||
| 72 | namespace { | |||
| 73 | ||||
| 74 | const char* PARSER_CONFIGS[] = { | |||
| 75 | // Configuration 0: one subnet with one pool, no user contexts | |||
| 76 | "{" | |||
| 77 | " \"interfaces-config\": {" | |||
| 78 | " \"interfaces\": [\"*\" ]" | |||
| 79 | " }," | |||
| 80 | " \"valid-lifetime\": 4000," | |||
| 81 | " \"rebind-timer\": 2000," | |||
| 82 | " \"renew-timer\": 1000," | |||
| 83 | " \"subnet4\": [ {" | |||
| 84 | " \"pools\": [ " | |||
| 85 | " { \"pool\": \"192.0.2.0/28\" }" | |||
| 86 | " ]," | |||
| 87 | " \"id\": 1," | |||
| 88 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 89 | " } ]" | |||
| 90 | "}", | |||
| 91 | ||||
| 92 | // Configuration 1: one pool with empty user context | |||
| 93 | "{" | |||
| 94 | " \"interfaces-config\": {" | |||
| 95 | " \"interfaces\": [\"*\" ]" | |||
| 96 | " }," | |||
| 97 | " \"valid-lifetime\": 4000," | |||
| 98 | " \"rebind-timer\": 2000," | |||
| 99 | " \"renew-timer\": 1000," | |||
| 100 | " \"subnet4\": [ {" | |||
| 101 | " \"pools\": [ " | |||
| 102 | " { \"pool\": \"192.0.2.0/28\"," | |||
| 103 | " \"user-context\": {" | |||
| 104 | " }" | |||
| 105 | " }" | |||
| 106 | " ]," | |||
| 107 | " \"id\": 1," | |||
| 108 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 109 | " } ]" | |||
| 110 | "}", | |||
| 111 | ||||
| 112 | // Configuration 2: one pool with user context containing lw4over6 parameters | |||
| 113 | "{" | |||
| 114 | " \"interfaces-config\": {" | |||
| 115 | " \"interfaces\": [\"*\" ]" | |||
| 116 | " }," | |||
| 117 | " \"valid-lifetime\": 4000," | |||
| 118 | " \"rebind-timer\": 2000," | |||
| 119 | " \"renew-timer\": 1000," | |||
| 120 | " \"subnet4\": [ {" | |||
| 121 | " \"pools\": [ " | |||
| 122 | " { \"pool\": \"192.0.2.0/28\"," | |||
| 123 | " \"user-context\": {" | |||
| 124 | " \"integer-param\": 42," | |||
| 125 | " \"string-param\": \"Sagittarius\"," | |||
| 126 | " \"bool-param\": true" | |||
| 127 | " }" | |||
| 128 | " }" | |||
| 129 | " ]," | |||
| 130 | " \"id\": 1," | |||
| 131 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 132 | " } ]" | |||
| 133 | "}", | |||
| 134 | ||||
| 135 | // Configuration 3: one min-max pool with user context containing lw4over6 parameters | |||
| 136 | "{" | |||
| 137 | " \"interfaces-config\": {" | |||
| 138 | " \"interfaces\": [\"*\" ]" | |||
| 139 | " }," | |||
| 140 | " \"valid-lifetime\": 4000," | |||
| 141 | " \"rebind-timer\": 2000," | |||
| 142 | " \"renew-timer\": 1000," | |||
| 143 | " \"subnet4\": [ {" | |||
| 144 | " \"pools\": [ " | |||
| 145 | " { \"pool\": \"192.0.2.0 - 192.0.2.15\"," | |||
| 146 | " \"user-context\": {" | |||
| 147 | " \"integer-param\": 42," | |||
| 148 | " \"string-param\": \"Sagittarius\"," | |||
| 149 | " \"bool-param\": true" | |||
| 150 | " }" | |||
| 151 | " }" | |||
| 152 | " ]," | |||
| 153 | " \"id\": 1," | |||
| 154 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 155 | " } ]" | |||
| 156 | "}", | |||
| 157 | ||||
| 158 | // Configuration 4: two host databases | |||
| 159 | "{" | |||
| 160 | " \"interfaces-config\": {" | |||
| 161 | " \"interfaces\": [\"*\" ]" | |||
| 162 | " }," | |||
| 163 | " \"valid-lifetime\": 4000," | |||
| 164 | " \"rebind-timer\": 2000," | |||
| 165 | " \"renew-timer\": 1000," | |||
| 166 | " \"hosts-databases\": [ {" | |||
| 167 | " \"type\": \"mysql\"," | |||
| 168 | " \"name\": \"keatest1\"," | |||
| 169 | " \"user\": \"keatest\"," | |||
| 170 | " \"password\": \"keatest\"" | |||
| 171 | " },{" | |||
| 172 | " \"type\": \"mysql\"," | |||
| 173 | " \"name\": \"keatest2\"," | |||
| 174 | " \"user\": \"keatest\"," | |||
| 175 | " \"retry-on-startup\": true," | |||
| 176 | " \"password\": \"keatest\"" | |||
| 177 | " }" | |||
| 178 | " ]" | |||
| 179 | "}", | |||
| 180 | ||||
| 181 | // Configuration 5: config databases | |||
| 182 | "{ \n" | |||
| 183 | " \"interfaces-config\": { \n" | |||
| 184 | " \"interfaces\": [\"*\" ] \n" | |||
| 185 | " }, \n" | |||
| 186 | " \"valid-lifetime\": 4000, \n" | |||
| 187 | " \"rebind-timer\": 2000, \n" | |||
| 188 | " \"renew-timer\": 1000, \n" | |||
| 189 | " \"config-control\": { \n" | |||
| 190 | " \"config-fetch-wait-time\": 10, \n" | |||
| 191 | " \"config-databases\": [ { \n" | |||
| 192 | " \"type\": \"mysql\", \n" | |||
| 193 | " \"name\": \"keatest1\", \n" | |||
| 194 | " \"user\": \"keatest\", \n" | |||
| 195 | " \"password\": \"keatest\" \n" | |||
| 196 | " },{ \n" | |||
| 197 | " \"type\": \"mysql\", \n" | |||
| 198 | " \"name\": \"keatest2\", \n" | |||
| 199 | " \"user\": \"keatest\", \n" | |||
| 200 | " \"retry-on-startup\": true, \n" | |||
| 201 | " \"password\": \"keatest\" \n" | |||
| 202 | " } \n" | |||
| 203 | " ] \n" | |||
| 204 | " } \n" | |||
| 205 | "} \n", | |||
| 206 | ||||
| 207 | // Configuration 6 for comments | |||
| 208 | "{" | |||
| 209 | " \"comment\": \"A DHCPv4 server\"," | |||
| 210 | " \"interfaces-config\": {" | |||
| 211 | " \"comment\": \"Use wildcard\"," | |||
| 212 | " \"interfaces\": [ \"*\" ] }," | |||
| 213 | " \"option-def\": [ {" | |||
| 214 | " \"comment\": \"An option definition\"," | |||
| 215 | " \"name\": \"foo\"," | |||
| 216 | " \"code\": 100," | |||
| 217 | " \"type\": \"ipv4-address\"," | |||
| 218 | " \"space\": \"isc\"" | |||
| 219 | " } ]," | |||
| 220 | " \"option-data\": [ {" | |||
| 221 | " \"comment\": \"Set option value\"," | |||
| 222 | " \"name\": \"dhcp-message\"," | |||
| 223 | " \"data\": \"ABCDEF0105\"," | |||
| 224 | " \"csv-format\": false" | |||
| 225 | " } ]," | |||
| 226 | " \"client-classes\": [" | |||
| 227 | " {" | |||
| 228 | " \"comment\": \"match all\"," | |||
| 229 | " \"name\": \"all\"," | |||
| 230 | " \"test\": \"'' == ''\"" | |||
| 231 | " }," | |||
| 232 | " {" | |||
| 233 | " \"name\": \"none\"" | |||
| 234 | " }," | |||
| 235 | " {" | |||
| 236 | " \"comment\": \"a comment\"," | |||
| 237 | " \"name\": \"both\"," | |||
| 238 | " \"user-context\": {" | |||
| 239 | " \"version\": 1" | |||
| 240 | " }" | |||
| 241 | " }" | |||
| 242 | " ]," | |||
| 243 | " \"control-sockets\": [" | |||
| 244 | " {" | |||
| 245 | " \"socket-type\": \"unix\"," | |||
| 246 | " \"socket-name\": \"kea4-ctrl-socket\"," | |||
| 247 | " \"user-context\": { \"comment\": \"Indirect comment\" }" | |||
| 248 | " }," | |||
| 249 | " {" | |||
| 250 | " \"comment\": \"HTTP control socket\"," | |||
| 251 | " \"socket-type\": \"http\"," | |||
| 252 | " \"socket-address\": \"::1\"," | |||
| 253 | " \"socket-port\": 8000," | |||
| 254 | " \"http-headers\": [ {" | |||
| 255 | " \"comment\": \"HSTS header\"," | |||
| 256 | " \"name\": \"Strict-Transport-Security\"," | |||
| 257 | " \"value\": \"max-age=31536000\"" | |||
| 258 | " } ]," | |||
| 259 | " \"authentication\": {" | |||
| 260 | " \"comment\": \"basic HTTP authentication\"," | |||
| 261 | " \"type\": \"basic\"," | |||
| 262 | " \"clients\": [ {" | |||
| 263 | " \"comment\": \"admin is authorized\"," | |||
| 264 | " \"user\": \"admin\"," | |||
| 265 | " \"password\": \"foobar\"" | |||
| 266 | " } ]" | |||
| 267 | " }" | |||
| 268 | " }" | |||
| 269 | " ]," | |||
| 270 | " \"shared-networks\": [ {" | |||
| 271 | " \"comment\": \"A shared network\"," | |||
| 272 | " \"name\": \"foo\"," | |||
| 273 | " \"subnet4\": [" | |||
| 274 | " { " | |||
| 275 | " \"comment\": \"A subnet\"," | |||
| 276 | " \"subnet\": \"192.0.1.0/24\"," | |||
| 277 | " \"id\": 100," | |||
| 278 | " \"pools\": [" | |||
| 279 | " {" | |||
| 280 | " \"comment\": \"A pool\"," | |||
| 281 | " \"pool\": \"192.0.1.1-192.0.1.10\"" | |||
| 282 | " }" | |||
| 283 | " ]," | |||
| 284 | " \"reservations\": [" | |||
| 285 | " {" | |||
| 286 | " \"comment\": \"A host reservation\"," | |||
| 287 | " \"hw-address\": \"AA:BB:CC:DD:EE:FF\"," | |||
| 288 | " \"hostname\": \"foo.example.com\"," | |||
| 289 | " \"option-data\": [ {" | |||
| 290 | " \"comment\": \"An option in a reservation\"," | |||
| 291 | " \"name\": \"domain-name\"," | |||
| 292 | " \"data\": \"example.com\"" | |||
| 293 | " } ]" | |||
| 294 | " }" | |||
| 295 | " ]" | |||
| 296 | " }" | |||
| 297 | " ]" | |||
| 298 | " } ]," | |||
| 299 | " \"dhcp-ddns\": {" | |||
| 300 | " \"comment\": \"No dynamic DNS\"," | |||
| 301 | " \"enable-updates\": false" | |||
| 302 | " }" | |||
| 303 | "}" | |||
| 304 | }; | |||
| 305 | ||||
| 306 | class Dhcp4ParserTest : public LogContentTest { | |||
| 307 | protected: | |||
| 308 | // Check that no hooks libraries are loaded. This is a pre-condition for | |||
| 309 | // a number of tests, so is checked in one place. As this uses an | |||
| 310 | // ASSERT call - and it is not clear from the documentation that Gtest | |||
| 311 | // predicates can be used in a constructor - the check is placed in SetUp. | |||
| 312 | virtual void SetUp() { | |||
| 313 | std::vector<std::string> libraries = HooksManager::getLibraryNames(); | |||
| 314 | ASSERT_TRUE(libraries.empty())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(libraries.empty())) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 314, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "libraries.empty()", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 315 | } | |||
| 316 | ||||
| 317 | public: | |||
| 318 | Dhcp4ParserTest() : rcode_(-1) { | |||
| 319 | // Open port 0 means to not open any sockets. We don't want to | |||
| 320 | // deal with sockets here, just check if configuration handling | |||
| 321 | // is sane. | |||
| 322 | srv_.reset(new ControlledDhcpv4Srv(0)); | |||
| 323 | ||||
| 324 | const IfaceCollection& ifaces = IfaceMgr::instance().getIfaces(); | |||
| 325 | ||||
| 326 | // There must be some interface detected | |||
| 327 | if (ifaces.empty()) { | |||
| 328 | // We can't use ASSERT in constructor | |||
| 329 | ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 329, "Failed") = ::testing::Message() << "No interfaces detected."; | |||
| 330 | } | |||
| 331 | ||||
| 332 | valid_iface_ = (*ifaces.begin())->getName(); | |||
| 333 | bogus_iface_ = "nonexisting0"; | |||
| 334 | ||||
| 335 | if (IfaceMgr::instance().getIface(bogus_iface_)) { | |||
| 336 | ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 336, "Failed") = ::testing::Message() << "The '" << bogus_iface_ << "' exists on this system" | |||
| 337 | << " while the test assumes that it doesn't, to execute" | |||
| 338 | << " some negative scenarios. Can't continue this test."; | |||
| 339 | } | |||
| 340 | // Reset configuration for each test. | |||
| 341 | resetConfiguration(); | |||
| 342 | ||||
| 343 | resetHooksPath(); | |||
| 344 | Dhcpv4SrvTest::resetSocketPath(); | |||
| 345 | file::PathChecker::enableEnforcement(true); | |||
| 346 | } | |||
| 347 | ||||
| 348 | ~Dhcp4ParserTest() { | |||
| 349 | // Reset configuration database after each test. | |||
| 350 | resetConfiguration(); | |||
| 351 | ||||
| 352 | // ... and delete the hooks library marker files if present | |||
| 353 | static_cast<void>(remove(LOAD_MARKER_FILE)); | |||
| 354 | static_cast<void>(remove(UNLOAD_MARKER_FILE)); | |||
| 355 | ||||
| 356 | resetHooksPath(); | |||
| 357 | Dhcpv4SrvTest::resetSocketPath(); | |||
| 358 | file::PathChecker::enableEnforcement(true); | |||
| 359 | }; | |||
| 360 | ||||
| 361 | /// @brief Sets the Hooks path from which hooks can be loaded. | |||
| 362 | /// @param explicit_path path to use as the hooks path. | |||
| 363 | void setHooksTestPath(const std::string explicit_path = "") { | |||
| 364 | HooksLibrariesParser::getHooksPath(true, | |||
| 365 | (!explicit_path.empty() ? | |||
| 366 | explicit_path : DHCP4_HOOKS_TEST_PATH)); | |||
| 367 | } | |||
| 368 | ||||
| 369 | /// @brief Resets the hooks path to DEFAULT_HOOKS_PATH. | |||
| 370 | void resetHooksPath() { | |||
| 371 | HooksLibrariesParser::getHooksPath(true); | |||
| 372 | } | |||
| 373 | ||||
| 374 | // Checks if the result of DHCP server configuration has | |||
| 375 | // expected code (0 for success, other for failures). | |||
| 376 | // Also stores result in rcode_ and comment_. | |||
| 377 | void checkResult(ConstElementPtr status, int expected_code) { | |||
| 378 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 378, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 379 | comment_ = parseAnswerText(rcode_, status); | |||
| 380 | EXPECT_EQ(expected_code, rcode_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("expected_code" , "rcode_", expected_code, rcode_))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 380, gtest_ar.failure_message()) = ::testing::Message() << "error text:" << comment_->stringValue(); | |||
| 381 | } | |||
| 382 | ||||
| 383 | // Checks if the result of DHCP server configuration has | |||
| 384 | // expected code (0 for success, other for failures) and | |||
| 385 | // the text part. Also stores result in rcode_ and comment_. | |||
| 386 | void checkResult(ConstElementPtr status, int expected_code, | |||
| 387 | string expected_txt) { | |||
| 388 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 388, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 389 | comment_ = parseAnswerText(rcode_, status); | |||
| 390 | EXPECT_EQ(expected_code, rcode_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("expected_code" , "rcode_", expected_code, rcode_))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 390, gtest_ar.failure_message()) = ::testing::Message() << "error text:" << comment_->stringValue(); | |||
| 391 | ASSERT_TRUE(comment_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(comment_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 391, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "comment_", "false", "true") .c_str()) = ::testing::Message (); | |||
| 392 | ASSERT_EQ(Element::string, comment_->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("Element::string" , "comment_->getType()", Element::string, comment_->getType ()))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 392, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 393 | EXPECT_EQ(expected_txt, comment_->stringValue())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("expected_txt" , "comment_->stringValue()", expected_txt, comment_->stringValue ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 393, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 394 | } | |||
| 395 | ||||
| 396 | /// @brief Convenience method for running configuration | |||
| 397 | /// | |||
| 398 | /// This method does not throw, but signals errors using gtest macros. | |||
| 399 | /// | |||
| 400 | /// @param config text to be parsed as JSON | |||
| 401 | /// @param expected_code expected code (see cc/command_interpreter.h) | |||
| 402 | /// @param exp_error expected text error (check skipped if empty) | |||
| 403 | void configure(std::string config, int expected_code, | |||
| 404 | std::string exp_error = "") { | |||
| 405 | ConstElementPtr json; | |||
| 406 | ASSERT_NO_THROW_LOG(json = parseDHCP4(config, true)){ try { json = parseDHCP4(config, true); } catch (const std:: exception& ex) { return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 406, "Failed") = ::testing::Message() << "json = parseDHCP4(config, true)" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 406 , "Failed") = ::testing::Message() << "json = parseDHCP4(config, true)" << " threw non-std::exception"; } }; | |||
| 407 | ||||
| 408 | ConstElementPtr status; | |||
| 409 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_409; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_409; } } else gtest_label_testnothrow_409 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 409, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 410 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 410, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 411 | ||||
| 412 | int rcode; | |||
| 413 | ConstElementPtr comment = parseAnswerText(rcode, status); | |||
| 414 | ||||
| 415 | string text; | |||
| 416 | ASSERT_TRUE(comment)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(comment)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 416, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "comment", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 417 | ASSERT_NO_THROW(text = comment->stringValue())switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { text = comment->stringValue(); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_417 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_417 ; } } else gtest_label_testnothrow_417 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 417, ("Expected: " "text = comment->stringValue()" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 418 | ||||
| 419 | // Socket name too long? | |||
| 420 | bool const too_long(SocketPath::isTooLongFromConfig(json)); | |||
| 421 | if (too_long) { | |||
| 422 | EXPECT_EQ(CONTROL_RESULT_ERROR, rcode)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("CONTROL_RESULT_ERROR" , "rcode", CONTROL_RESULT_ERROR, rcode))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 422, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 423 | exp_error = "name too long"; | |||
| 424 | EXPECT_NE(std::string::npos, text.find(exp_error))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("std::string::npos" , "text.find(exp_error)", std::string::npos, text.find(exp_error )))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 424, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 425 | return; | |||
| 426 | } | |||
| 427 | ||||
| 428 | EXPECT_EQ(expected_code, rcode)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("expected_code" , "rcode", expected_code, rcode))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 428, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 429 | if (expected_code != rcode) { | |||
| 430 | std::cout << "Reported status: " << text << std::endl; | |||
| 431 | } | |||
| 432 | ||||
| 433 | if ((rcode != 0)) { | |||
| 434 | if (!exp_error.empty()) { | |||
| 435 | EXPECT_EQ(exp_error, text)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("exp_error" , "text", exp_error, text))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 435, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 436 | } | |||
| 437 | } | |||
| 438 | } | |||
| 439 | ||||
| 440 | /// @brief Returns an interface configuration used by the most of the | |||
| 441 | /// unit tests. | |||
| 442 | std::string genIfaceConfig() const { | |||
| 443 | return ("\"interfaces-config\": {" | |||
| 444 | " \"interfaces\": [ \"*\" ]" | |||
| 445 | "}"); | |||
| 446 | } | |||
| 447 | ||||
| 448 | /// @brief Create the simple configuration with single option. | |||
| 449 | /// | |||
| 450 | /// This function allows to set one of the parameters that configure | |||
| 451 | /// option value. These parameters are: "name", "code", "data", | |||
| 452 | /// "csv-format" and "space". | |||
| 453 | /// | |||
| 454 | /// @param param_value string holding option parameter value to be | |||
| 455 | /// injected into the configuration string. | |||
| 456 | /// @param parameter name of the parameter to be configured with | |||
| 457 | /// param value. | |||
| 458 | /// @return configuration string containing custom values of parameters | |||
| 459 | /// describing an option. | |||
| 460 | std::string createConfigWithOption(const std::string& param_value, | |||
| 461 | const std::string& parameter) { | |||
| 462 | std::map<std::string, std::string> params; | |||
| 463 | if (parameter == "name") { | |||
| 464 | params["name"] = param_value; | |||
| 465 | params["space"] = DHCP4_OPTION_SPACE"dhcp4"; | |||
| 466 | params["code"] = "56"; | |||
| 467 | params["data"] = "ABCDEF0105"; | |||
| 468 | params["csv-format"] = "false"; | |||
| 469 | } else if (parameter == "space") { | |||
| 470 | params["name"] = "dhcp-message"; | |||
| 471 | params["space"] = param_value; | |||
| 472 | params["code"] = "56"; | |||
| 473 | params["data"] = "ABCDEF0105"; | |||
| 474 | params["csv-format"] = "false"; | |||
| 475 | } else if (parameter == "code") { | |||
| 476 | params["name"] = "dhcp-message"; | |||
| 477 | params["space"] = DHCP4_OPTION_SPACE"dhcp4"; | |||
| 478 | params["code"] = param_value; | |||
| 479 | params["data"] = "ABCDEF0105"; | |||
| 480 | params["csv-format"] = "false"; | |||
| 481 | } else if (parameter == "data") { | |||
| 482 | params["name"] = "dhcp-message"; | |||
| 483 | params["space"] = DHCP4_OPTION_SPACE"dhcp4"; | |||
| 484 | params["code"] = "56"; | |||
| 485 | params["data"] = param_value; | |||
| 486 | params["csv-format"] = "false"; | |||
| 487 | } else if (parameter == "csv-format") { | |||
| 488 | params["name"] = "dhcp-message"; | |||
| 489 | params["space"] = DHCP4_OPTION_SPACE"dhcp4"; | |||
| 490 | params["code"] = "56"; | |||
| 491 | params["data"] = "ABCDEF0105"; | |||
| 492 | params["csv-format"] = param_value; | |||
| 493 | } | |||
| 494 | return (createConfigWithOption(params)); | |||
| 495 | } | |||
| 496 | ||||
| 497 | /// @brief Create simple configuration with single option. | |||
| 498 | /// | |||
| 499 | /// This function creates a configuration for a single option with | |||
| 500 | /// custom values for all parameters that describe the option. | |||
| 501 | /// | |||
| 502 | /// @params params map holding parameters and their values. | |||
| 503 | /// @return configuration string containing custom values of parameters | |||
| 504 | /// describing an option. | |||
| 505 | std::string createConfigWithOption(const std::map<std::string, | |||
| 506 | std::string>& params) { | |||
| 507 | std::ostringstream stream; | |||
| 508 | stream << "{ " << genIfaceConfig() << "," << | |||
| 509 | "\"rebind-timer\": 2000, " | |||
| 510 | "\"renew-timer\": 1000, " | |||
| 511 | "\"subnet4\": [ { " | |||
| 512 | " \"id\": 1," | |||
| 513 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 514 | " \"subnet\": \"192.0.2.0/24\", " | |||
| 515 | " \"option-data\": [ {"; | |||
| 516 | bool first = true; | |||
| 517 | for (auto const& param : params) { | |||
| 518 | if (!first) { | |||
| 519 | stream << ", "; | |||
| 520 | } else { | |||
| 521 | // cppcheck-suppress unreadVariable | |||
| 522 | first = false; | |||
| 523 | } | |||
| 524 | if (param.first == "name") { | |||
| 525 | stream << "\"name\": \"" << param.second << "\""; | |||
| 526 | } else if (param.first == "space") { | |||
| 527 | stream << "\"space\": \"" << param.second << "\""; | |||
| 528 | } else if (param.first == "code") { | |||
| 529 | stream << "\"code\": " << param.second; | |||
| 530 | } else if (param.first == "data") { | |||
| 531 | stream << "\"data\": \"" << param.second << "\""; | |||
| 532 | } else if (param.first == "csv-format") { | |||
| 533 | stream << "\"csv-format\": " << param.second; | |||
| 534 | } | |||
| 535 | } | |||
| 536 | stream << | |||
| 537 | " } ]" | |||
| 538 | " } ]," | |||
| 539 | "\"valid-lifetime\": 4000 }"; | |||
| 540 | return (stream.str()); | |||
| 541 | } | |||
| 542 | ||||
| 543 | /// @brief Returns an option from the subnet. | |||
| 544 | /// | |||
| 545 | /// This function returns an option from a subnet to which the | |||
| 546 | /// specified subnet address belongs. The option is identified | |||
| 547 | /// by its code. | |||
| 548 | /// | |||
| 549 | /// @param subnet_address Address which belongs to the subnet from | |||
| 550 | /// which the option is to be returned. | |||
| 551 | /// @param option_code Code of the option to be returned. | |||
| 552 | /// @param expected_options_count Expected number of options in | |||
| 553 | /// the particular subnet. | |||
| 554 | /// | |||
| 555 | /// @return Descriptor of the option. If the descriptor holds a | |||
| 556 | /// NULL option pointer, it means that there was no such option | |||
| 557 | /// in the subnet. | |||
| 558 | OptionDescriptor | |||
| 559 | getOptionFromSubnet(const IOAddress& subnet_address, | |||
| 560 | const uint16_t option_code, | |||
| 561 | const uint16_t expected_options_count = 1) { | |||
| 562 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 563 | getCfgSubnets4()->selectSubnet(subnet_address); | |||
| 564 | if (!subnet) { | |||
| 565 | ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 565, "Failed") = ::testing::Message() << "A subnet for the specified address " | |||
| 566 | << subnet_address | |||
| 567 | << " does not exist in Config Manager"; | |||
| 568 | return (OptionDescriptor(false, false)); | |||
| 569 | } | |||
| 570 | OptionContainerPtr options = | |||
| 571 | subnet->getCfgOption()->getAll(DHCP4_OPTION_SPACE"dhcp4"); | |||
| 572 | if (expected_options_count != options->size()) { | |||
| 573 | ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 573, "Failed") = ::testing::Message() << "The number of options in the subnet '" | |||
| 574 | << subnet_address.toText() << "' is different " | |||
| 575 | " than expected number of options '" | |||
| 576 | << expected_options_count << "'"; | |||
| 577 | } | |||
| 578 | ||||
| 579 | // Get the search index. Index #1 is to search using option code. | |||
| 580 | const OptionContainerTypeIndex& idx = options->get<1>(); | |||
| 581 | ||||
| 582 | // Get the options for specified index. Expecting one option to be | |||
| 583 | // returned but in theory we may have multiple options with the same | |||
| 584 | // code so we get the range. | |||
| 585 | std::pair<OptionContainerTypeIndex::const_iterator, | |||
| 586 | OptionContainerTypeIndex::const_iterator> range = | |||
| 587 | idx.equal_range(option_code); | |||
| 588 | if (std::distance(range.first, range.second) > 1) { | |||
| 589 | ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 589, "Failed") = ::testing::Message() << "There is more than one option having the" | |||
| 590 | " option code '" << option_code << "' in a subnet '" | |||
| 591 | << subnet_address.toText() << "'. Expected " | |||
| 592 | " at most one option"; | |||
| 593 | } else if (std::distance(range.first, range.second) == 0) { | |||
| 594 | return (OptionDescriptor(OptionPtr(), false, false)); | |||
| 595 | } | |||
| 596 | ||||
| 597 | return (*range.first); | |||
| 598 | } | |||
| 599 | ||||
| 600 | /// @brief Test invalid option parameter value. | |||
| 601 | /// | |||
| 602 | /// This test function constructs the simple configuration | |||
| 603 | /// string and injects invalid option configuration into it. | |||
| 604 | /// It expects that parser will fail with provided option code. | |||
| 605 | /// | |||
| 606 | /// @param param_value string holding invalid option parameter value | |||
| 607 | /// to be injected into configuration string. | |||
| 608 | /// @param parameter name of the parameter to be configured with | |||
| 609 | /// param_value (can be any of "name", "code", "data") | |||
| 610 | void testInvalidOptionParam(const std::string& param_value, | |||
| 611 | const std::string& parameter) { | |||
| 612 | ConstElementPtr x; | |||
| 613 | std::string config = createConfigWithOption(param_value, parameter); | |||
| 614 | ConstElementPtr json = parseDHCP4(config); | |||
| 615 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_615; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_615; } } else gtest_label_testnothrow_615 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 615, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 616 | checkResult(x, 1); | |||
| 617 | EXPECT_TRUE(errorContainsPosition(x, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (x, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 617, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(x, \"<string>\")", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 618 | CfgMgr::instance().clear(); | |||
| 619 | } | |||
| 620 | ||||
| 621 | /// @brief Test invalid option parameter value. | |||
| 622 | /// | |||
| 623 | /// This test function constructs the simple configuration | |||
| 624 | /// string and injects invalid option configuration into it. | |||
| 625 | /// It expects that parser will fail with provided option code. | |||
| 626 | /// | |||
| 627 | /// @param params Map of parameters defining an option. | |||
| 628 | void | |||
| 629 | testInvalidOptionParam(const std::map<std::string, std::string>& params) { | |||
| 630 | ConstElementPtr x; | |||
| 631 | std::string config = createConfigWithOption(params); | |||
| 632 | ConstElementPtr json = parseDHCP4(config); | |||
| 633 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_633; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_633; } } else gtest_label_testnothrow_633 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 633, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 634 | checkResult(x, 1); | |||
| 635 | EXPECT_TRUE(errorContainsPosition(x, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (x, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 635, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(x, \"<string>\")", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 636 | CfgMgr::instance().clear(); | |||
| 637 | } | |||
| 638 | ||||
| 639 | /// @brief Test option against given code and data. | |||
| 640 | /// | |||
| 641 | /// @param option_desc option descriptor that carries the option to | |||
| 642 | /// be tested. | |||
| 643 | /// @param expected_code expected code of the option. | |||
| 644 | /// @param expected_data expected data in the option. | |||
| 645 | /// @param expected_data_len length of the reference data. | |||
| 646 | /// @param extra_data if true extra data is allowed in an option | |||
| 647 | /// after tested data. | |||
| 648 | void testOption(const OptionDescriptor& option_desc, | |||
| 649 | uint16_t expected_code, const uint8_t* expected_data, | |||
| 650 | size_t expected_data_len, | |||
| 651 | bool extra_data = false) { | |||
| 652 | // Check if option descriptor contains valid option pointer. | |||
| 653 | ASSERT_TRUE(option_desc.option_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(option_desc.option_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 653, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "option_desc.option_", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 654 | // Verify option type. | |||
| 655 | EXPECT_EQ(expected_code, option_desc.option_->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("expected_code" , "option_desc.option_->getType()", expected_code, option_desc .option_->getType()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 655, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 656 | // We may have many different option types being created. Some of them | |||
| 657 | // have dedicated classes derived from Option class. In such case if | |||
| 658 | // we want to verify the option contents against expected_data we have | |||
| 659 | // to prepare raw buffer with the contents of the option. The easiest | |||
| 660 | // way is to call pack() which will prepare on-wire data. | |||
| 661 | util::OutputBuffer buf(option_desc.option_->getData().size()); | |||
| 662 | option_desc.option_->pack(buf); | |||
| 663 | if (extra_data) { | |||
| 664 | // The length of the buffer must be at least equal to size of the | |||
| 665 | // reference data but it can sometimes be greater than that. This is | |||
| 666 | // because some options carry suboptions that increase the overall | |||
| 667 | // length. | |||
| 668 | ASSERT_GE(buf.getLength() - option_desc.option_->getHeaderLen(),switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperGE("buf.getLength() - option_desc.option_->getHeaderLen()" , "expected_data_len", buf.getLength() - option_desc.option_-> getHeaderLen(), expected_data_len))) ; else return ::testing:: internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 669 , gtest_ar.failure_message()) = ::testing::Message() | |||
| 669 | expected_data_len)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperGE("buf.getLength() - option_desc.option_->getHeaderLen()" , "expected_data_len", buf.getLength() - option_desc.option_-> getHeaderLen(), expected_data_len))) ; else return ::testing:: internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 669 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 670 | } else { | |||
| 671 | ASSERT_EQ(buf.getLength() - option_desc.option_->getHeaderLen(),switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("buf.getLength() - option_desc.option_->getHeaderLen()" , "expected_data_len", buf.getLength() - option_desc.option_-> getHeaderLen(), expected_data_len))) ; else return ::testing:: internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 672 , gtest_ar.failure_message()) = ::testing::Message() | |||
| 672 | expected_data_len)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("buf.getLength() - option_desc.option_->getHeaderLen()" , "expected_data_len", buf.getLength() - option_desc.option_-> getHeaderLen(), expected_data_len))) ; else return ::testing:: internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 672 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 673 | } | |||
| 674 | // Verify that the data is correct. Do not verify suboptions and a header. | |||
| 675 | const uint8_t* data = buf.getData(); | |||
| 676 | EXPECT_EQ(0, memcmp(expected_data,switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "memcmp(expected_data, data + option_desc.option_->getHeaderLen(), expected_data_len)" , 0, memcmp(expected_data, data + option_desc.option_->getHeaderLen (), expected_data_len)))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 678, gtest_ar.failure_message()) = ::testing::Message() | |||
| 677 | data + option_desc.option_->getHeaderLen(),switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "memcmp(expected_data, data + option_desc.option_->getHeaderLen(), expected_data_len)" , 0, memcmp(expected_data, data + option_desc.option_->getHeaderLen (), expected_data_len)))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 678, gtest_ar.failure_message()) = ::testing::Message() | |||
| 678 | expected_data_len))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "memcmp(expected_data, data + option_desc.option_->getHeaderLen(), expected_data_len)" , 0, memcmp(expected_data, data + option_desc.option_->getHeaderLen (), expected_data_len)))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 678, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 679 | } | |||
| 680 | ||||
| 681 | /// @brief Test option configuration. | |||
| 682 | /// | |||
| 683 | /// This function creates a configuration for a specified option using | |||
| 684 | /// a map of parameters specified as the argument. The map holds | |||
| 685 | /// name/value pairs which identifies option's configuration parameters: | |||
| 686 | /// - name | |||
| 687 | /// - space | |||
| 688 | /// - code | |||
| 689 | /// - data | |||
| 690 | /// - csv-format. | |||
| 691 | /// This function applies a new server configuration and checks that the | |||
| 692 | /// option being configured is inserted into CfgMgr. The raw contents of | |||
| 693 | /// this option are compared with the binary data specified as expected | |||
| 694 | /// data passed to this function. | |||
| 695 | /// | |||
| 696 | /// @param params Map of parameters defining an option. | |||
| 697 | /// @param option_code Option code. | |||
| 698 | /// @param expected_data Array containing binary data expected to be stored | |||
| 699 | /// in the configured option. | |||
| 700 | /// @param expected_data_len Length of the array holding reference data. | |||
| 701 | void testConfiguration(const std::map<std::string, std::string>& params, | |||
| 702 | const uint16_t option_code, | |||
| 703 | const uint8_t* expected_data, | |||
| 704 | const size_t expected_data_len) { | |||
| 705 | CfgMgr::instance().clear(); | |||
| 706 | ||||
| 707 | std::string config = createConfigWithOption(params); | |||
| 708 | ASSERT_TRUE(executeConfiguration(config, "parse option configuration"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(executeConfiguration( config, "parse option configuration"))) ; else return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 708 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "executeConfiguration(config, \"parse option configuration\")" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 709 | ||||
| 710 | // The subnet should now hold one option with the specified option code. | |||
| 711 | OptionDescriptor desc = | |||
| 712 | getOptionFromSubnet(IOAddress("192.0.2.24"), option_code); | |||
| 713 | ASSERT_TRUE(desc.option_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(desc.option_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 713, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "desc.option_", "false", "true") .c_str()) = ::testing::Message (); | |||
| 714 | testOption(desc, option_code, expected_data, expected_data_len); | |||
| 715 | CfgMgr::instance().clear(); | |||
| 716 | } | |||
| 717 | ||||
| 718 | /// @brief Parse and Execute configuration | |||
| 719 | /// | |||
| 720 | /// Parses a configuration and executes a configuration of the server. | |||
| 721 | /// If the operation fails, the current test will register a failure. | |||
| 722 | /// | |||
| 723 | /// @param config Configuration to parse | |||
| 724 | /// @param operation Operation being performed. In the case of an error, | |||
| 725 | /// the error text will include the string "unable to <operation>.". | |||
| 726 | /// | |||
| 727 | /// @return true if the configuration succeeded, false if not. In the | |||
| 728 | /// latter case, a failure will have been added to the current test. | |||
| 729 | bool | |||
| 730 | executeConfiguration(const std::string& config, const char* operation) { | |||
| 731 | CfgMgr::instance().clear(); | |||
| 732 | ConstElementPtr json; | |||
| 733 | ConstElementPtr status; | |||
| 734 | try { | |||
| 735 | json = parseJSON(config); | |||
| 736 | status = Dhcpv4SrvTest::configure(*srv_, json); | |||
| 737 | } catch (const std::exception& ex) { | |||
| 738 | ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 738, "Failed") = ::testing::Message() << "Unable to " << operation << ". " | |||
| 739 | << "The following configuration was used: " << std::endl | |||
| 740 | << config << std::endl | |||
| 741 | << " and the following error message was returned:" | |||
| 742 | << ex.what() << std::endl; | |||
| 743 | return (false); | |||
| 744 | } | |||
| 745 | ||||
| 746 | // The status object must not be NULL | |||
| 747 | if (!status) { | |||
| 748 | ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 748, "Failed") = ::testing::Message() << "Unable to " << operation << ". " | |||
| 749 | << "The configuration function returned a null pointer."; | |||
| 750 | return (false); | |||
| 751 | } | |||
| 752 | ||||
| 753 | // Store the answer if we need it. | |||
| 754 | ||||
| 755 | // Returned value should be 0 (configuration success) | |||
| 756 | comment_ = parseAnswerText(rcode_, status); | |||
| 757 | if (rcode_ != 0) { | |||
| 758 | string reason = ""; | |||
| 759 | if (comment_) { | |||
| 760 | reason = string(" (") + comment_->stringValue() + string(")"); | |||
| 761 | } | |||
| 762 | ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 762, "Failed") = ::testing::Message() << "Unable to " << operation << ". " | |||
| 763 | << "The configuration function returned error code " | |||
| 764 | << rcode_ << reason; | |||
| 765 | return (false); | |||
| 766 | } | |||
| 767 | ||||
| 768 | return (true); | |||
| 769 | } | |||
| 770 | ||||
| 771 | /// @brief Reset configuration database. | |||
| 772 | /// | |||
| 773 | /// This function resets configuration data base by removing all subnets | |||
| 774 | /// option-data, and hooks libraries. The reset must be performed after each | |||
| 775 | /// test to make sure that contents of the database do not affect the | |||
| 776 | /// results of subsequent tests. | |||
| 777 | void resetConfiguration() { | |||
| 778 | // The default setting is to listen on all interfaces. In order to | |||
| 779 | // properly test interface configuration we disable listening on | |||
| 780 | // all interfaces before each test and later check that this setting | |||
| 781 | // has been overridden by the configuration used in the test. | |||
| 782 | CfgMgr::instance().clear(); | |||
| 783 | string config = "{ \"interfaces-config\": {" | |||
| 784 | " \"interfaces\": [ ]" | |||
| 785 | "}," | |||
| 786 | "\"hooks-libraries\": [ ]," | |||
| 787 | "\"rebind-timer\": 2000, " | |||
| 788 | "\"renew-timer\": 1000, " | |||
| 789 | "\"valid-lifetime\": 4000, " | |||
| 790 | "\"subnet4\": [ ], " | |||
| 791 | "\"dhcp-ddns\": { \"enable-updates\" : false }, " | |||
| 792 | "\"option-def\": [ ], " | |||
| 793 | "\"option-data\": [ ] }"; | |||
| 794 | static_cast<void>(executeConfiguration(config, | |||
| 795 | "reset configuration database")); | |||
| 796 | CfgMgr::instance().clearStagingConfiguration(); | |||
| 797 | } | |||
| 798 | ||||
| 799 | /// @brief Retrieve an option associated with a host. | |||
| 800 | /// | |||
| 801 | /// The option is retrieved from the "dhcp4" option space. | |||
| 802 | /// | |||
| 803 | /// @param host Reference to a host for which an option should be retrieved. | |||
| 804 | /// @param option_code Option code. | |||
| 805 | /// @tparam ReturnType Type of the pointer object returned. | |||
| 806 | /// | |||
| 807 | /// @return Pointer to an option or NULL pointer if not found. | |||
| 808 | template<typename ReturnType> | |||
| 809 | ReturnType | |||
| 810 | retrieveOption(const Host& host, const uint16_t option_code) const { | |||
| 811 | return (retrieveOption<ReturnType>(host, DHCP4_OPTION_SPACE"dhcp4", option_code)); | |||
| 812 | } | |||
| 813 | ||||
| 814 | /// @brief Retrieve an option associated with a host. | |||
| 815 | /// | |||
| 816 | /// @param host Reference to a host for which an option should be retrieved. | |||
| 817 | /// @param space Option space from which option should be retrieved. | |||
| 818 | /// @param option_code Option code. | |||
| 819 | /// @tparam ReturnType Type of the pointer object returned. | |||
| 820 | /// | |||
| 821 | /// @return Pointer to an option or NULL pointer if not found. | |||
| 822 | template<typename ReturnType> | |||
| 823 | ReturnType | |||
| 824 | retrieveOption(const Host& host, const std::string& space, | |||
| 825 | const uint16_t option_code) const { | |||
| 826 | ConstCfgOptionPtr cfg_option = host.getCfgOption4(); | |||
| 827 | if (cfg_option) { | |||
| 828 | OptionDescriptor opt_desc = cfg_option->get(space, option_code); | |||
| 829 | if (opt_desc.option_) { | |||
| 830 | return (boost::dynamic_pointer_cast< | |||
| 831 | typename ReturnType::element_type>(opt_desc.option_)); | |||
| 832 | } | |||
| 833 | } | |||
| 834 | return (ReturnType()); | |||
| 835 | } | |||
| 836 | ||||
| 837 | /// @brief Checks if specified subnet is part of the collection | |||
| 838 | /// | |||
| 839 | /// @tparam CollectionType type of subnet4 collections i.e. | |||
| 840 | /// either Subnet4SimpleCollection or Subnet4Collection | |||
| 841 | /// @param col collection of subnets to be inspected | |||
| 842 | /// @param subnet text notation (e.g. 192.0.2.0/24) | |||
| 843 | /// @param t1 expected renew-timer value | |||
| 844 | /// @param t2 expected rebind-timer value | |||
| 845 | /// @param valid expected valid-lifetime value | |||
| 846 | /// @param min_valid expected min-valid-lifetime value | |||
| 847 | /// (0 (default) means same as valid) | |||
| 848 | /// @param max_valid expected max-valid-lifetime value | |||
| 849 | /// (0 (default) means same as valid) | |||
| 850 | /// @return the subnet that was examined | |||
| 851 | template <typename CollectionType> | |||
| 852 | Subnet4Ptr | |||
| 853 | checkSubnet(const CollectionType& col, std::string subnet, | |||
| 854 | uint32_t t1, uint32_t t2, uint32_t valid, | |||
| 855 | uint32_t min_valid = 0, uint32_t max_valid = 0) { | |||
| 856 | auto const& index = col.template get<SubnetPrefixIndexTag>(); | |||
| 857 | auto subnet_it = index.find(subnet); | |||
| 858 | if (subnet_it == index.cend()) { | |||
| 859 | ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 859, "Failed") = ::testing::Message() << "Unable to find expected subnet " << subnet; | |||
| 860 | return (Subnet4Ptr()); | |||
| 861 | } | |||
| 862 | Subnet4Ptr s = *subnet_it; | |||
| 863 | ||||
| 864 | EXPECT_EQ(t1, s->getT1().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("t1", "s->getT1().get()" , t1, s->getT1().get()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 864, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 865 | EXPECT_EQ(t2, s->getT2().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("t2", "s->getT2().get()" , t2, s->getT2().get()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 865, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 866 | EXPECT_EQ(valid, s->getValid().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("valid", "s->getValid().get()" , valid, s->getValid().get()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 866, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 867 | EXPECT_EQ(min_valid ? min_valid : valid, s->getValid().getMin())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("min_valid ? min_valid : valid" , "s->getValid().getMin()", min_valid ? min_valid : valid, s->getValid().getMin()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 867, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 868 | EXPECT_EQ(max_valid ? max_valid : valid, s->getValid().getMax())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("max_valid ? max_valid : valid" , "s->getValid().getMax()", max_valid ? max_valid : valid, s->getValid().getMax()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 868, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 869 | ||||
| 870 | return (s); | |||
| 871 | } | |||
| 872 | ||||
| 873 | /// @brief This utility method attempts to configure using specified | |||
| 874 | /// config and then returns requested pool from requested subnet | |||
| 875 | /// | |||
| 876 | /// @param config configuration to be applied | |||
| 877 | /// @param subnet_index index of the subnet to be returned (0 - the first subnet) | |||
| 878 | /// @param pool_index index of the pool within a subnet (0 - the first pool) | |||
| 879 | /// @param pool [out] Pool pointer will be stored here (if found) | |||
| 880 | void getPool(const std::string& config, size_t subnet_index, | |||
| 881 | size_t pool_index, PoolPtr& pool) { | |||
| 882 | ConstElementPtr status; | |||
| 883 | ConstElementPtr json; | |||
| 884 | ||||
| 885 | EXPECT_NO_THROW(json = parseDHCP4(config, true))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(config, 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_885 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_885 ; } } else gtest_label_testnothrow_885 : ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 885, ("Expected: " "json = parseDHCP4(config, true)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 886 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_886; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_886; } } else gtest_label_testnothrow_886 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 886, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 887 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 887, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 888 | checkResult(status, 0); | |||
| 889 | ||||
| 890 | ConstCfgSubnets4Ptr subnets4 = CfgMgr::instance().getStagingCfg()->getCfgSubnets4(); | |||
| 891 | ASSERT_TRUE(subnets4)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnets4)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 891, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnets4", "false", "true") .c_str()) = ::testing::Message (); | |||
| 892 | ||||
| 893 | const Subnet4Collection* subnets = subnets4->getAll(); | |||
| 894 | ASSERT_TRUE(subnets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnets)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 894, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnets", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 895 | ASSERT_GE(subnets->size(), subnet_index + 1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperGE("subnets->size()" , "subnet_index + 1", subnets->size(), subnet_index + 1))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 895, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 896 | ||||
| 897 | auto subnet = subnets->begin(); | |||
| 898 | // std::advance is not available for subnets iterators. | |||
| 899 | for (size_t i = 0; i < subnet_index; ++i) { | |||
| 900 | subnet = std::next(subnet); | |||
| 901 | } | |||
| 902 | const PoolCollection pools = (*subnet)->getPools(Lease::TYPE_V4); | |||
| 903 | ASSERT_GE(pools.size(), pool_index + 1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperGE("pools.size()", "pool_index + 1", pools.size(), pool_index + 1))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 903, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 904 | ||||
| 905 | pool = pools.at(pool_index); | |||
| 906 | EXPECT_TRUE(pool)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool)) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 906 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool", "false", "true") .c_str()) = ::testing::Message(); | |||
| 907 | } | |||
| 908 | ||||
| 909 | /// @brief Tests if the current config has a given global parameter value | |||
| 910 | /// @param name name of the global parameter expected to exist | |||
| 911 | /// @param value expected value of the global parameter | |||
| 912 | template <typename ValueType> | |||
| 913 | void checkGlobal(const std::string name, ValueType value) { | |||
| 914 | ConstElementPtr param; | |||
| 915 | ConstElementPtr exp_value; | |||
| 916 | param = CfgMgr::instance().getStagingCfg()->getConfiguredGlobal(name); | |||
| 917 | ASSERT_TRUE(param)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(param)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 917, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "param", "false", "true") .c_str()) = ::testing::Message() << "global: " << name << ", expected but not found"; | |||
| 918 | ASSERT_NO_THROW(exp_value = Element::create(value))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { exp_value = Element::create(value); } else static_assert(true , ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_918 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_918 ; } } else gtest_label_testnothrow_918 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 918, ("Expected: " "exp_value = Element::create(value)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 919 | EXPECT_TRUE(param->equals(*exp_value))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(param->equals(*exp_value ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 919, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "param->equals(*exp_value)", "false", "true") .c_str()) = ::testing::Message() << "global: " << name | |||
| 920 | << isc::data::prettyPrint(param) | |||
| 921 | << " does not match expected: " | |||
| 922 | << isc::data::prettyPrint(exp_value); | |||
| 923 | } | |||
| 924 | ||||
| 925 | int rcode_; ///< Return code from element parsing | |||
| 926 | boost::scoped_ptr<Dhcpv4Srv> srv_; ///< Instance of the Dhcpv4Srv used during tests | |||
| 927 | ConstElementPtr comment_; ///< Comment (see @ref isc::config::parseAnswer) | |||
| 928 | string valid_iface_; ///< Valid network interface name (present in system) | |||
| 929 | string bogus_iface_; ///< invalid network interface name (not in system) | |||
| 930 | isc::dhcp::ClientClasses classify_; ///< used in client classification | |||
| 931 | }; | |||
| 932 | ||||
| 933 | /// The goal of this test is to verify that the code accepts only | |||
| 934 | /// valid commands and malformed or unsupported parameters are rejected. | |||
| 935 | TEST_F(Dhcp4ParserTest, bogusCommand)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("bogusCommand") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_bogusCommand_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_bogusCommand_Test() = default; ~Dhcp4ParserTest_bogusCommand_Test () override = default; Dhcp4ParserTest_bogusCommand_Test (const Dhcp4ParserTest_bogusCommand_Test &) = delete; Dhcp4ParserTest_bogusCommand_Test & operator=( const Dhcp4ParserTest_bogusCommand_Test & ) = delete; Dhcp4ParserTest_bogusCommand_Test (Dhcp4ParserTest_bogusCommand_Test &&) noexcept = delete; Dhcp4ParserTest_bogusCommand_Test & operator=( Dhcp4ParserTest_bogusCommand_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_bogusCommand_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "bogusCommand", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 935 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 935), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 935), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_bogusCommand_Test >); void Dhcp4ParserTest_bogusCommand_Test::TestBody() { | |||
| 936 | ||||
| 937 | ConstElementPtr x; | |||
| 938 | ||||
| 939 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_,switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, parseJSON("{\"bogus\": 5}" )); } else static_assert(true, ""); } catch (std::exception const & e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg .value += "\"."; goto gtest_label_testnothrow_940; } catch (... ) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_940 ; } } else gtest_label_testnothrow_940 : ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 940, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, parseJSON(\"{\\\"bogus\\\": 5}\"))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() | |||
| 940 | parseJSON("{\"bogus\": 5}")))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, parseJSON("{\"bogus\": 5}" )); } else static_assert(true, ""); } catch (std::exception const & e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg .value += "\"."; goto gtest_label_testnothrow_940; } catch (... ) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_940 ; } } else gtest_label_testnothrow_940 : ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 940, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, parseJSON(\"{\\\"bogus\\\": 5}\"))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 941 | ||||
| 942 | // returned value must be 1 (configuration parse error) | |||
| 943 | checkResult(x, 1); | |||
| 944 | ||||
| 945 | // it should be refused by syntax too | |||
| 946 | EXPECT_THROW(parseDHCP4("{\"bogus\": 5}"), Dhcp4ParseError)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { parseDHCP4("{\"bogus\": 5}" ); } else static_assert(true, ""); } catch (Dhcp4ParseError const &) { gtest_caught_expected = true; } catch (typename std:: conditional< std::is_same<typename std::remove_cv<typename std::remove_reference< Dhcp4ParseError>::type>::type , std::exception>::value, const ::testing::internal::NeverThrown &, const std::exception&>::type e) { gtest_msg.value = "Expected: " "parseDHCP4(\"{\\\"bogus\\\": 5}\")" " throws an exception of type " "Dhcp4ParseError" ".\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_946; } catch (... ) { gtest_msg.value = "Expected: " "parseDHCP4(\"{\\\"bogus\\\": 5}\")" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_946; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "parseDHCP4(\"{\\\"bogus\\\": 5}\")" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws nothing." ; goto gtest_label_testthrow_946; } } else gtest_label_testthrow_946 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 946, gtest_msg.value.c_str()) = ::testing::Message(); | |||
| 947 | } | |||
| 948 | ||||
| 949 | /// The goal of this test is to verify empty interface-config is accepted. | |||
| 950 | TEST_F(Dhcp4ParserTest, emptyInterfaceConfig)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("emptyInterfaceConfig") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_emptyInterfaceConfig_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_emptyInterfaceConfig_Test() = default ; ~Dhcp4ParserTest_emptyInterfaceConfig_Test() override = default ; Dhcp4ParserTest_emptyInterfaceConfig_Test (const Dhcp4ParserTest_emptyInterfaceConfig_Test &) = delete; Dhcp4ParserTest_emptyInterfaceConfig_Test & operator=( const Dhcp4ParserTest_emptyInterfaceConfig_Test & ) = delete; Dhcp4ParserTest_emptyInterfaceConfig_Test (Dhcp4ParserTest_emptyInterfaceConfig_Test &&) noexcept = delete; Dhcp4ParserTest_emptyInterfaceConfig_Test & operator=( Dhcp4ParserTest_emptyInterfaceConfig_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_emptyInterfaceConfig_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "emptyInterfaceConfig", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 950), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 950), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 950), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_emptyInterfaceConfig_Test >); void Dhcp4ParserTest_emptyInterfaceConfig_Test::TestBody () { | |||
| 951 | ||||
| 952 | ConstElementPtr json; | |||
| 953 | EXPECT_NO_THROW(json = parseDHCP4("{ "switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4("{ " "\"rebind-timer\": 2000, " "\"renew-timer\": 1000, " "\"valid-lifetime\": 4000 }"); } else static_assert(true, "" ); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_956 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_956 ; } } else gtest_label_testnothrow_956 : ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 956, ("Expected: " "json = parseDHCP4(\"{ \" \"\\\"rebind-timer\\\": 2000, \" \"\\\"renew-timer\\\": 1000, \" \"\\\"valid-lifetime\\\": 4000 }\")" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() | |||
| 954 | "\"rebind-timer\": 2000, "switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4("{ " "\"rebind-timer\": 2000, " "\"renew-timer\": 1000, " "\"valid-lifetime\": 4000 }"); } else static_assert(true, "" ); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_956 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_956 ; } } else gtest_label_testnothrow_956 : ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 956, ("Expected: " "json = parseDHCP4(\"{ \" \"\\\"rebind-timer\\\": 2000, \" \"\\\"renew-timer\\\": 1000, \" \"\\\"valid-lifetime\\\": 4000 }\")" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() | |||
| 955 | "\"renew-timer\": 1000, "switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4("{ " "\"rebind-timer\": 2000, " "\"renew-timer\": 1000, " "\"valid-lifetime\": 4000 }"); } else static_assert(true, "" ); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_956 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_956 ; } } else gtest_label_testnothrow_956 : ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 956, ("Expected: " "json = parseDHCP4(\"{ \" \"\\\"rebind-timer\\\": 2000, \" \"\\\"renew-timer\\\": 1000, \" \"\\\"valid-lifetime\\\": 4000 }\")" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() | |||
| 956 | "\"valid-lifetime\": 4000 }"))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4("{ " "\"rebind-timer\": 2000, " "\"renew-timer\": 1000, " "\"valid-lifetime\": 4000 }"); } else static_assert(true, "" ); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_956 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_956 ; } } else gtest_label_testnothrow_956 : ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 956, ("Expected: " "json = parseDHCP4(\"{ \" \"\\\"rebind-timer\\\": 2000, \" \"\\\"renew-timer\\\": 1000, \" \"\\\"valid-lifetime\\\": 4000 }\")" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 957 | ||||
| 958 | ConstElementPtr status; | |||
| 959 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_959; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_959; } } else gtest_label_testnothrow_959 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 959, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 960 | ||||
| 961 | // returned value should be 0 (success) | |||
| 962 | checkResult(status, 0); | |||
| 963 | } | |||
| 964 | ||||
| 965 | /// Check that valid-lifetime must be between min-valid-lifetime and | |||
| 966 | /// max-valid-lifetime when a bound is specified, *AND* a subnet is | |||
| 967 | /// specified (boundary check is done when lifetimes are applied). | |||
| 968 | TEST_F(Dhcp4ParserTest, outBoundValidLifetime)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("outBoundValidLifetime") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_outBoundValidLifetime_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_outBoundValidLifetime_Test() = default ; ~Dhcp4ParserTest_outBoundValidLifetime_Test() override = default ; Dhcp4ParserTest_outBoundValidLifetime_Test (const Dhcp4ParserTest_outBoundValidLifetime_Test &) = delete; Dhcp4ParserTest_outBoundValidLifetime_Test & operator=( const Dhcp4ParserTest_outBoundValidLifetime_Test & ) = delete; Dhcp4ParserTest_outBoundValidLifetime_Test (Dhcp4ParserTest_outBoundValidLifetime_Test &&) noexcept = delete; Dhcp4ParserTest_outBoundValidLifetime_Test & operator=( Dhcp4ParserTest_outBoundValidLifetime_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_outBoundValidLifetime_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "outBoundValidLifetime", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 968), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 968), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 968), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_outBoundValidLifetime_Test >); void Dhcp4ParserTest_outBoundValidLifetime_Test::TestBody () { | |||
| 969 | ||||
| 970 | string too_small = "{ " + genIfaceConfig() + "," | |||
| 971 | "\"subnet4\": [ { " | |||
| 972 | " \"id\": 1," | |||
| 973 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 974 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 975 | "\"valid-lifetime\": 1000, \"min-valid-lifetime\": 2000 }"; | |||
| 976 | ||||
| 977 | ConstElementPtr json; | |||
| 978 | ASSERT_NO_THROW(json = parseDHCP4(too_small))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(too_small); } else static_assert(true, "") ; } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_978 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_978 ; } } else gtest_label_testnothrow_978 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 978, ("Expected: " "json = parseDHCP4(too_small)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 979 | ||||
| 980 | ConstElementPtr status; | |||
| 981 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_981; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_981; } } else gtest_label_testnothrow_981 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 981, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 982 | string expected = "subnet configuration failed: " | |||
| 983 | "the value of min-valid-lifetime (2000) is not " | |||
| 984 | "less than (default) valid-lifetime (1000)"; | |||
| 985 | checkResult(status, 1, expected); | |||
| 986 | resetConfiguration(); | |||
| 987 | ||||
| 988 | string too_large = "{ " + genIfaceConfig() + "," | |||
| 989 | "\"subnet4\": [ { " | |||
| 990 | " \"id\": 1," | |||
| 991 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 992 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 993 | "\"valid-lifetime\": 2000, \"max-valid-lifetime\": 1000 }"; | |||
| 994 | ||||
| 995 | ASSERT_NO_THROW(json = parseDHCP4(too_large))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(too_large); } else static_assert(true, "") ; } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_995 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_995 ; } } else gtest_label_testnothrow_995 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 995, ("Expected: " "json = parseDHCP4(too_large)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 996 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_996; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_996; } } else gtest_label_testnothrow_996 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 996, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 997 | expected = "subnet configuration failed: " | |||
| 998 | "the value of (default) valid-lifetime (2000) is not " | |||
| 999 | "less than max-valid-lifetime (1000)"; | |||
| 1000 | checkResult(status, 1, expected); | |||
| 1001 | resetConfiguration(); | |||
| 1002 | ||||
| 1003 | string before = "{ " + genIfaceConfig() + "," | |||
| 1004 | "\"subnet4\": [ { " | |||
| 1005 | " \"id\": 1," | |||
| 1006 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1007 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1008 | "\"valid-lifetime\": 1000, \"min-valid-lifetime\": 2000, " | |||
| 1009 | "\"max-valid-lifetime\": 4000 }"; | |||
| 1010 | ||||
| 1011 | ASSERT_NO_THROW(json = parseDHCP4(before))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(before); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1011 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1011 ; } } else gtest_label_testnothrow_1011 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1011, ("Expected: " "json = parseDHCP4(before)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1012 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1012; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1012; } } else gtest_label_testnothrow_1012 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1012, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1013 | expected = "subnet configuration failed: " | |||
| 1014 | "the value of (default) valid-lifetime (1000) is not " | |||
| 1015 | "between min-valid-lifetime (2000) and max-valid-lifetime (4000)"; | |||
| 1016 | checkResult(status, 1, expected); | |||
| 1017 | resetConfiguration(); | |||
| 1018 | ||||
| 1019 | string after = "{ " + genIfaceConfig() + "," | |||
| 1020 | "\"subnet4\": [ { " | |||
| 1021 | " \"id\": 1," | |||
| 1022 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1023 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1024 | "\"valid-lifetime\": 5000, \"min-valid-lifetime\": 1000, " | |||
| 1025 | "\"max-valid-lifetime\": 4000 }"; | |||
| 1026 | ||||
| 1027 | ASSERT_NO_THROW(json = parseDHCP4(after))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(after); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1027 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1027 ; } } else gtest_label_testnothrow_1027 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1027, ("Expected: " "json = parseDHCP4(after)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1028 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1028; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1028; } } else gtest_label_testnothrow_1028 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1028, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1029 | expected = "subnet configuration failed: " | |||
| 1030 | "the value of (default) valid-lifetime (5000) is not " | |||
| 1031 | "between min-valid-lifetime (1000) and max-valid-lifetime (4000)"; | |||
| 1032 | checkResult(status, 1, expected); | |||
| 1033 | resetConfiguration(); | |||
| 1034 | ||||
| 1035 | string crossed = "{ " + genIfaceConfig() + "," | |||
| 1036 | "\"subnet4\": [ { " | |||
| 1037 | " \"id\": 1," | |||
| 1038 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1039 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1040 | "\"valid-lifetime\": 1500, \"min-valid-lifetime\": 2000, " | |||
| 1041 | "\"max-valid-lifetime\": 1000 }"; | |||
| 1042 | ||||
| 1043 | ASSERT_NO_THROW(json = parseDHCP4(crossed))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(crossed); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1043 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1043 ; } } else gtest_label_testnothrow_1043 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1043, ("Expected: " "json = parseDHCP4(crossed)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1044 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1044; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1044; } } else gtest_label_testnothrow_1044 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1044, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1045 | expected = "subnet configuration failed: " | |||
| 1046 | "the value of min-valid-lifetime (2000) is not " | |||
| 1047 | "less than max-valid-lifetime (1000)"; | |||
| 1048 | checkResult(status, 1, expected); | |||
| 1049 | } | |||
| 1050 | ||||
| 1051 | /// Check that valid-lifetime must be between min-valid-lifetime and | |||
| 1052 | /// max-valid-lifetime when a bound is specified. Check on global | |||
| 1053 | /// parameters only. | |||
| 1054 | TEST_F(Dhcp4ParserTest, outBoundGlobalValidLifetime)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("outBoundGlobalValidLifetime") > 1 , "test_name must not be empty"); class Dhcp4ParserTest_outBoundGlobalValidLifetime_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_outBoundGlobalValidLifetime_Test () = default; ~Dhcp4ParserTest_outBoundGlobalValidLifetime_Test () override = default; Dhcp4ParserTest_outBoundGlobalValidLifetime_Test (const Dhcp4ParserTest_outBoundGlobalValidLifetime_Test & ) = delete; Dhcp4ParserTest_outBoundGlobalValidLifetime_Test & operator=( const Dhcp4ParserTest_outBoundGlobalValidLifetime_Test &) = delete; Dhcp4ParserTest_outBoundGlobalValidLifetime_Test (Dhcp4ParserTest_outBoundGlobalValidLifetime_Test && ) noexcept = delete; Dhcp4ParserTest_outBoundGlobalValidLifetime_Test & operator=( Dhcp4ParserTest_outBoundGlobalValidLifetime_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_outBoundGlobalValidLifetime_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "outBoundGlobalValidLifetime", nullptr, nullptr, ::testing:: internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1054), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1054), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1054), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_outBoundGlobalValidLifetime_Test >); void Dhcp4ParserTest_outBoundGlobalValidLifetime_Test:: TestBody() { | |||
| 1055 | ||||
| 1056 | string too_small = "{ " + genIfaceConfig() + "," | |||
| 1057 | "\"valid-lifetime\": 1000, \"min-valid-lifetime\": 2000 }"; | |||
| 1058 | ||||
| 1059 | ConstElementPtr json; | |||
| 1060 | ASSERT_NO_THROW(json = parseDHCP4(too_small))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(too_small); } else static_assert(true, "") ; } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1060 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1060 ; } } else gtest_label_testnothrow_1060 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1060, ("Expected: " "json = parseDHCP4(too_small)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1061 | ||||
| 1062 | ConstElementPtr status; | |||
| 1063 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_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/bin/dhcp4/tests/config_parser_unittest.cc" , 1063, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1064 | string expected = | |||
| 1065 | "the value of min-valid-lifetime (2000) is not " | |||
| 1066 | "less than (default) valid-lifetime (1000)"; | |||
| 1067 | checkResult(status, 1, expected); | |||
| 1068 | resetConfiguration(); | |||
| 1069 | ||||
| 1070 | string too_large = "{ " + genIfaceConfig() + "," | |||
| 1071 | "\"valid-lifetime\": 2000, \"max-valid-lifetime\": 1000 }"; | |||
| 1072 | ||||
| 1073 | ASSERT_NO_THROW(json = parseDHCP4(too_large))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(too_large); } else static_assert(true, "") ; } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1073 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1073 ; } } else gtest_label_testnothrow_1073 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1073, ("Expected: " "json = parseDHCP4(too_large)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1074 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1074; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1074; } } else gtest_label_testnothrow_1074 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1074, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1075 | expected = | |||
| 1076 | "the value of (default) valid-lifetime (2000) is not " | |||
| 1077 | "less than max-valid-lifetime (1000)"; | |||
| 1078 | checkResult(status, 1, expected); | |||
| 1079 | resetConfiguration(); | |||
| 1080 | ||||
| 1081 | string before = "{ " + genIfaceConfig() + "," | |||
| 1082 | "\"valid-lifetime\": 1000, \"min-valid-lifetime\": 2000, " | |||
| 1083 | "\"max-valid-lifetime\": 4000 }"; | |||
| 1084 | ||||
| 1085 | ASSERT_NO_THROW(json = parseDHCP4(before))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(before); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1085 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1085 ; } } else gtest_label_testnothrow_1085 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1085, ("Expected: " "json = parseDHCP4(before)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1086 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1086; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1086; } } else gtest_label_testnothrow_1086 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1086, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1087 | expected = | |||
| 1088 | "the value of (default) valid-lifetime (1000) is not " | |||
| 1089 | "between min-valid-lifetime (2000) and max-valid-lifetime (4000)"; | |||
| 1090 | checkResult(status, 1, expected); | |||
| 1091 | resetConfiguration(); | |||
| 1092 | ||||
| 1093 | string after = "{ " + genIfaceConfig() + "," | |||
| 1094 | "\"valid-lifetime\": 5000, \"min-valid-lifetime\": 1000, " | |||
| 1095 | "\"max-valid-lifetime\": 4000 }"; | |||
| 1096 | ||||
| 1097 | ASSERT_NO_THROW(json = parseDHCP4(after))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(after); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1097 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1097 ; } } else gtest_label_testnothrow_1097 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1097, ("Expected: " "json = parseDHCP4(after)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1098 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1098; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1098; } } else gtest_label_testnothrow_1098 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1098, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1099 | expected = | |||
| 1100 | "the value of (default) valid-lifetime (5000) is not " | |||
| 1101 | "between min-valid-lifetime (1000) and max-valid-lifetime (4000)"; | |||
| 1102 | checkResult(status, 1, expected); | |||
| 1103 | resetConfiguration(); | |||
| 1104 | ||||
| 1105 | string crossed = "{ " + genIfaceConfig() + "," | |||
| 1106 | "\"valid-lifetime\": 1500, \"min-valid-lifetime\": 2000, " | |||
| 1107 | "\"max-valid-lifetime\": 1000 }"; | |||
| 1108 | ||||
| 1109 | ASSERT_NO_THROW(json = parseDHCP4(crossed))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(crossed); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1109 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1109 ; } } else gtest_label_testnothrow_1109 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1109, ("Expected: " "json = parseDHCP4(crossed)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1110 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1110; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1110; } } else gtest_label_testnothrow_1110 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1110, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1111 | expected = | |||
| 1112 | "the value of min-valid-lifetime (2000) is not " | |||
| 1113 | "less than max-valid-lifetime (1000)"; | |||
| 1114 | checkResult(status, 1, expected); | |||
| 1115 | } | |||
| 1116 | ||||
| 1117 | /// Check that the renew-timer doesn't have to be specified, in which case | |||
| 1118 | /// it is marked unspecified in the Subnet. | |||
| 1119 | TEST_F(Dhcp4ParserTest, unspecifiedRenewTimer)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("unspecifiedRenewTimer") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_unspecifiedRenewTimer_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_unspecifiedRenewTimer_Test() = default ; ~Dhcp4ParserTest_unspecifiedRenewTimer_Test() override = default ; Dhcp4ParserTest_unspecifiedRenewTimer_Test (const Dhcp4ParserTest_unspecifiedRenewTimer_Test &) = delete; Dhcp4ParserTest_unspecifiedRenewTimer_Test & operator=( const Dhcp4ParserTest_unspecifiedRenewTimer_Test & ) = delete; Dhcp4ParserTest_unspecifiedRenewTimer_Test (Dhcp4ParserTest_unspecifiedRenewTimer_Test &&) noexcept = delete; Dhcp4ParserTest_unspecifiedRenewTimer_Test & operator=( Dhcp4ParserTest_unspecifiedRenewTimer_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_unspecifiedRenewTimer_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "unspecifiedRenewTimer", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1119), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1119), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1119), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_unspecifiedRenewTimer_Test >); void Dhcp4ParserTest_unspecifiedRenewTimer_Test::TestBody () { | |||
| 1120 | ||||
| 1121 | string config = "{ " + genIfaceConfig() + "," | |||
| 1122 | "\"rebind-timer\": 2000, " | |||
| 1123 | "\"subnet4\": [ { " | |||
| 1124 | " \"id\": 1," | |||
| 1125 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1126 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1127 | "\"valid-lifetime\": 4000 }"; | |||
| 1128 | ||||
| 1129 | ConstElementPtr json; | |||
| 1130 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_1130 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1130 ; } } else gtest_label_testnothrow_1130 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1130, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1131 | extractConfig(config); | |||
| 1132 | ||||
| 1133 | ConstElementPtr status; | |||
| 1134 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1134; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1134; } } else gtest_label_testnothrow_1134 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1134, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1135 | ||||
| 1136 | // returned value should be 0 (success) | |||
| 1137 | checkResult(status, 0); | |||
| 1138 | ||||
| 1139 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 1140 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200")); | |||
| 1141 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1141, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 1142 | ||||
| 1143 | EXPECT_TRUE(subnet->getT1().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->getT1().unspecified ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1143, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getT1().unspecified()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 1144 | EXPECT_FALSE(subnet->getT2().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getT2(). unspecified()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1144, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getT2().unspecified()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 1145 | EXPECT_EQ(2000, subnet->getT2().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2000", "subnet->getT2().get()" , 2000, subnet->getT2().get()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1145, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1146 | EXPECT_EQ(4000, subnet->getValid().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("4000", "subnet->getValid().get()" , 4000, subnet->getValid().get()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1146, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1147 | ||||
| 1148 | // Check that subnet-id is 1 | |||
| 1149 | EXPECT_EQ(1, subnet->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "subnet->getID()" , 1, subnet->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1149, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1150 | } | |||
| 1151 | ||||
| 1152 | /// Check that the rebind-timer doesn't have to be specified, in which case | |||
| 1153 | /// it is marked unspecified in the Subnet. | |||
| 1154 | TEST_F(Dhcp4ParserTest, unspecifiedRebindTimer)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("unspecifiedRebindTimer") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_unspecifiedRebindTimer_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_unspecifiedRebindTimer_Test () = default; ~Dhcp4ParserTest_unspecifiedRebindTimer_Test() override = default; Dhcp4ParserTest_unspecifiedRebindTimer_Test (const Dhcp4ParserTest_unspecifiedRebindTimer_Test &) = delete; Dhcp4ParserTest_unspecifiedRebindTimer_Test & operator=( const Dhcp4ParserTest_unspecifiedRebindTimer_Test &) = delete ; Dhcp4ParserTest_unspecifiedRebindTimer_Test (Dhcp4ParserTest_unspecifiedRebindTimer_Test &&) noexcept = delete; Dhcp4ParserTest_unspecifiedRebindTimer_Test & operator=( Dhcp4ParserTest_unspecifiedRebindTimer_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_unspecifiedRebindTimer_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "unspecifiedRebindTimer", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1154), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1154), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1154), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_unspecifiedRebindTimer_Test >); void Dhcp4ParserTest_unspecifiedRebindTimer_Test::TestBody () { | |||
| 1155 | ||||
| 1156 | string config = "{ " + genIfaceConfig() + "," | |||
| 1157 | "\"renew-timer\": 1000, " | |||
| 1158 | "\"subnet4\": [ { " | |||
| 1159 | " \"id\": 1," | |||
| 1160 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1161 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1162 | "\"valid-lifetime\": 4000 }"; | |||
| 1163 | ||||
| 1164 | ConstElementPtr json; | |||
| 1165 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_1165 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1165 ; } } else gtest_label_testnothrow_1165 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1165, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1166 | extractConfig(config); | |||
| 1167 | ||||
| 1168 | ConstElementPtr status; | |||
| 1169 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1169; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1169; } } else gtest_label_testnothrow_1169 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1169, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1170 | ||||
| 1171 | // returned value should be 0 (success) | |||
| 1172 | checkResult(status, 0); | |||
| 1173 | ||||
| 1174 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 1175 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200")); | |||
| 1176 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1176, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 1177 | EXPECT_FALSE(subnet->getT1().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getT1(). unspecified()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1177, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getT1().unspecified()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 1178 | EXPECT_EQ(1000, subnet->getT1().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1000", "subnet->getT1().get()" , 1000, subnet->getT1().get()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1178, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1179 | EXPECT_TRUE(subnet->getT2().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->getT2().unspecified ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1179, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getT2().unspecified()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 1180 | EXPECT_EQ(4000, subnet->getValid().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("4000", "subnet->getValid().get()" , 4000, subnet->getValid().get()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1180, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1181 | ||||
| 1182 | // Check that subnet-id is 1 | |||
| 1183 | EXPECT_EQ(1, subnet->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "subnet->getID()" , 1, subnet->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1183, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1184 | } | |||
| 1185 | ||||
| 1186 | /// The goal of this test is to verify if configuration without any | |||
| 1187 | /// subnets defined can be accepted. | |||
| 1188 | TEST_F(Dhcp4ParserTest, emptySubnet)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("emptySubnet") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_emptySubnet_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_emptySubnet_Test() = default; ~Dhcp4ParserTest_emptySubnet_Test () override = default; Dhcp4ParserTest_emptySubnet_Test (const Dhcp4ParserTest_emptySubnet_Test &) = delete; Dhcp4ParserTest_emptySubnet_Test & operator=( const Dhcp4ParserTest_emptySubnet_Test & ) = delete; Dhcp4ParserTest_emptySubnet_Test (Dhcp4ParserTest_emptySubnet_Test &&) noexcept = delete; Dhcp4ParserTest_emptySubnet_Test & operator=( Dhcp4ParserTest_emptySubnet_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_emptySubnet_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "emptySubnet", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 1188 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1188), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1188), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_emptySubnet_Test >); void Dhcp4ParserTest_emptySubnet_Test::TestBody() { | |||
| 1189 | ||||
| 1190 | string config = "{ " + genIfaceConfig() + "," | |||
| 1191 | "\"rebind-timer\": 2000, " | |||
| 1192 | "\"renew-timer\": 1000, " | |||
| 1193 | "\"subnet4\": [ ], " | |||
| 1194 | "\"valid-lifetime\": 4000 }"; | |||
| 1195 | ||||
| 1196 | ConstElementPtr json; | |||
| 1197 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_1197 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1197 ; } } else gtest_label_testnothrow_1197 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1197, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1198 | extractConfig(config); | |||
| 1199 | ||||
| 1200 | ConstElementPtr status; | |||
| 1201 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1201; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1201; } } else gtest_label_testnothrow_1201 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1201, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1202 | ||||
| 1203 | // returned value should be 0 (success) | |||
| 1204 | checkResult(status, 0); | |||
| 1205 | } | |||
| 1206 | ||||
| 1207 | /// The goal of this test is to verify if defined subnet uses global | |||
| 1208 | /// parameter timer definitions. | |||
| 1209 | TEST_F(Dhcp4ParserTest, subnetGlobalDefaults)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("subnetGlobalDefaults") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_subnetGlobalDefaults_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_subnetGlobalDefaults_Test() = default ; ~Dhcp4ParserTest_subnetGlobalDefaults_Test() override = default ; Dhcp4ParserTest_subnetGlobalDefaults_Test (const Dhcp4ParserTest_subnetGlobalDefaults_Test &) = delete; Dhcp4ParserTest_subnetGlobalDefaults_Test & operator=( const Dhcp4ParserTest_subnetGlobalDefaults_Test & ) = delete; Dhcp4ParserTest_subnetGlobalDefaults_Test (Dhcp4ParserTest_subnetGlobalDefaults_Test &&) noexcept = delete; Dhcp4ParserTest_subnetGlobalDefaults_Test & operator=( Dhcp4ParserTest_subnetGlobalDefaults_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_subnetGlobalDefaults_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "subnetGlobalDefaults", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1209), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1209), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1209), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_subnetGlobalDefaults_Test >); void Dhcp4ParserTest_subnetGlobalDefaults_Test::TestBody () { | |||
| 1210 | ||||
| 1211 | string config = "{ " + genIfaceConfig() + "," | |||
| 1212 | "\"rebind-timer\": 2000, " | |||
| 1213 | "\"renew-timer\": 1000, " | |||
| 1214 | "\"subnet4\": [ { " | |||
| 1215 | " \"id\": 1," | |||
| 1216 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1217 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1218 | "\"valid-lifetime\": 4000," | |||
| 1219 | "\"min-valid-lifetime\": 3000," | |||
| 1220 | "\"max-valid-lifetime\": 5000 }"; | |||
| 1221 | ||||
| 1222 | ConstElementPtr json; | |||
| 1223 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_1223 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1223 ; } } else gtest_label_testnothrow_1223 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1223, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1224 | extractConfig(config); | |||
| 1225 | ||||
| 1226 | ConstElementPtr status; | |||
| 1227 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1227; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1227; } } else gtest_label_testnothrow_1227 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1227, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1228 | ||||
| 1229 | // check if returned status is OK | |||
| 1230 | checkResult(status, 0); | |||
| 1231 | ||||
| 1232 | // Now check if the configuration was indeed handled and we have | |||
| 1233 | // expected pool configured. | |||
| 1234 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 1235 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200")); | |||
| 1236 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1236, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 1237 | EXPECT_EQ(1000, subnet->getT1().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1000", "subnet->getT1().get()" , 1000, subnet->getT1().get()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1237, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1238 | EXPECT_EQ(2000, subnet->getT2().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2000", "subnet->getT2().get()" , 2000, subnet->getT2().get()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1238, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1239 | EXPECT_EQ(4000, subnet->getValid().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("4000", "subnet->getValid().get()" , 4000, subnet->getValid().get()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1239, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1240 | EXPECT_EQ(3000, subnet->getValid().getMin())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("3000", "subnet->getValid().getMin()" , 3000, subnet->getValid().getMin()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1240, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1241 | EXPECT_EQ(5000, subnet->getValid().getMax())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("5000", "subnet->getValid().getMax()" , 5000, subnet->getValid().getMax()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1241, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1242 | ||||
| 1243 | // Check that subnet-id is 1 | |||
| 1244 | EXPECT_EQ(1, subnet->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "subnet->getID()" , 1, subnet->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1244, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1245 | } | |||
| 1246 | ||||
| 1247 | // This test checks that it is possible to assign arbitrary ids for subnets. | |||
| 1248 | TEST_F(Dhcp4ParserTest, multipleSubnetsExplicitIDs)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("multipleSubnetsExplicitIDs") > 1, "test_name must not be empty"); class Dhcp4ParserTest_multipleSubnetsExplicitIDs_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_multipleSubnetsExplicitIDs_Test () = default; ~Dhcp4ParserTest_multipleSubnetsExplicitIDs_Test () override = default; Dhcp4ParserTest_multipleSubnetsExplicitIDs_Test (const Dhcp4ParserTest_multipleSubnetsExplicitIDs_Test & ) = delete; Dhcp4ParserTest_multipleSubnetsExplicitIDs_Test & operator=( const Dhcp4ParserTest_multipleSubnetsExplicitIDs_Test &) = delete; Dhcp4ParserTest_multipleSubnetsExplicitIDs_Test (Dhcp4ParserTest_multipleSubnetsExplicitIDs_Test &&) noexcept = delete; Dhcp4ParserTest_multipleSubnetsExplicitIDs_Test & operator=( Dhcp4ParserTest_multipleSubnetsExplicitIDs_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_multipleSubnetsExplicitIDs_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "multipleSubnetsExplicitIDs", nullptr, nullptr, ::testing:: internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1248), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1248), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1248), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_multipleSubnetsExplicitIDs_Test >); void Dhcp4ParserTest_multipleSubnetsExplicitIDs_Test:: TestBody() { | |||
| 1249 | ConstElementPtr x; | |||
| 1250 | // Four subnets with arbitrary subnet ids. | |||
| 1251 | string config = "{ " + genIfaceConfig() + "," | |||
| 1252 | "\"rebind-timer\": 2000, " | |||
| 1253 | "\"renew-timer\": 1000, " | |||
| 1254 | "\"subnet4\": [ { " | |||
| 1255 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1256 | " \"subnet\": \"192.0.2.0/24\", " | |||
| 1257 | " \"id\": 1024" | |||
| 1258 | " }," | |||
| 1259 | " {" | |||
| 1260 | " \"pools\": [ { \"pool\": \"192.0.3.101 - 192.0.3.150\" } ]," | |||
| 1261 | " \"subnet\": \"192.0.3.0/24\", " | |||
| 1262 | " \"id\": 100" | |||
| 1263 | " }," | |||
| 1264 | " {" | |||
| 1265 | " \"pools\": [ { \"pool\": \"192.0.4.101 - 192.0.4.150\" } ]," | |||
| 1266 | " \"subnet\": \"192.0.4.0/24\", " | |||
| 1267 | " \"id\": 1" | |||
| 1268 | " }," | |||
| 1269 | " {" | |||
| 1270 | " \"pools\": [ { \"pool\": \"192.0.5.101 - 192.0.5.150\" } ]," | |||
| 1271 | " \"subnet\": \"192.0.5.0/24\", " | |||
| 1272 | " \"id\": 34" | |||
| 1273 | " } ]," | |||
| 1274 | "\"valid-lifetime\": 4000 }"; | |||
| 1275 | ||||
| 1276 | int cnt = 0; // Number of reconfigurations | |||
| 1277 | ||||
| 1278 | ConstElementPtr json; | |||
| 1279 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_1279 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1279 ; } } else gtest_label_testnothrow_1279 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1279, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1280 | extractConfig(config); | |||
| 1281 | ||||
| 1282 | do { | |||
| 1283 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1283; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1283; } } else gtest_label_testnothrow_1283 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1283, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1284 | checkResult(x, 0); | |||
| 1285 | ||||
| 1286 | CfgMgr::instance().commit(); | |||
| 1287 | ||||
| 1288 | const Subnet4Collection* subnets = | |||
| 1289 | CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll(); | |||
| 1290 | ASSERT_TRUE(subnets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnets)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1290, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnets", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 1291 | ASSERT_EQ(4, subnets->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("4", "subnets->size()" , 4, subnets->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1291, gtest_ar.failure_message()) = ::testing::Message(); // We expect 4 subnets | |||
| 1292 | ||||
| 1293 | // Verify that subnet ids are as expected. | |||
| 1294 | // Now the subnet order is the subnet id one. | |||
| 1295 | auto subnet = subnets->begin(); | |||
| 1296 | EXPECT_EQ(1, (*subnet)->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "(*subnet)->getID()" , 1, (*subnet)->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1296, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1297 | EXPECT_EQ(34, (*++subnet)->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("34", "(*++subnet)->getID()" , 34, (*++subnet)->getID()))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1297, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1298 | EXPECT_EQ(100, (*++subnet)->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("100", "(*++subnet)->getID()" , 100, (*++subnet)->getID()))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1298, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1299 | EXPECT_EQ(1024, (*++subnet)->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1024", "(*++subnet)->getID()" , 1024, (*++subnet)->getID()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1299, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1300 | ||||
| 1301 | // Repeat reconfiguration process 10 times and check that the subnet-id | |||
| 1302 | // is set to the same value. | |||
| 1303 | } while (++cnt < 3); | |||
| 1304 | } | |||
| 1305 | ||||
| 1306 | // Check that the configuration with two subnets having the same ID is rejected. | |||
| 1307 | TEST_F(Dhcp4ParserTest, multipleSubnetsOverlappingIDs)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("multipleSubnetsOverlappingIDs") > 1, "test_name must not be empty"); class Dhcp4ParserTest_multipleSubnetsOverlappingIDs_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_multipleSubnetsOverlappingIDs_Test () = default; ~Dhcp4ParserTest_multipleSubnetsOverlappingIDs_Test () override = default; Dhcp4ParserTest_multipleSubnetsOverlappingIDs_Test (const Dhcp4ParserTest_multipleSubnetsOverlappingIDs_Test & ) = delete; Dhcp4ParserTest_multipleSubnetsOverlappingIDs_Test & operator=( const Dhcp4ParserTest_multipleSubnetsOverlappingIDs_Test &) = delete; Dhcp4ParserTest_multipleSubnetsOverlappingIDs_Test (Dhcp4ParserTest_multipleSubnetsOverlappingIDs_Test && ) noexcept = delete; Dhcp4ParserTest_multipleSubnetsOverlappingIDs_Test & operator=( Dhcp4ParserTest_multipleSubnetsOverlappingIDs_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_multipleSubnetsOverlappingIDs_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "multipleSubnetsOverlappingIDs", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1307), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1307), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1307), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_multipleSubnetsOverlappingIDs_Test >); void Dhcp4ParserTest_multipleSubnetsOverlappingIDs_Test ::TestBody() { | |||
| 1308 | ConstElementPtr x; | |||
| 1309 | // Four subnets, two of them have the same id. | |||
| 1310 | string config = "{ " + genIfaceConfig() + "," | |||
| 1311 | "\"rebind-timer\": 2000, " | |||
| 1312 | "\"renew-timer\": 1000, " | |||
| 1313 | "\"subnet4\": [ { " | |||
| 1314 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1315 | " \"subnet\": \"192.0.2.0/24\", " | |||
| 1316 | " \"id\": 1024" | |||
| 1317 | " }," | |||
| 1318 | " {" | |||
| 1319 | " \"pools\": [ { \"pool\": \"192.0.3.101 - 192.0.3.150\" } ]," | |||
| 1320 | " \"subnet\": \"192.0.3.0/24\", " | |||
| 1321 | " \"id\": 100" | |||
| 1322 | " }," | |||
| 1323 | " {" | |||
| 1324 | " \"pools\": [ { \"pool\": \"192.0.4.101 - 192.0.4.150\" } ]," | |||
| 1325 | " \"subnet\": \"192.0.4.0/24\", " | |||
| 1326 | " \"id\": 1024" | |||
| 1327 | " }," | |||
| 1328 | " {" | |||
| 1329 | " \"pools\": [ { \"pool\": \"192.0.5.101 - 192.0.5.150\" } ]," | |||
| 1330 | " \"subnet\": \"192.0.5.0/24\", " | |||
| 1331 | " \"id\": 34" | |||
| 1332 | " } ]," | |||
| 1333 | "\"valid-lifetime\": 4000 }"; | |||
| 1334 | ||||
| 1335 | ConstElementPtr json; | |||
| 1336 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_1336 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1336 ; } } else gtest_label_testnothrow_1336 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1336, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1337 | ||||
| 1338 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1338; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1338; } } else gtest_label_testnothrow_1338 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1338, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1339 | checkResult(x, 1); | |||
| 1340 | EXPECT_TRUE(errorContainsPosition(x, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (x, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1340, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(x, \"<string>\")", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 1341 | } | |||
| 1342 | ||||
| 1343 | // Goal of this test is to verify that a previously configured subnet can be | |||
| 1344 | // deleted in subsequent reconfiguration. | |||
| 1345 | TEST_F(Dhcp4ParserTest, reconfigureRemoveSubnet)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("reconfigureRemoveSubnet") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_reconfigureRemoveSubnet_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_reconfigureRemoveSubnet_Test () = default; ~Dhcp4ParserTest_reconfigureRemoveSubnet_Test() override = default; Dhcp4ParserTest_reconfigureRemoveSubnet_Test (const Dhcp4ParserTest_reconfigureRemoveSubnet_Test &) = delete; Dhcp4ParserTest_reconfigureRemoveSubnet_Test & operator =( const Dhcp4ParserTest_reconfigureRemoveSubnet_Test &) = delete; Dhcp4ParserTest_reconfigureRemoveSubnet_Test (Dhcp4ParserTest_reconfigureRemoveSubnet_Test &&) noexcept = delete; Dhcp4ParserTest_reconfigureRemoveSubnet_Test & operator=( Dhcp4ParserTest_reconfigureRemoveSubnet_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_reconfigureRemoveSubnet_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "reconfigureRemoveSubnet", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1345), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1345), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1345), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_reconfigureRemoveSubnet_Test >); void Dhcp4ParserTest_reconfigureRemoveSubnet_Test::TestBody () { | |||
| 1346 | ConstElementPtr x; | |||
| 1347 | ||||
| 1348 | // All four subnets | |||
| 1349 | string config4 = "{ " + genIfaceConfig() + "," | |||
| 1350 | "\"rebind-timer\": 2000, " | |||
| 1351 | "\"renew-timer\": 1000, " | |||
| 1352 | "\"subnet4\": [ { " | |||
| 1353 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1354 | " \"subnet\": \"192.0.2.0/24\", " | |||
| 1355 | " \"id\": 1" | |||
| 1356 | " }," | |||
| 1357 | " {" | |||
| 1358 | " \"pools\": [ { \"pool\": \"192.0.3.101 - 192.0.3.150\" } ]," | |||
| 1359 | " \"subnet\": \"192.0.3.0/24\", " | |||
| 1360 | " \"id\": 2" | |||
| 1361 | " }," | |||
| 1362 | " {" | |||
| 1363 | " \"pools\": [ { \"pool\": \"192.0.4.101 - 192.0.4.150\" } ]," | |||
| 1364 | " \"subnet\": \"192.0.4.0/24\", " | |||
| 1365 | " \"id\": 3" | |||
| 1366 | " }," | |||
| 1367 | " {" | |||
| 1368 | " \"pools\": [ { \"pool\": \"192.0.5.101 - 192.0.5.150\" } ]," | |||
| 1369 | " \"subnet\": \"192.0.5.0/24\", " | |||
| 1370 | " \"id\": 4" | |||
| 1371 | " } ]," | |||
| 1372 | "\"valid-lifetime\": 4000 }"; | |||
| 1373 | ||||
| 1374 | // Three subnets (the last one removed) | |||
| 1375 | string config_first3 = "{ " + genIfaceConfig() + "," | |||
| 1376 | "\"rebind-timer\": 2000, " | |||
| 1377 | "\"renew-timer\": 1000, " | |||
| 1378 | "\"subnet4\": [ { " | |||
| 1379 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1380 | " \"subnet\": \"192.0.2.0/24\", " | |||
| 1381 | " \"id\": 1" | |||
| 1382 | " }," | |||
| 1383 | " {" | |||
| 1384 | " \"pools\": [ { \"pool\": \"192.0.3.101 - 192.0.3.150\" } ]," | |||
| 1385 | " \"subnet\": \"192.0.3.0/24\", " | |||
| 1386 | " \"id\": 2" | |||
| 1387 | " }," | |||
| 1388 | " {" | |||
| 1389 | " \"pools\": [ { \"pool\": \"192.0.4.101 - 192.0.4.150\" } ]," | |||
| 1390 | " \"subnet\": \"192.0.4.0/24\", " | |||
| 1391 | " \"id\": 3" | |||
| 1392 | " } ]," | |||
| 1393 | "\"valid-lifetime\": 4000 }"; | |||
| 1394 | ||||
| 1395 | // Second subnet removed | |||
| 1396 | string config_second_removed = "{ " + genIfaceConfig() + "," | |||
| 1397 | "\"rebind-timer\": 2000, " | |||
| 1398 | "\"renew-timer\": 1000, " | |||
| 1399 | "\"subnet4\": [ { " | |||
| 1400 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1401 | " \"subnet\": \"192.0.2.0/24\", " | |||
| 1402 | " \"id\": 1" | |||
| 1403 | " }," | |||
| 1404 | " {" | |||
| 1405 | " \"pools\": [ { \"pool\": \"192.0.4.101 - 192.0.4.150\" } ]," | |||
| 1406 | " \"subnet\": \"192.0.4.0/24\", " | |||
| 1407 | " \"id\": 3" | |||
| 1408 | " }," | |||
| 1409 | " {" | |||
| 1410 | " \"pools\": [ { \"pool\": \"192.0.5.101 - 192.0.5.150\" } ]," | |||
| 1411 | " \"subnet\": \"192.0.5.0/24\", " | |||
| 1412 | " \"id\": 4" | |||
| 1413 | " } ]," | |||
| 1414 | "\"valid-lifetime\": 4000 }"; | |||
| 1415 | ||||
| 1416 | // CASE 1: Configure 4 subnets, then reconfigure and remove the | |||
| 1417 | // last one. | |||
| 1418 | ||||
| 1419 | ConstElementPtr json; | |||
| 1420 | ASSERT_NO_THROW(json = parseDHCP4(config4))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(config4); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1420 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1420 ; } } else gtest_label_testnothrow_1420 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1420, ("Expected: " "json = parseDHCP4(config4)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1421 | extractConfig(config4); | |||
| 1422 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1422; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1422; } } else gtest_label_testnothrow_1422 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1422, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1423 | checkResult(x, 0); | |||
| 1424 | ||||
| 1425 | CfgMgr::instance().commit(); | |||
| 1426 | ||||
| 1427 | const Subnet4Collection* subnets = | |||
| 1428 | CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll(); | |||
| 1429 | ASSERT_TRUE(subnets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnets)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1429, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnets", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 1430 | ASSERT_EQ(4, subnets->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("4", "subnets->size()" , 4, subnets->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1430, gtest_ar.failure_message()) = ::testing::Message(); // We expect 4 subnets | |||
| 1431 | ||||
| 1432 | CfgMgr::instance().clear(); | |||
| 1433 | ||||
| 1434 | // Do the reconfiguration (the last subnet is removed) | |||
| 1435 | ASSERT_NO_THROW(json = parseDHCP4(config_first3))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(config_first3); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1435 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1435 ; } } else gtest_label_testnothrow_1435 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1435, ("Expected: " "json = parseDHCP4(config_first3)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1436 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1436; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1436; } } else gtest_label_testnothrow_1436 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1436, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1437 | checkResult(x, 0); | |||
| 1438 | ||||
| 1439 | CfgMgr::instance().commit(); | |||
| 1440 | ||||
| 1441 | subnets = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll(); | |||
| 1442 | ASSERT_TRUE(subnets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnets)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1442, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnets", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 1443 | ASSERT_EQ(3, subnets->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("3", "subnets->size()" , 3, subnets->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1443, gtest_ar.failure_message()) = ::testing::Message(); // We expect 3 subnets now (4th is removed) | |||
| 1444 | ||||
| 1445 | // Check subnet-ids of each subnet (it should be monotonously increasing) | |||
| 1446 | auto subnet = subnets->begin(); | |||
| 1447 | EXPECT_EQ(1, (*subnet)->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "(*subnet)->getID()" , 1, (*subnet)->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1447, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1448 | EXPECT_EQ(2, (*++subnet)->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "(*++subnet)->getID()" , 2, (*++subnet)->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1448, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1449 | EXPECT_EQ(3, (*++subnet)->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("3", "(*++subnet)->getID()" , 3, (*++subnet)->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1449, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1450 | ||||
| 1451 | CfgMgr::instance().clear(); | |||
| 1452 | ||||
| 1453 | /// CASE 2: Configure 4 subnets, then reconfigure and remove one | |||
| 1454 | /// from in between (not first, not last) | |||
| 1455 | ASSERT_NO_THROW(json = parseDHCP4(config4))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(config4); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1455 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1455 ; } } else gtest_label_testnothrow_1455 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1455, ("Expected: " "json = parseDHCP4(config4)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1456 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1456; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1456; } } else gtest_label_testnothrow_1456 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1456, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1457 | checkResult(x, 0); | |||
| 1458 | ||||
| 1459 | CfgMgr::instance().commit(); | |||
| 1460 | ||||
| 1461 | // Do reconfiguration | |||
| 1462 | ASSERT_NO_THROW(json = parseDHCP4(config_second_removed))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(config_second_removed); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1462; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1462; } } else gtest_label_testnothrow_1462 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1462, ("Expected: " "json = parseDHCP4(config_second_removed)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1463 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1463; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1463; } } else gtest_label_testnothrow_1463 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1463, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1464 | checkResult(x, 0); | |||
| 1465 | ||||
| 1466 | CfgMgr::instance().commit(); | |||
| 1467 | ||||
| 1468 | subnets = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4()->getAll(); | |||
| 1469 | ASSERT_TRUE(subnets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnets)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1469, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnets", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 1470 | ASSERT_EQ(3, subnets->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("3", "subnets->size()" , 3, subnets->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1470, gtest_ar.failure_message()) = ::testing::Message(); // We expect 4 subnets | |||
| 1471 | ||||
| 1472 | subnet = subnets->begin(); | |||
| 1473 | EXPECT_EQ(1, (*subnet)->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "(*subnet)->getID()" , 1, (*subnet)->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1473, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1474 | // The second subnet (with subnet-id = 2) is no longer there | |||
| 1475 | EXPECT_EQ(3, (*++subnet)->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("3", "(*++subnet)->getID()" , 3, (*++subnet)->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1475, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1476 | EXPECT_EQ(4, (*++subnet)->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("4", "(*++subnet)->getID()" , 4, (*++subnet)->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1476, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1477 | } | |||
| 1478 | ||||
| 1479 | /// @todo: implement subnet removal test as part of #3281. | |||
| 1480 | ||||
| 1481 | // Checks if the next-server and other fixed BOOTP fields defined as | |||
| 1482 | // global parameter are taken into consideration. | |||
| 1483 | TEST_F(Dhcp4ParserTest, nextServerGlobal)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("nextServerGlobal") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_nextServerGlobal_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_nextServerGlobal_Test() = default; ~Dhcp4ParserTest_nextServerGlobal_Test() override = default; Dhcp4ParserTest_nextServerGlobal_Test (const Dhcp4ParserTest_nextServerGlobal_Test &) = delete; Dhcp4ParserTest_nextServerGlobal_Test & operator=( const Dhcp4ParserTest_nextServerGlobal_Test & ) = delete; Dhcp4ParserTest_nextServerGlobal_Test (Dhcp4ParserTest_nextServerGlobal_Test &&) noexcept = delete; Dhcp4ParserTest_nextServerGlobal_Test & operator=( Dhcp4ParserTest_nextServerGlobal_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_nextServerGlobal_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "nextServerGlobal", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1483), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1483), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1483), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_nextServerGlobal_Test >); void Dhcp4ParserTest_nextServerGlobal_Test::TestBody() { | |||
| 1484 | ||||
| 1485 | string config = "{ " + genIfaceConfig() + "," | |||
| 1486 | "\"rebind-timer\": 2000, " | |||
| 1487 | "\"renew-timer\": 1000, " | |||
| 1488 | "\"next-server\": \"1.2.3.4\", " | |||
| 1489 | "\"server-hostname\": \"foo\", " | |||
| 1490 | "\"boot-file-name\": \"bar\", " | |||
| 1491 | "\"subnet4\": [ { " | |||
| 1492 | " \"id\": 1," | |||
| 1493 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1494 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1495 | "\"valid-lifetime\": 4000 }"; | |||
| 1496 | ||||
| 1497 | ConstElementPtr json; | |||
| 1498 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_1498 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1498 ; } } else gtest_label_testnothrow_1498 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1498, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1499 | extractConfig(config); | |||
| 1500 | ||||
| 1501 | ConstElementPtr status; | |||
| 1502 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1502; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1502; } } else gtest_label_testnothrow_1502 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1502, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1503 | ||||
| 1504 | // check if returned status is OK | |||
| 1505 | checkResult(status, 0); | |||
| 1506 | ||||
| 1507 | // Now check if the configuration was indeed handled and we have | |||
| 1508 | // expected pool configured. | |||
| 1509 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 1510 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200")); | |||
| 1511 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1511, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 1512 | // Reset the fetch global function to staging (vs current) config. | |||
| 1513 | Subnet4Ptr mutable_subnet = boost::const_pointer_cast<Subnet4>(subnet); | |||
| 1514 | mutable_subnet->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr { | |||
| 1515 | return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals()); | |||
| 1516 | }); | |||
| 1517 | EXPECT_EQ("1.2.3.4", subnet->getSiaddr().get().toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"1.2.3.4\"" , "subnet->getSiaddr().get().toText()", "1.2.3.4", subnet-> getSiaddr().get().toText()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1517, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1518 | EXPECT_EQ("foo", subnet->getSname().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"foo\"" , "subnet->getSname().get()", "foo", subnet->getSname() .get()))) ; else ::testing::internal::AssertHelper(::testing:: TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1518, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1519 | EXPECT_EQ("bar", subnet->getFilename().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"bar\"" , "subnet->getFilename().get()", "bar", subnet->getFilename ().get()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1519, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1520 | } | |||
| 1521 | ||||
| 1522 | // Checks if the next-server and other fixed BOOTP fields defined as | |||
| 1523 | // subnet parameter are taken into consideration. | |||
| 1524 | TEST_F(Dhcp4ParserTest, nextServerSubnet)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("nextServerSubnet") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_nextServerSubnet_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_nextServerSubnet_Test() = default; ~Dhcp4ParserTest_nextServerSubnet_Test() override = default; Dhcp4ParserTest_nextServerSubnet_Test (const Dhcp4ParserTest_nextServerSubnet_Test &) = delete; Dhcp4ParserTest_nextServerSubnet_Test & operator=( const Dhcp4ParserTest_nextServerSubnet_Test & ) = delete; Dhcp4ParserTest_nextServerSubnet_Test (Dhcp4ParserTest_nextServerSubnet_Test &&) noexcept = delete; Dhcp4ParserTest_nextServerSubnet_Test & operator=( Dhcp4ParserTest_nextServerSubnet_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_nextServerSubnet_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "nextServerSubnet", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1524), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1524), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1524), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_nextServerSubnet_Test >); void Dhcp4ParserTest_nextServerSubnet_Test::TestBody() { | |||
| 1525 | ||||
| 1526 | string config = "{ " + genIfaceConfig() + "," | |||
| 1527 | "\"rebind-timer\": 2000, " | |||
| 1528 | "\"renew-timer\": 1000, " | |||
| 1529 | "\"subnet4\": [ { " | |||
| 1530 | " \"id\": 1," | |||
| 1531 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1532 | " \"next-server\": \"1.2.3.4\", " | |||
| 1533 | " \"server-hostname\": \"foo\", " | |||
| 1534 | " \"boot-file-name\": \"bar\", " | |||
| 1535 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1536 | "\"valid-lifetime\": 4000 }"; | |||
| 1537 | ||||
| 1538 | ConstElementPtr json; | |||
| 1539 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_1539 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1539 ; } } else gtest_label_testnothrow_1539 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1539, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1540 | extractConfig(config); | |||
| 1541 | ||||
| 1542 | ConstElementPtr status; | |||
| 1543 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1543; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1543; } } else gtest_label_testnothrow_1543 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1543, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1544 | ||||
| 1545 | // check if returned status is OK | |||
| 1546 | checkResult(status, 0); | |||
| 1547 | ||||
| 1548 | // Now check if the configuration was indeed handled and we have | |||
| 1549 | // expected pool configured. | |||
| 1550 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 1551 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200")); | |||
| 1552 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1552, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 1553 | EXPECT_EQ("1.2.3.4", subnet->getSiaddr().get().toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"1.2.3.4\"" , "subnet->getSiaddr().get().toText()", "1.2.3.4", subnet-> getSiaddr().get().toText()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1553, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1554 | EXPECT_EQ("foo", subnet->getSname().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"foo\"" , "subnet->getSname().get()", "foo", subnet->getSname() .get()))) ; else ::testing::internal::AssertHelper(::testing:: TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1554, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1555 | EXPECT_EQ("bar", subnet->getFilename().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"bar\"" , "subnet->getFilename().get()", "bar", subnet->getFilename ().get()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1555, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1556 | } | |||
| 1557 | ||||
| 1558 | // Test checks several negative scenarios for next-server configuration: bogus | |||
| 1559 | // address, IPv6 address and empty string. | |||
| 1560 | TEST_F(Dhcp4ParserTest, nextServerNegative)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("nextServerNegative") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_nextServerNegative_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_nextServerNegative_Test() = default ; ~Dhcp4ParserTest_nextServerNegative_Test() override = default ; Dhcp4ParserTest_nextServerNegative_Test (const Dhcp4ParserTest_nextServerNegative_Test &) = delete; Dhcp4ParserTest_nextServerNegative_Test & operator=( const Dhcp4ParserTest_nextServerNegative_Test & ) = delete; Dhcp4ParserTest_nextServerNegative_Test (Dhcp4ParserTest_nextServerNegative_Test &&) noexcept = delete; Dhcp4ParserTest_nextServerNegative_Test & operator=( Dhcp4ParserTest_nextServerNegative_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_nextServerNegative_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "nextServerNegative", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1560), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1560), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1560), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_nextServerNegative_Test >); void Dhcp4ParserTest_nextServerNegative_Test::TestBody () { | |||
| 1561 | IfaceMgrTestConfig test_config(true); | |||
| 1562 | ||||
| 1563 | // Config with junk instead of next-server address | |||
| 1564 | string config_bogus1 = "{ " + genIfaceConfig() + "," | |||
| 1565 | "\"rebind-timer\": 2000, " | |||
| 1566 | "\"renew-timer\": 1000, " | |||
| 1567 | "\"subnet4\": [ { " | |||
| 1568 | " \"id\": 1," | |||
| 1569 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1570 | " \"rebind-timer\": 2000, " | |||
| 1571 | " \"renew-timer\": 1000, " | |||
| 1572 | " \"next-server\": \"a.b.c.d\", " | |||
| 1573 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1574 | "\"valid-lifetime\": 4000 }"; | |||
| 1575 | ||||
| 1576 | // Config with IPv6 next server address | |||
| 1577 | string config_bogus2 = "{ " + genIfaceConfig() + "," | |||
| 1578 | "\"rebind-timer\": 2000, " | |||
| 1579 | "\"renew-timer\": 1000, " | |||
| 1580 | "\"subnet4\": [ { " | |||
| 1581 | " \"id\": 1," | |||
| 1582 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1583 | " \"rebind-timer\": 2000, " | |||
| 1584 | " \"renew-timer\": 1000, " | |||
| 1585 | " \"next-server\": \"2001:db8::1\", " | |||
| 1586 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1587 | "\"valid-lifetime\": 4000 }"; | |||
| 1588 | ||||
| 1589 | // Config with empty next server address | |||
| 1590 | string config_bogus3 = "{ " + genIfaceConfig() + "," | |||
| 1591 | "\"rebind-timer\": 2000, " | |||
| 1592 | "\"renew-timer\": 1000, " | |||
| 1593 | "\"subnet4\": [ { " | |||
| 1594 | " \"id\": 1," | |||
| 1595 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1596 | " \"rebind-timer\": 2000, " | |||
| 1597 | " \"renew-timer\": 1000, " | |||
| 1598 | " \"next-server\": \"\", " | |||
| 1599 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1600 | "\"valid-lifetime\": 4000 }"; | |||
| 1601 | ||||
| 1602 | // Config with too large server-hostname | |||
| 1603 | string bigsname(Pkt4::MAX_SNAME_LEN + 1, ' '); | |||
| 1604 | string config_bogus4 = "{ " + genIfaceConfig() + "," | |||
| 1605 | "\"rebind-timer\": 2000, " | |||
| 1606 | "\"renew-timer\": 1000, " | |||
| 1607 | "\"subnet4\": [ { " | |||
| 1608 | " \"id\": 1," | |||
| 1609 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1610 | " \"rebind-timer\": 2000, " | |||
| 1611 | " \"renew-timer\": 1000, " | |||
| 1612 | " \"server-hostname\": \"" + bigsname + "\", " + | |||
| 1613 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1614 | "\"valid-lifetime\": 4000 }"; | |||
| 1615 | ||||
| 1616 | // Config with too large boot-file-hostname | |||
| 1617 | string bigfilename(Pkt4::MAX_FILE_LEN + 1, ' '); | |||
| 1618 | string config_bogus5 = "{ " + genIfaceConfig() + "," | |||
| 1619 | "\"rebind-timer\": 2000, " | |||
| 1620 | "\"renew-timer\": 1000, " | |||
| 1621 | "\"subnet4\": [ { " | |||
| 1622 | " \"id\": 1," | |||
| 1623 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1624 | " \"rebind-timer\": 2000, " | |||
| 1625 | " \"renew-timer\": 1000, " | |||
| 1626 | " \"boot-file-name\": \"" + bigfilename + "\", " + | |||
| 1627 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1628 | "\"valid-lifetime\": 4000 }"; | |||
| 1629 | ||||
| 1630 | ConstElementPtr json1; | |||
| 1631 | ASSERT_NO_THROW(json1 = parseDHCP4(config_bogus1))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json1 = parseDHCP4(config_bogus1); } else static_assert(true , ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1631 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1631 ; } } else gtest_label_testnothrow_1631 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1631, ("Expected: " "json1 = parseDHCP4(config_bogus1)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1632 | ConstElementPtr json2; | |||
| 1633 | ASSERT_NO_THROW(json2 = parseDHCP4(config_bogus2))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json2 = parseDHCP4(config_bogus2); } else static_assert(true , ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1633 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1633 ; } } else gtest_label_testnothrow_1633 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1633, ("Expected: " "json2 = parseDHCP4(config_bogus2)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1634 | ConstElementPtr json3; | |||
| 1635 | ASSERT_NO_THROW(json3 = parseDHCP4(config_bogus3))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json3 = parseDHCP4(config_bogus3); } else static_assert(true , ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1635 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1635 ; } } else gtest_label_testnothrow_1635 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1635, ("Expected: " "json3 = parseDHCP4(config_bogus3)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1636 | ConstElementPtr json4; | |||
| 1637 | ASSERT_NO_THROW(json4 = parseDHCP4(config_bogus4))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json4 = parseDHCP4(config_bogus4); } else static_assert(true , ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1637 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1637 ; } } else gtest_label_testnothrow_1637 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1637, ("Expected: " "json4 = parseDHCP4(config_bogus4)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1638 | ConstElementPtr json5; | |||
| 1639 | ASSERT_NO_THROW(json5 = parseDHCP4(config_bogus5))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json5 = parseDHCP4(config_bogus5); } else static_assert(true , ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_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/bin/dhcp4/tests/config_parser_unittest.cc" , 1639, ("Expected: " "json5 = parseDHCP4(config_bogus5)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1640 | ||||
| 1641 | // check if returned status is always a failure | |||
| 1642 | ConstElementPtr status; | |||
| 1643 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json1))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json1); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1643; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1643; } } else gtest_label_testnothrow_1643 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1643, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json1)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1644 | checkResult(status, 1); | |||
| 1645 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1645, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 1646 | ||||
| 1647 | CfgMgr::instance().clear(); | |||
| 1648 | ||||
| 1649 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json2))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json2); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1649; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1649; } } else gtest_label_testnothrow_1649 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1649, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json2)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1650 | checkResult(status, 1); | |||
| 1651 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1651, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 1652 | ||||
| 1653 | CfgMgr::instance().clear(); | |||
| 1654 | ||||
| 1655 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json3))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json3); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1655; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1655; } } else gtest_label_testnothrow_1655 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1655, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json3)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1656 | checkResult(status, 0); | |||
| 1657 | EXPECT_FALSE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(errorContainsPosition (status, "<string>")))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1657, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "true" , "false") .c_str()) = ::testing::Message(); | |||
| 1658 | ||||
| 1659 | CfgMgr::instance().clear(); | |||
| 1660 | ||||
| 1661 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json4))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json4); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1661; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1661; } } else gtest_label_testnothrow_1661 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1661, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json4)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1662 | checkResult(status, 1); | |||
| 1663 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1663, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 1664 | ||||
| 1665 | CfgMgr::instance().clear(); | |||
| 1666 | ||||
| 1667 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json5))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json5); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1667; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1667; } } else gtest_label_testnothrow_1667 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1667, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json5)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1668 | checkResult(status, 1); | |||
| 1669 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1669, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 1670 | } | |||
| 1671 | ||||
| 1672 | // Checks if the next-server defined as global value is overridden by subnet | |||
| 1673 | // specific value. | |||
| 1674 | TEST_F(Dhcp4ParserTest, nextServerOverride)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("nextServerOverride") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_nextServerOverride_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_nextServerOverride_Test() = default ; ~Dhcp4ParserTest_nextServerOverride_Test() override = default ; Dhcp4ParserTest_nextServerOverride_Test (const Dhcp4ParserTest_nextServerOverride_Test &) = delete; Dhcp4ParserTest_nextServerOverride_Test & operator=( const Dhcp4ParserTest_nextServerOverride_Test & ) = delete; Dhcp4ParserTest_nextServerOverride_Test (Dhcp4ParserTest_nextServerOverride_Test &&) noexcept = delete; Dhcp4ParserTest_nextServerOverride_Test & operator=( Dhcp4ParserTest_nextServerOverride_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_nextServerOverride_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "nextServerOverride", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1674), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1674), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1674), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_nextServerOverride_Test >); void Dhcp4ParserTest_nextServerOverride_Test::TestBody () { | |||
| 1675 | ||||
| 1676 | string config = "{ " + genIfaceConfig() + "," | |||
| 1677 | "\"rebind-timer\": 2000, " | |||
| 1678 | "\"renew-timer\": 1000, " | |||
| 1679 | "\"next-server\": \"192.0.0.1\", " | |||
| 1680 | "\"server-hostname\": \"nohost\"," | |||
| 1681 | "\"boot-file-name\": \"nofile\"," | |||
| 1682 | "\"subnet4\": [ { " | |||
| 1683 | " \"id\": 1," | |||
| 1684 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1685 | " \"next-server\": \"1.2.3.4\", " | |||
| 1686 | " \"server-hostname\": \"some-name.example.org\"," | |||
| 1687 | " \"boot-file-name\": \"bootfile.efi\"," | |||
| 1688 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1689 | "\"valid-lifetime\": 4000 }"; | |||
| 1690 | ||||
| 1691 | ConstElementPtr json; | |||
| 1692 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_1692 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1692 ; } } else gtest_label_testnothrow_1692 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1692, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1693 | extractConfig(config); | |||
| 1694 | ||||
| 1695 | ConstElementPtr status; | |||
| 1696 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1696; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1696; } } else gtest_label_testnothrow_1696 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1696, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1697 | ||||
| 1698 | // check if returned status is OK | |||
| 1699 | checkResult(status, 0); | |||
| 1700 | ||||
| 1701 | // Now check if the configuration was indeed handled and we have | |||
| 1702 | // expected pool configured. | |||
| 1703 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 1704 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200")); | |||
| 1705 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1705, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 1706 | EXPECT_EQ("1.2.3.4", subnet->getSiaddr().get().toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"1.2.3.4\"" , "subnet->getSiaddr().get().toText()", "1.2.3.4", subnet-> getSiaddr().get().toText()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1706, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1707 | EXPECT_EQ("some-name.example.org", subnet->getSname().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"some-name.example.org\"" , "subnet->getSname().get()", "some-name.example.org", subnet ->getSname().get()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1707, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1708 | EXPECT_EQ("bootfile.efi", subnet->getFilename().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"bootfile.efi\"" , "subnet->getFilename().get()", "bootfile.efi", subnet-> getFilename().get()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1708, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 1709 | } | |||
| 1710 | ||||
| 1711 | // Check whether it is possible to configure echo-client-id | |||
| 1712 | TEST_F(Dhcp4ParserTest, echoClientId)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("echoClientId") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_echoClientId_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_echoClientId_Test() = default; ~Dhcp4ParserTest_echoClientId_Test () override = default; Dhcp4ParserTest_echoClientId_Test (const Dhcp4ParserTest_echoClientId_Test &) = delete; Dhcp4ParserTest_echoClientId_Test & operator=( const Dhcp4ParserTest_echoClientId_Test & ) = delete; Dhcp4ParserTest_echoClientId_Test (Dhcp4ParserTest_echoClientId_Test &&) noexcept = delete; Dhcp4ParserTest_echoClientId_Test & operator=( Dhcp4ParserTest_echoClientId_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_echoClientId_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "echoClientId", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 1712 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1712), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1712), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_echoClientId_Test >); void Dhcp4ParserTest_echoClientId_Test::TestBody() { | |||
| 1713 | ||||
| 1714 | string config_false = "{ " + genIfaceConfig() + "," | |||
| 1715 | "\"rebind-timer\": 2000, " | |||
| 1716 | "\"renew-timer\": 1000, " | |||
| 1717 | "\"echo-client-id\": false," | |||
| 1718 | "\"subnet4\": [ { " | |||
| 1719 | " \"id\": 1," | |||
| 1720 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1721 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1722 | "\"valid-lifetime\": 4000 }"; | |||
| 1723 | ||||
| 1724 | string config_true = "{ " + genIfaceConfig() + "," | |||
| 1725 | "\"rebind-timer\": 2000, " | |||
| 1726 | "\"renew-timer\": 1000, " | |||
| 1727 | "\"echo-client-id\": true," | |||
| 1728 | "\"subnet4\": [ { " | |||
| 1729 | " \"id\": 1," | |||
| 1730 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1731 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1732 | "\"valid-lifetime\": 4000 }"; | |||
| 1733 | ||||
| 1734 | ConstElementPtr json_false; | |||
| 1735 | ASSERT_NO_THROW(json_false = parseDHCP4(config_false))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json_false = parseDHCP4(config_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_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/bin/dhcp4/tests/config_parser_unittest.cc" , 1735, ("Expected: " "json_false = parseDHCP4(config_false)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1736 | extractConfig(config_false); | |||
| 1737 | ConstElementPtr json_true; | |||
| 1738 | ASSERT_NO_THROW(json_true = parseDHCP4(config_true))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json_true = parseDHCP4(config_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_1738 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1738 ; } } else gtest_label_testnothrow_1738 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1738, ("Expected: " "json_true = parseDHCP4(config_true)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1739 | extractConfig(config_true); | |||
| 1740 | ||||
| 1741 | // Let's check the default. It should be true | |||
| 1742 | ASSERT_TRUE(CfgMgr::instance().getStagingCfg()->getEchoClientId())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(CfgMgr::instance().getStagingCfg ()->getEchoClientId())) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1742, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()->getEchoClientId()", "false", "true") .c_str()) = ::testing::Message(); | |||
| 1743 | ||||
| 1744 | // Now check that "false" configuration is really applied. | |||
| 1745 | ConstElementPtr status; | |||
| 1746 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json_false))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json_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_1746; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1746; } } else gtest_label_testnothrow_1746 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1746, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json_false)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1747 | checkResult(status, 0); | |||
| 1748 | ASSERT_FALSE(CfgMgr::instance().getStagingCfg()->getEchoClientId())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(CfgMgr::instance(). getStagingCfg()->getEchoClientId()))) ; else return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 1748 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()->getEchoClientId()", "true", "false") .c_str()) = ::testing::Message(); | |||
| 1749 | ||||
| 1750 | CfgMgr::instance().clear(); | |||
| 1751 | ||||
| 1752 | // Now check that "true" configuration is really applied. | |||
| 1753 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json_true))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json_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_1753; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1753; } } else gtest_label_testnothrow_1753 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1753, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json_true)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1754 | checkResult(status, 0); | |||
| 1755 | ASSERT_TRUE(CfgMgr::instance().getStagingCfg()->getEchoClientId())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(CfgMgr::instance().getStagingCfg ()->getEchoClientId())) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1755, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()->getEchoClientId()", "false", "true") .c_str()) = ::testing::Message(); | |||
| 1756 | ||||
| 1757 | // In any case revert back to the default value (true) | |||
| 1758 | CfgMgr::instance().getStagingCfg()->setEchoClientId(true); | |||
| 1759 | } | |||
| 1760 | ||||
| 1761 | // Check whether it is possible to configure compatibility flags. | |||
| 1762 | TEST_F(Dhcp4ParserTest, compatibility)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("compatibility") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_compatibility_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_compatibility_Test() = default; ~Dhcp4ParserTest_compatibility_Test () override = default; Dhcp4ParserTest_compatibility_Test (const Dhcp4ParserTest_compatibility_Test &) = delete; Dhcp4ParserTest_compatibility_Test & operator=( const Dhcp4ParserTest_compatibility_Test & ) = delete; Dhcp4ParserTest_compatibility_Test (Dhcp4ParserTest_compatibility_Test &&) noexcept = delete; Dhcp4ParserTest_compatibility_Test & operator=( Dhcp4ParserTest_compatibility_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_compatibility_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "compatibility", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 1762 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1762), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1762), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_compatibility_Test >); void Dhcp4ParserTest_compatibility_Test::TestBody() { | |||
| 1763 | string config = "{ " + genIfaceConfig() + "," | |||
| 1764 | "\"rebind-timer\": 2000, " | |||
| 1765 | "\"renew-timer\": 1000, " | |||
| 1766 | "\"compatibility\": { " | |||
| 1767 | " \"lenient-option-parsing\": true," | |||
| 1768 | " \"ignore-dhcp-server-identifier\": true," | |||
| 1769 | " \"ignore-rai-link-selection\": true," | |||
| 1770 | " \"exclude-first-last-24\": true" | |||
| 1771 | "}," | |||
| 1772 | "\"subnet4\": [ { " | |||
| 1773 | " \"id\": 1," | |||
| 1774 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1775 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1776 | "\"valid-lifetime\": 4000 }"; | |||
| 1777 | ||||
| 1778 | ConstElementPtr json; | |||
| 1779 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_1779 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1779 ; } } else gtest_label_testnothrow_1779 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1779, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message () << "bad config: " << config; | |||
| 1780 | extractConfig(config); | |||
| 1781 | ||||
| 1782 | // Check defaults: they should be false. | |||
| 1783 | EXPECT_FALSE(CfgMgr::instance().getStagingCfg()->getLenientOptionParsing())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(CfgMgr::instance(). getStagingCfg()->getLenientOptionParsing()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 1783 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()->getLenientOptionParsing()" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 1784 | EXPECT_FALSE(CfgMgr::instance().getStagingCfg()->getIgnoreServerIdentifier())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(CfgMgr::instance(). getStagingCfg()->getIgnoreServerIdentifier()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 1784 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()->getIgnoreServerIdentifier()" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 1785 | EXPECT_FALSE(CfgMgr::instance().getStagingCfg()->getIgnoreRAILinkSelection())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(CfgMgr::instance(). getStagingCfg()->getIgnoreRAILinkSelection()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 1785 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()->getIgnoreRAILinkSelection()" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 1786 | EXPECT_FALSE(CfgMgr::instance().getStagingCfg()->getExcludeFirstLast24())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(CfgMgr::instance(). getStagingCfg()->getExcludeFirstLast24()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 1786 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()->getExcludeFirstLast24()" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 1787 | ||||
| 1788 | // Check the configuration was really applied. | |||
| 1789 | ConstElementPtr status; | |||
| 1790 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1790; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1790; } } else gtest_label_testnothrow_1790 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1790, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1791 | checkResult(status, 0); | |||
| 1792 | ||||
| 1793 | EXPECT_TRUE(CfgMgr::instance().getStagingCfg()->getLenientOptionParsing())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(CfgMgr::instance().getStagingCfg ()->getLenientOptionParsing())) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1793, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()->getLenientOptionParsing()" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 1794 | EXPECT_TRUE(CfgMgr::instance().getStagingCfg()->getIgnoreServerIdentifier())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(CfgMgr::instance().getStagingCfg ()->getIgnoreServerIdentifier())) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1794, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()->getIgnoreServerIdentifier()" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 1795 | EXPECT_TRUE(CfgMgr::instance().getStagingCfg()->getIgnoreRAILinkSelection())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(CfgMgr::instance().getStagingCfg ()->getIgnoreRAILinkSelection())) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1795, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()->getIgnoreRAILinkSelection()" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 1796 | EXPECT_TRUE(CfgMgr::instance().getStagingCfg()->getExcludeFirstLast24())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(CfgMgr::instance().getStagingCfg ()->getExcludeFirstLast24())) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1796, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()->getExcludeFirstLast24()" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 1797 | } | |||
| 1798 | ||||
| 1799 | // Check that unknown compatibility flag raises error. | |||
| 1800 | TEST_F(Dhcp4ParserTest, compatibilityUnknown)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("compatibilityUnknown") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_compatibilityUnknown_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_compatibilityUnknown_Test() = default ; ~Dhcp4ParserTest_compatibilityUnknown_Test() override = default ; Dhcp4ParserTest_compatibilityUnknown_Test (const Dhcp4ParserTest_compatibilityUnknown_Test &) = delete; Dhcp4ParserTest_compatibilityUnknown_Test & operator=( const Dhcp4ParserTest_compatibilityUnknown_Test & ) = delete; Dhcp4ParserTest_compatibilityUnknown_Test (Dhcp4ParserTest_compatibilityUnknown_Test &&) noexcept = delete; Dhcp4ParserTest_compatibilityUnknown_Test & operator=( Dhcp4ParserTest_compatibilityUnknown_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_compatibilityUnknown_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "compatibilityUnknown", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1800), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1800), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1800), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_compatibilityUnknown_Test >); void Dhcp4ParserTest_compatibilityUnknown_Test::TestBody () { | |||
| 1801 | string config = "{ " + genIfaceConfig() + "," | |||
| 1802 | "\"rebind-timer\": 2000, " | |||
| 1803 | "\"renew-timer\": 1000, " | |||
| 1804 | "\"compatibility\": { " | |||
| 1805 | " \"foo-bar\": true" | |||
| 1806 | "}," | |||
| 1807 | "\"subnet4\": [ { " | |||
| 1808 | " \"id\": 1," | |||
| 1809 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1810 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1811 | "\"valid-lifetime\": 4000 }"; | |||
| 1812 | ||||
| 1813 | // Syntax is incorrect. | |||
| 1814 | EXPECT_THROW(parseDHCP4(config), Dhcp4ParseError)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { parseDHCP4(config); } else static_assert(true, ""); } catch (Dhcp4ParseError const& ) { gtest_caught_expected = true; } catch (typename std::conditional < std::is_same<typename std::remove_cv<typename std:: remove_reference< Dhcp4ParseError>::type>::type, std ::exception>::value, const ::testing::internal::NeverThrown &, const std::exception&>::type e) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\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_1814; } catch (... ) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_1814; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws nothing."; goto gtest_label_testthrow_1814 ; } } else gtest_label_testthrow_1814 : ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1814, gtest_msg.value.c_str()) = ::testing::Message(); | |||
| 1815 | ConstElementPtr json; | |||
| 1816 | EXPECT_NO_THROW(json = parseJSON(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseJSON(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_1816 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1816 ; } } else gtest_label_testnothrow_1816 : ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1816, ("Expected: " "json = parseJSON(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1817 | ||||
| 1818 | // Unknown keyword is detected. | |||
| 1819 | ConstElementPtr status; | |||
| 1820 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1820; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1820; } } else gtest_label_testnothrow_1820 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1820, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1821 | string expected = "unsupported compatibility parameter: "; | |||
| 1822 | expected += "foo-bar (<string>:1:127)"; | |||
| 1823 | checkResult(status, 1, expected); | |||
| 1824 | } | |||
| 1825 | ||||
| 1826 | // Check that not boolean compatibility flag value raises error. | |||
| 1827 | TEST_F(Dhcp4ParserTest, compatibilityNotBool)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("compatibilityNotBool") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_compatibilityNotBool_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_compatibilityNotBool_Test() = default ; ~Dhcp4ParserTest_compatibilityNotBool_Test() override = default ; Dhcp4ParserTest_compatibilityNotBool_Test (const Dhcp4ParserTest_compatibilityNotBool_Test &) = delete; Dhcp4ParserTest_compatibilityNotBool_Test & operator=( const Dhcp4ParserTest_compatibilityNotBool_Test & ) = delete; Dhcp4ParserTest_compatibilityNotBool_Test (Dhcp4ParserTest_compatibilityNotBool_Test &&) noexcept = delete; Dhcp4ParserTest_compatibilityNotBool_Test & operator=( Dhcp4ParserTest_compatibilityNotBool_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_compatibilityNotBool_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "compatibilityNotBool", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1827), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1827), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1827), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_compatibilityNotBool_Test >); void Dhcp4ParserTest_compatibilityNotBool_Test::TestBody () { | |||
| 1828 | string config = "{ " + genIfaceConfig() + "," | |||
| 1829 | "\"rebind-timer\": 2000, " | |||
| 1830 | "\"renew-timer\": 1000, " | |||
| 1831 | "\"compatibility\": { " | |||
| 1832 | " \"lenient-option-parsing\": 1" | |||
| 1833 | "}," | |||
| 1834 | "\"subnet4\": [ { " | |||
| 1835 | " \"id\": 1," | |||
| 1836 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1837 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 1838 | "\"valid-lifetime\": 4000 }"; | |||
| 1839 | ||||
| 1840 | // Syntax is incorrect. | |||
| 1841 | EXPECT_THROW(parseDHCP4(config), Dhcp4ParseError)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { parseDHCP4(config); } else static_assert(true, ""); } catch (Dhcp4ParseError const& ) { gtest_caught_expected = true; } catch (typename std::conditional < std::is_same<typename std::remove_cv<typename std:: remove_reference< Dhcp4ParseError>::type>::type, std ::exception>::value, const ::testing::internal::NeverThrown &, const std::exception&>::type e) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\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_1841; } catch (... ) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_1841; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws nothing."; goto gtest_label_testthrow_1841 ; } } else gtest_label_testthrow_1841 : ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1841, gtest_msg.value.c_str()) = ::testing::Message(); | |||
| 1842 | ConstElementPtr json; | |||
| 1843 | EXPECT_NO_THROW(json = parseJSON(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseJSON(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_1843 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1843 ; } } else gtest_label_testnothrow_1843 : ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1843, ("Expected: " "json = parseJSON(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1844 | ||||
| 1845 | // Bad value type is detected. | |||
| 1846 | ConstElementPtr status; | |||
| 1847 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1847; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1847; } } else gtest_label_testnothrow_1847 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1847, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1848 | string expected = "compatibility parameter values must be boolean "; | |||
| 1849 | expected += "(lenient-option-parsing at <string>:1:142)"; | |||
| 1850 | checkResult(status, 1, expected); | |||
| 1851 | } | |||
| 1852 | ||||
| 1853 | // This test checks that the global match-client-id parameter is optional | |||
| 1854 | // and that values under the subnet are used. | |||
| 1855 | TEST_F(Dhcp4ParserTest, matchClientIdNoGlobal)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("matchClientIdNoGlobal") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_matchClientIdNoGlobal_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_matchClientIdNoGlobal_Test() = default ; ~Dhcp4ParserTest_matchClientIdNoGlobal_Test() override = default ; Dhcp4ParserTest_matchClientIdNoGlobal_Test (const Dhcp4ParserTest_matchClientIdNoGlobal_Test &) = delete; Dhcp4ParserTest_matchClientIdNoGlobal_Test & operator=( const Dhcp4ParserTest_matchClientIdNoGlobal_Test & ) = delete; Dhcp4ParserTest_matchClientIdNoGlobal_Test (Dhcp4ParserTest_matchClientIdNoGlobal_Test &&) noexcept = delete; Dhcp4ParserTest_matchClientIdNoGlobal_Test & operator=( Dhcp4ParserTest_matchClientIdNoGlobal_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_matchClientIdNoGlobal_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "matchClientIdNoGlobal", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1855), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1855), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1855), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_matchClientIdNoGlobal_Test >); void Dhcp4ParserTest_matchClientIdNoGlobal_Test::TestBody () { | |||
| 1856 | std::string config = "{ " + genIfaceConfig() + "," | |||
| 1857 | "\"rebind-timer\": 2000, " | |||
| 1858 | "\"renew-timer\": 1000, " | |||
| 1859 | "\"subnet4\": [ " | |||
| 1860 | "{" | |||
| 1861 | " \"id\": 1," | |||
| 1862 | " \"match-client-id\": true," | |||
| 1863 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1864 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 1865 | "}," | |||
| 1866 | "{" | |||
| 1867 | " \"id\": 2," | |||
| 1868 | " \"match-client-id\": false," | |||
| 1869 | " \"pools\": [ { \"pool\": \"192.0.3.1 - 192.0.3.100\" } ]," | |||
| 1870 | " \"subnet\": \"192.0.3.0/24\"" | |||
| 1871 | "} ]," | |||
| 1872 | "\"valid-lifetime\": 4000 }"; | |||
| 1873 | ||||
| 1874 | ConstElementPtr json; | |||
| 1875 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_1875 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1875 ; } } else gtest_label_testnothrow_1875 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1875, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1876 | extractConfig(config); | |||
| 1877 | ||||
| 1878 | ConstElementPtr status; | |||
| 1879 | ASSERT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1879; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1879; } } else gtest_label_testnothrow_1879 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1879, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1880 | checkResult(status, 0); | |||
| 1881 | ||||
| 1882 | CfgSubnets4Ptr cfg = CfgMgr::instance().getStagingCfg()->getCfgSubnets4(); | |||
| 1883 | ConstSubnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1")); | |||
| 1884 | ASSERT_TRUE(subnet1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet1)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1884, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 1885 | // Reset the fetch global function to staging (vs current) config. | |||
| 1886 | Subnet4Ptr mutable_subnet1 = boost::const_pointer_cast<Subnet4>(subnet1); | |||
| 1887 | mutable_subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr { | |||
| 1888 | return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals()); | |||
| 1889 | }); | |||
| 1890 | EXPECT_TRUE(subnet1->getMatchClientId())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet1->getMatchClientId ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1890, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1->getMatchClientId()", "false", "true") .c_str() ) = ::testing::Message(); | |||
| 1891 | ||||
| 1892 | ConstSubnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1")); | |||
| 1893 | ASSERT_TRUE(subnet2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1893, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 1894 | // Reset the fetch global function to staging (vs current) config. | |||
| 1895 | Subnet4Ptr mutable_subnet2 = boost::const_pointer_cast<Subnet4>(subnet2); | |||
| 1896 | mutable_subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr { | |||
| 1897 | return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals()); | |||
| 1898 | }); | |||
| 1899 | EXPECT_FALSE(subnet2->getMatchClientId())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet2->getMatchClientId ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1899, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2->getMatchClientId()", "true", "false") .c_str() ) = ::testing::Message(); | |||
| 1900 | } | |||
| 1901 | ||||
| 1902 | // This test checks that the global match-client-id parameter is used | |||
| 1903 | // when there is no such parameter under subnet and that the parameter | |||
| 1904 | // specified for a subnet overrides the global setting. | |||
| 1905 | TEST_F(Dhcp4ParserTest, matchClientIdGlobal)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("matchClientIdGlobal") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_matchClientIdGlobal_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_matchClientIdGlobal_Test() = default ; ~Dhcp4ParserTest_matchClientIdGlobal_Test() override = default ; Dhcp4ParserTest_matchClientIdGlobal_Test (const Dhcp4ParserTest_matchClientIdGlobal_Test &) = delete; Dhcp4ParserTest_matchClientIdGlobal_Test & operator=( const Dhcp4ParserTest_matchClientIdGlobal_Test & ) = delete; Dhcp4ParserTest_matchClientIdGlobal_Test (Dhcp4ParserTest_matchClientIdGlobal_Test &&) noexcept = delete; Dhcp4ParserTest_matchClientIdGlobal_Test & operator=( Dhcp4ParserTest_matchClientIdGlobal_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_matchClientIdGlobal_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "matchClientIdGlobal", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1905), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1905), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1905), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_matchClientIdGlobal_Test >); void Dhcp4ParserTest_matchClientIdGlobal_Test::TestBody () { | |||
| 1906 | std::string config = "{ " + genIfaceConfig() + "," | |||
| 1907 | "\"rebind-timer\": 2000, " | |||
| 1908 | "\"renew-timer\": 1000, " | |||
| 1909 | "\"match-client-id\": true," | |||
| 1910 | "\"subnet4\": [ " | |||
| 1911 | "{" | |||
| 1912 | " \"id\": 1," | |||
| 1913 | " \"match-client-id\": false," | |||
| 1914 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1915 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 1916 | "}," | |||
| 1917 | "{" | |||
| 1918 | " \"id\": 2," | |||
| 1919 | " \"pools\": [ { \"pool\": \"192.0.3.1 - 192.0.3.100\" } ]," | |||
| 1920 | " \"subnet\": \"192.0.3.0/24\"" | |||
| 1921 | "} ]," | |||
| 1922 | "\"valid-lifetime\": 4000 }"; | |||
| 1923 | ||||
| 1924 | ConstElementPtr json; | |||
| 1925 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_1925 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1925 ; } } else gtest_label_testnothrow_1925 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1925, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1926 | extractConfig(config); | |||
| 1927 | ||||
| 1928 | ConstElementPtr status; | |||
| 1929 | ASSERT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1929; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1929; } } else gtest_label_testnothrow_1929 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1929, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1930 | checkResult(status, 0); | |||
| 1931 | ||||
| 1932 | CfgSubnets4Ptr cfg = CfgMgr::instance().getStagingCfg()->getCfgSubnets4(); | |||
| 1933 | ConstSubnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1")); | |||
| 1934 | ASSERT_TRUE(subnet1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet1)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1934, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 1935 | // Reset the fetch global function to staging (vs current) config. | |||
| 1936 | Subnet4Ptr mutable_subnet1 = boost::const_pointer_cast<Subnet4>(subnet1); | |||
| 1937 | mutable_subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr { | |||
| 1938 | return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals()); | |||
| 1939 | }); | |||
| 1940 | EXPECT_FALSE(subnet1->getMatchClientId())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet1->getMatchClientId ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1940, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1->getMatchClientId()", "true", "false") .c_str() ) = ::testing::Message(); | |||
| 1941 | ||||
| 1942 | ConstSubnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1")); | |||
| 1943 | ASSERT_TRUE(subnet2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1943, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 1944 | // Reset the fetch global function to staging (vs current) config. | |||
| 1945 | Subnet4Ptr mutable_subnet2 = boost::const_pointer_cast<Subnet4>(subnet2); | |||
| 1946 | mutable_subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr { | |||
| 1947 | return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals()); | |||
| 1948 | }); | |||
| 1949 | EXPECT_TRUE(subnet2->getMatchClientId())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2->getMatchClientId ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1949, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2->getMatchClientId()", "false", "true") .c_str() ) = ::testing::Message(); | |||
| 1950 | } | |||
| 1951 | ||||
| 1952 | // This test checks that the global authoritative parameter is optional | |||
| 1953 | // and that values under the subnet are used. | |||
| 1954 | TEST_F(Dhcp4ParserTest, authoritativeNoGlobal)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("authoritativeNoGlobal") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_authoritativeNoGlobal_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_authoritativeNoGlobal_Test() = default ; ~Dhcp4ParserTest_authoritativeNoGlobal_Test() override = default ; Dhcp4ParserTest_authoritativeNoGlobal_Test (const Dhcp4ParserTest_authoritativeNoGlobal_Test &) = delete; Dhcp4ParserTest_authoritativeNoGlobal_Test & operator=( const Dhcp4ParserTest_authoritativeNoGlobal_Test & ) = delete; Dhcp4ParserTest_authoritativeNoGlobal_Test (Dhcp4ParserTest_authoritativeNoGlobal_Test &&) noexcept = delete; Dhcp4ParserTest_authoritativeNoGlobal_Test & operator=( Dhcp4ParserTest_authoritativeNoGlobal_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_authoritativeNoGlobal_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "authoritativeNoGlobal", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1954), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1954), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1954), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_authoritativeNoGlobal_Test >); void Dhcp4ParserTest_authoritativeNoGlobal_Test::TestBody () { | |||
| 1955 | std::string config = "{ " + genIfaceConfig() + "," | |||
| 1956 | "\"rebind-timer\": 2000, " | |||
| 1957 | "\"renew-timer\": 1000, " | |||
| 1958 | "\"subnet4\": [ " | |||
| 1959 | "{" | |||
| 1960 | " \"id\": 1," | |||
| 1961 | " \"authoritative\": true," | |||
| 1962 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 1963 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 1964 | "}," | |||
| 1965 | "{" | |||
| 1966 | " \"id\": 2," | |||
| 1967 | " \"authoritative\": false," | |||
| 1968 | " \"pools\": [ { \"pool\": \"192.0.3.1 - 192.0.3.100\" } ]," | |||
| 1969 | " \"subnet\": \"192.0.3.0/24\"" | |||
| 1970 | "} ]," | |||
| 1971 | "\"valid-lifetime\": 4000 }"; | |||
| 1972 | ||||
| 1973 | ConstElementPtr json; | |||
| 1974 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_1974 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1974 ; } } else gtest_label_testnothrow_1974 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1974, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 1975 | extractConfig(config); | |||
| 1976 | ||||
| 1977 | ConstElementPtr status; | |||
| 1978 | ASSERT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_1978; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_1978; } } else gtest_label_testnothrow_1978 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1978, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 1979 | checkResult(status, 0); | |||
| 1980 | ||||
| 1981 | CfgSubnets4Ptr cfg = CfgMgr::instance().getStagingCfg()->getCfgSubnets4(); | |||
| 1982 | ConstSubnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1")); | |||
| 1983 | ASSERT_TRUE(subnet1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet1)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1983, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 1984 | // Reset the fetch global function to staging (vs current) config. | |||
| 1985 | Subnet4Ptr mutable_subnet1 = boost::const_pointer_cast<Subnet4>(subnet1); | |||
| 1986 | mutable_subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr { | |||
| 1987 | return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals()); | |||
| 1988 | }); | |||
| 1989 | EXPECT_TRUE(subnet1->getAuthoritative())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet1->getAuthoritative ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1989, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1->getAuthoritative()", "false", "true") .c_str() ) = ::testing::Message(); | |||
| 1990 | ||||
| 1991 | ConstSubnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1")); | |||
| 1992 | ASSERT_TRUE(subnet2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1992, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 1993 | // Reset the fetch global function to staging (vs current) config. | |||
| 1994 | Subnet4Ptr mutable_subnet2 = boost::const_pointer_cast<Subnet4>(subnet2); | |||
| 1995 | mutable_subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr { | |||
| 1996 | return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals()); | |||
| 1997 | }); | |||
| 1998 | EXPECT_FALSE(subnet2->getAuthoritative())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet2->getAuthoritative ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 1998, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2->getAuthoritative()", "true", "false") .c_str() ) = ::testing::Message(); | |||
| 1999 | } | |||
| 2000 | ||||
| 2001 | // This test checks that the global authoritative parameter is used | |||
| 2002 | // when there is no such parameter under subnet and that the parameter | |||
| 2003 | // specified for a subnet overrides the global setting. | |||
| 2004 | TEST_F(Dhcp4ParserTest, authoritativeGlobal)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("authoritativeGlobal") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_authoritativeGlobal_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_authoritativeGlobal_Test() = default ; ~Dhcp4ParserTest_authoritativeGlobal_Test() override = default ; Dhcp4ParserTest_authoritativeGlobal_Test (const Dhcp4ParserTest_authoritativeGlobal_Test &) = delete; Dhcp4ParserTest_authoritativeGlobal_Test & operator=( const Dhcp4ParserTest_authoritativeGlobal_Test & ) = delete; Dhcp4ParserTest_authoritativeGlobal_Test (Dhcp4ParserTest_authoritativeGlobal_Test &&) noexcept = delete; Dhcp4ParserTest_authoritativeGlobal_Test & operator=( Dhcp4ParserTest_authoritativeGlobal_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_authoritativeGlobal_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "authoritativeGlobal", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2004), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2004), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2004), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_authoritativeGlobal_Test >); void Dhcp4ParserTest_authoritativeGlobal_Test::TestBody () { | |||
| 2005 | std::string config = "{ " + genIfaceConfig() + "," | |||
| 2006 | "\"rebind-timer\": 2000, " | |||
| 2007 | "\"renew-timer\": 1000, " | |||
| 2008 | "\"authoritative\": true," | |||
| 2009 | "\"subnet4\": [ " | |||
| 2010 | "{" | |||
| 2011 | " \"id\": 1," | |||
| 2012 | " \"authoritative\": false," | |||
| 2013 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 2014 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 2015 | "}," | |||
| 2016 | "{" | |||
| 2017 | " \"id\": 2," | |||
| 2018 | " \"pools\": [ { \"pool\": \"192.0.3.1 - 192.0.3.100\" } ]," | |||
| 2019 | " \"subnet\": \"192.0.3.0/24\"" | |||
| 2020 | "} ]," | |||
| 2021 | "\"valid-lifetime\": 4000 }"; | |||
| 2022 | ||||
| 2023 | ConstElementPtr json; | |||
| 2024 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_2024 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2024 ; } } else gtest_label_testnothrow_2024 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2024, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2025 | extractConfig(config); | |||
| 2026 | ||||
| 2027 | ConstElementPtr status; | |||
| 2028 | ASSERT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2028; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2028; } } else gtest_label_testnothrow_2028 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2028, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2029 | checkResult(status, 0); | |||
| 2030 | ||||
| 2031 | CfgSubnets4Ptr cfg = CfgMgr::instance().getStagingCfg()->getCfgSubnets4(); | |||
| 2032 | ConstSubnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1")); | |||
| 2033 | ASSERT_TRUE(subnet1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet1)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2033, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 2034 | // Reset the fetch global function to staging (vs current) config. | |||
| 2035 | Subnet4Ptr mutable_subnet1 = boost::const_pointer_cast<Subnet4>(subnet1); | |||
| 2036 | mutable_subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr { | |||
| 2037 | return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals()); | |||
| 2038 | }); | |||
| 2039 | EXPECT_FALSE(subnet1->getAuthoritative())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet1->getAuthoritative ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2039, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1->getAuthoritative()", "true", "false") .c_str() ) = ::testing::Message(); | |||
| 2040 | ||||
| 2041 | ConstSubnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1")); | |||
| 2042 | ASSERT_TRUE(subnet2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2042, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 2043 | // Reset the fetch global function to staging (vs current) config. | |||
| 2044 | Subnet4Ptr mutable_subnet2 = boost::const_pointer_cast<Subnet4>(subnet2); | |||
| 2045 | mutable_subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr { | |||
| 2046 | return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals()); | |||
| 2047 | }); | |||
| 2048 | EXPECT_TRUE(subnet2->getAuthoritative())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2->getAuthoritative ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2048, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2->getAuthoritative()", "false", "true") .c_str() ) = ::testing::Message(); | |||
| 2049 | } | |||
| 2050 | ||||
| 2051 | // This test checks if it is possible to override global values | |||
| 2052 | // on a per subnet basis. | |||
| 2053 | TEST_F(Dhcp4ParserTest, subnetLocal)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("subnetLocal") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_subnetLocal_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_subnetLocal_Test() = default; ~Dhcp4ParserTest_subnetLocal_Test () override = default; Dhcp4ParserTest_subnetLocal_Test (const Dhcp4ParserTest_subnetLocal_Test &) = delete; Dhcp4ParserTest_subnetLocal_Test & operator=( const Dhcp4ParserTest_subnetLocal_Test & ) = delete; Dhcp4ParserTest_subnetLocal_Test (Dhcp4ParserTest_subnetLocal_Test &&) noexcept = delete; Dhcp4ParserTest_subnetLocal_Test & operator=( Dhcp4ParserTest_subnetLocal_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_subnetLocal_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "subnetLocal", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2053 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2053), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2053), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_subnetLocal_Test >); void Dhcp4ParserTest_subnetLocal_Test::TestBody() { | |||
| 2054 | ||||
| 2055 | string config = "{ " + genIfaceConfig() + "," | |||
| 2056 | "\"rebind-timer\": 2000, " | |||
| 2057 | "\"renew-timer\": 1000, " | |||
| 2058 | "\"subnet4\": [ { " | |||
| 2059 | " \"id\": 1," | |||
| 2060 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 2061 | " \"renew-timer\": 1, " | |||
| 2062 | " \"rebind-timer\": 2, " | |||
| 2063 | " \"valid-lifetime\": 4," | |||
| 2064 | " \"min-valid-lifetime\": 3," | |||
| 2065 | " \"max-valid-lifetime\": 5," | |||
| 2066 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 2067 | "\"valid-lifetime\": 4000," | |||
| 2068 | "\"min-valid-lifetime\": 3000," | |||
| 2069 | "\"max-valid-lifetime\": 5000 }"; | |||
| 2070 | ||||
| 2071 | ConstElementPtr json; | |||
| 2072 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_2072 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2072 ; } } else gtest_label_testnothrow_2072 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2072, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2073 | extractConfig(config); | |||
| 2074 | ||||
| 2075 | ConstElementPtr status; | |||
| 2076 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2076; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2076; } } else gtest_label_testnothrow_2076 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2076, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2077 | ||||
| 2078 | // returned value should be 0 (configuration success) | |||
| 2079 | checkResult(status, 0); | |||
| 2080 | ||||
| 2081 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 2082 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200")); | |||
| 2083 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2083, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2084 | EXPECT_EQ(1, subnet->getT1().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "subnet->getT1().get()" , 1, subnet->getT1().get()))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2084, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2085 | EXPECT_EQ(2, subnet->getT2().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "subnet->getT2().get()" , 2, subnet->getT2().get()))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2085, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2086 | EXPECT_EQ(4, subnet->getValid().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("4", "subnet->getValid().get()" , 4, subnet->getValid().get()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2086, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2087 | EXPECT_EQ(3, subnet->getValid().getMin())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("3", "subnet->getValid().getMin()" , 3, subnet->getValid().getMin()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2087, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2088 | EXPECT_EQ(5, subnet->getValid().getMax())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("5", "subnet->getValid().getMax()" , 5, subnet->getValid().getMax()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2088, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2089 | } | |||
| 2090 | ||||
| 2091 | // This test checks if it is possible to define a subnet with an | |||
| 2092 | // interface defined. | |||
| 2093 | TEST_F(Dhcp4ParserTest, subnetInterface)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("subnetInterface") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_subnetInterface_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_subnetInterface_Test() = default; ~ Dhcp4ParserTest_subnetInterface_Test() override = default; Dhcp4ParserTest_subnetInterface_Test (const Dhcp4ParserTest_subnetInterface_Test &) = delete; Dhcp4ParserTest_subnetInterface_Test & operator=( const Dhcp4ParserTest_subnetInterface_Test &) = delete; Dhcp4ParserTest_subnetInterface_Test (Dhcp4ParserTest_subnetInterface_Test &&) noexcept = delete; Dhcp4ParserTest_subnetInterface_Test & operator=( Dhcp4ParserTest_subnetInterface_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_subnetInterface_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "subnetInterface", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2093 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2093), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2093), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_subnetInterface_Test >); void Dhcp4ParserTest_subnetInterface_Test::TestBody() { | |||
| 2094 | ||||
| 2095 | // There should be at least one interface | |||
| 2096 | // As far as I can tell, this is the first lambda in Kea code. Cool. | |||
| 2097 | auto config = [this](string iface) { | |||
| 2098 | return ("{ " + genIfaceConfig() + "," | |||
| 2099 | "\"rebind-timer\": 2000, " | |||
| 2100 | "\"renew-timer\": 1000, " | |||
| 2101 | "\"subnet4\": [ { " | |||
| 2102 | " \"id\": 1," | |||
| 2103 | " \"pools\": [ { " | |||
| 2104 | " \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 2105 | " \"interface\": \"" + iface + "\"," | |||
| 2106 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 2107 | "\"valid-lifetime\": 4000 }"); }; | |||
| 2108 | cout << config(valid_iface_) << endl; | |||
| 2109 | ||||
| 2110 | ConstElementPtr json; | |||
| 2111 | ASSERT_NO_THROW(json = parseDHCP4(config(valid_iface_)))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(config(valid_iface_)); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_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/bin/dhcp4/tests/config_parser_unittest.cc" , 2111, ("Expected: " "json = parseDHCP4(config(valid_iface_))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2112 | extractConfig(config("eth0")); | |||
| 2113 | ||||
| 2114 | ConstElementPtr status; | |||
| 2115 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2115; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2115; } } else gtest_label_testnothrow_2115 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2115, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2116 | ||||
| 2117 | // returned value should be 0 (configuration success) | |||
| 2118 | checkResult(status, 0); | |||
| 2119 | ||||
| 2120 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 2121 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200"), classify_); | |||
| 2122 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2122, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2123 | EXPECT_EQ(valid_iface_, subnet->getIface().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("valid_iface_" , "subnet->getIface().get()", valid_iface_, subnet->getIface ().get()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2123, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2124 | } | |||
| 2125 | ||||
| 2126 | // This test checks if invalid interface name will be rejected in | |||
| 2127 | // Subnet4 definition. | |||
| 2128 | TEST_F(Dhcp4ParserTest, subnetInterfaceBogus)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("subnetInterfaceBogus") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_subnetInterfaceBogus_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_subnetInterfaceBogus_Test() = default ; ~Dhcp4ParserTest_subnetInterfaceBogus_Test() override = default ; Dhcp4ParserTest_subnetInterfaceBogus_Test (const Dhcp4ParserTest_subnetInterfaceBogus_Test &) = delete; Dhcp4ParserTest_subnetInterfaceBogus_Test & operator=( const Dhcp4ParserTest_subnetInterfaceBogus_Test & ) = delete; Dhcp4ParserTest_subnetInterfaceBogus_Test (Dhcp4ParserTest_subnetInterfaceBogus_Test &&) noexcept = delete; Dhcp4ParserTest_subnetInterfaceBogus_Test & operator=( Dhcp4ParserTest_subnetInterfaceBogus_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_subnetInterfaceBogus_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "subnetInterfaceBogus", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2128), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2128), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2128), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_subnetInterfaceBogus_Test >); void Dhcp4ParserTest_subnetInterfaceBogus_Test::TestBody () { | |||
| 2129 | ||||
| 2130 | // There should be at least one interface | |||
| 2131 | ||||
| 2132 | string config = "{ " + genIfaceConfig() + "," | |||
| 2133 | "\"rebind-timer\": 2000, " | |||
| 2134 | "\"renew-timer\": 1000, " | |||
| 2135 | "\"subnet4\": [ { " | |||
| 2136 | " \"id\": 1," | |||
| 2137 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 2138 | " \"interface\": \"" + bogus_iface_ + "\"," | |||
| 2139 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 2140 | "\"valid-lifetime\": 4000 }"; | |||
| 2141 | cout << config << endl; | |||
| 2142 | ||||
| 2143 | ConstElementPtr json; | |||
| 2144 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_2144 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2144 ; } } else gtest_label_testnothrow_2144 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2144, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2145 | ||||
| 2146 | ConstElementPtr status; | |||
| 2147 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2147; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2147; } } else gtest_label_testnothrow_2147 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2147, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2148 | ||||
| 2149 | // returned value should be 1 (configuration error) | |||
| 2150 | checkResult(status, 1); | |||
| 2151 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2151, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 2152 | ||||
| 2153 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 2154 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200"), classify_); | |||
| 2155 | EXPECT_FALSE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2155 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "true", "false") .c_str()) = ::testing::Message(); | |||
| 2156 | } | |||
| 2157 | ||||
| 2158 | // This test checks if it is not allowed to define global interface | |||
| 2159 | // parameter. | |||
| 2160 | TEST_F(Dhcp4ParserTest, interfaceGlobal)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("interfaceGlobal") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_interfaceGlobal_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_interfaceGlobal_Test() = default; ~ Dhcp4ParserTest_interfaceGlobal_Test() override = default; Dhcp4ParserTest_interfaceGlobal_Test (const Dhcp4ParserTest_interfaceGlobal_Test &) = delete; Dhcp4ParserTest_interfaceGlobal_Test & operator=( const Dhcp4ParserTest_interfaceGlobal_Test &) = delete; Dhcp4ParserTest_interfaceGlobal_Test (Dhcp4ParserTest_interfaceGlobal_Test &&) noexcept = delete; Dhcp4ParserTest_interfaceGlobal_Test & operator=( Dhcp4ParserTest_interfaceGlobal_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_interfaceGlobal_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "interfaceGlobal", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2160 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2160), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2160), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_interfaceGlobal_Test >); void Dhcp4ParserTest_interfaceGlobal_Test::TestBody() { | |||
| 2161 | ||||
| 2162 | string config = "{ " + genIfaceConfig() + "," | |||
| 2163 | "\"rebind-timer\": 2000, " | |||
| 2164 | "\"renew-timer\": 1000, " | |||
| 2165 | "\"interface\": \"" + valid_iface_ + "\"," // Not valid. Can be defined in subnet only | |||
| 2166 | "\"subnet4\": [ { " | |||
| 2167 | " \"id\": 1," | |||
| 2168 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 2169 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 2170 | "\"valid-lifetime\": 4000 }"; | |||
| 2171 | cout << config << endl; | |||
| 2172 | ||||
| 2173 | ConstElementPtr json = parseJSON(config); | |||
| 2174 | ||||
| 2175 | ConstElementPtr status; | |||
| 2176 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2176; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2176; } } else gtest_label_testnothrow_2176 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2176, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2177 | ||||
| 2178 | // returned value should be 1 (parse error) | |||
| 2179 | checkResult(status, 1); | |||
| 2180 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2180, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 2181 | ||||
| 2182 | EXPECT_THROW(parseDHCP4(config), Dhcp4ParseError)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { parseDHCP4(config); } else static_assert(true, ""); } catch (Dhcp4ParseError const& ) { gtest_caught_expected = true; } catch (typename std::conditional < std::is_same<typename std::remove_cv<typename std:: remove_reference< Dhcp4ParseError>::type>::type, std ::exception>::value, const ::testing::internal::NeverThrown &, const std::exception&>::type e) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\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_2182; } catch (... ) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_2182; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws nothing."; goto gtest_label_testthrow_2182 ; } } else gtest_label_testthrow_2182 : ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2182, gtest_msg.value.c_str()) = ::testing::Message(); | |||
| 2183 | } | |||
| 2184 | ||||
| 2185 | // Goal of this test is to verify that invalid subnet fails to be parsed. | |||
| 2186 | TEST_F(Dhcp4ParserTest, badSubnetValues)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("badSubnetValues") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_badSubnetValues_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_badSubnetValues_Test() = default; ~ Dhcp4ParserTest_badSubnetValues_Test() override = default; Dhcp4ParserTest_badSubnetValues_Test (const Dhcp4ParserTest_badSubnetValues_Test &) = delete; Dhcp4ParserTest_badSubnetValues_Test & operator=( const Dhcp4ParserTest_badSubnetValues_Test &) = delete; Dhcp4ParserTest_badSubnetValues_Test (Dhcp4ParserTest_badSubnetValues_Test &&) noexcept = delete; Dhcp4ParserTest_badSubnetValues_Test & operator=( Dhcp4ParserTest_badSubnetValues_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_badSubnetValues_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "badSubnetValues", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2186 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2186), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2186), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_badSubnetValues_Test >); void Dhcp4ParserTest_badSubnetValues_Test::TestBody() { | |||
| 2187 | ||||
| 2188 | // Contains parts needed for a single test scenario. | |||
| 2189 | struct Scenario { | |||
| 2190 | std::string description_; | |||
| 2191 | std::string config_json_; | |||
| 2192 | std::string exp_error_msg_; | |||
| 2193 | }; | |||
| 2194 | ||||
| 2195 | // Vector of scenarios. | |||
| 2196 | std::vector<Scenario> scenarios = { | |||
| 2197 | { | |||
| 2198 | "IP is not an address", | |||
| 2199 | "{ \"subnet4\": [ { " | |||
| 2200 | " \"subnet\": \"not an address/24\" } ]," | |||
| 2201 | "\"valid-lifetime\": 4000 }", | |||
| 2202 | "subnet configuration failed: " | |||
| 2203 | "Failed to convert string to address 'notanaddress': Invalid argument" | |||
| 2204 | }, | |||
| 2205 | { | |||
| 2206 | "IP is Invalid", | |||
| 2207 | "{ \"subnet4\": [ { " | |||
| 2208 | " \"subnet\": \"256.16.1.0/24\" } ]," | |||
| 2209 | "\"valid-lifetime\": 4000 }", | |||
| 2210 | "subnet configuration failed: " | |||
| 2211 | "Failed to convert string to address '256.16.1.0': Invalid argument" | |||
| 2212 | }, | |||
| 2213 | { | |||
| 2214 | "Missing prefix", | |||
| 2215 | "{ \"subnet4\": [ { " | |||
| 2216 | " \"subnet\": \"192.0.2.0\" } ]," | |||
| 2217 | "\"valid-lifetime\": 4000 }", | |||
| 2218 | "subnet configuration failed: " | |||
| 2219 | "Invalid subnet syntax (prefix/len expected):192.0.2.0 (<string>:1:32)" | |||
| 2220 | }, | |||
| 2221 | { | |||
| 2222 | "Prefix not an integer (2 slashes)", | |||
| 2223 | "{ \"subnet4\": [ { " | |||
| 2224 | " \"subnet\": \"192.0.2.0//24\" } ]," | |||
| 2225 | "\"valid-lifetime\": 4000 }", | |||
| 2226 | "subnet configuration failed: " | |||
| 2227 | "prefix length: '/24' is not an integer (<string>:1:32)" | |||
| 2228 | }, | |||
| 2229 | { | |||
| 2230 | "Prefix value is insane", | |||
| 2231 | "{ \"subnet4\": [ { " | |||
| 2232 | " \"subnet\": \"192.0.2.0/45938\" } ]," | |||
| 2233 | "\"valid-lifetime\": 4000 }", | |||
| 2234 | "subnet configuration failed: " | |||
| 2235 | "Invalid prefix length specified for subnet: 45938 (<string>:1:32)" | |||
| 2236 | } | |||
| 2237 | }; | |||
| 2238 | ||||
| 2239 | // Iterate over the list of scenarios. Each should fail to parse with | |||
| 2240 | // a specific error message. | |||
| 2241 | for (auto const& scenario : scenarios) { | |||
| 2242 | SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_2242( "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2242, (scenario.description_)); | |||
| 2243 | ConstElementPtr config; | |||
| 2244 | ASSERT_NO_THROW(config = parseDHCP4(scenario.config_json_))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { config = parseDHCP4(scenario.config_json_); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2244; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2244; } } else gtest_label_testnothrow_2244 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2244, ("Expected: " "config = parseDHCP4(scenario.config_json_)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() | |||
| 2245 | << "invalid json, broken test"; | |||
| 2246 | ConstElementPtr status; | |||
| 2247 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, 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_2247; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2247; } } else gtest_label_testnothrow_2247 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2247, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2248 | checkResult(status, 1); | |||
| 2249 | ASSERT_TRUE(comment_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(comment_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2249, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "comment_", "false", "true") .c_str()) = ::testing::Message (); | |||
| 2250 | EXPECT_EQ(comment_->stringValue(), scenario.exp_error_msg_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("comment_->stringValue()" , "scenario.exp_error_msg_", comment_->stringValue(), scenario .exp_error_msg_))) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2250, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2251 | } | |||
| 2252 | } | |||
| 2253 | ||||
| 2254 | // This test checks that multiple pools can be defined and handled properly. | |||
| 2255 | // The test defines 2 subnets, each with 2 pools. | |||
| 2256 | TEST_F(Dhcp4ParserTest, multiplePools)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("multiplePools") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_multiplePools_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_multiplePools_Test() = default; ~Dhcp4ParserTest_multiplePools_Test () override = default; Dhcp4ParserTest_multiplePools_Test (const Dhcp4ParserTest_multiplePools_Test &) = delete; Dhcp4ParserTest_multiplePools_Test & operator=( const Dhcp4ParserTest_multiplePools_Test & ) = delete; Dhcp4ParserTest_multiplePools_Test (Dhcp4ParserTest_multiplePools_Test &&) noexcept = delete; Dhcp4ParserTest_multiplePools_Test & operator=( Dhcp4ParserTest_multiplePools_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_multiplePools_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "multiplePools", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2256 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2256), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2256), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_multiplePools_Test >); void Dhcp4ParserTest_multiplePools_Test::TestBody() { | |||
| 2257 | // Collection with two subnets, each with 2 pools. | |||
| 2258 | string config = "{ " + genIfaceConfig() + "," | |||
| 2259 | "\"rebind-timer\": 2000, " | |||
| 2260 | "\"renew-timer\": 1000, " | |||
| 2261 | "\"subnet4\": [ { " | |||
| 2262 | " \"id\": 1," | |||
| 2263 | " \"pools\": [ " | |||
| 2264 | " { \"pool\": \"192.0.2.0/28\" }," | |||
| 2265 | " { \"pool\": \"192.0.2.200-192.0.2.255\" }" | |||
| 2266 | " ]," | |||
| 2267 | " \"subnet\": \"192.0.2.0/24\" " | |||
| 2268 | " }," | |||
| 2269 | " {" | |||
| 2270 | " \"id\": 2," | |||
| 2271 | " \"pools\": [ " | |||
| 2272 | " { \"pool\": \"192.0.3.0/25\" }," | |||
| 2273 | " { \"pool\": \"192.0.3.128/25\" }" | |||
| 2274 | " ]," | |||
| 2275 | " \"subnet\": \"192.0.3.0/24\"" | |||
| 2276 | " } ]," | |||
| 2277 | "\"valid-lifetime\": 4000 }"; | |||
| 2278 | ConstElementPtr json; | |||
| 2279 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_2279 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2279 ; } } else gtest_label_testnothrow_2279 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2279, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2280 | extractConfig(config); | |||
| 2281 | ||||
| 2282 | ConstElementPtr status; | |||
| 2283 | ASSERT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2283; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2283; } } else gtest_label_testnothrow_2283 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2283, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2284 | checkResult(status, 0); | |||
| 2285 | ||||
| 2286 | const Subnet4Collection* subnets = | |||
| 2287 | CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->getAll(); | |||
| 2288 | ASSERT_TRUE(subnets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnets)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2288, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnets", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 2289 | ASSERT_EQ(2, subnets->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "subnets->size()" , 2, subnets->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2289, gtest_ar.failure_message()) = ::testing::Message(); // We expect 2 subnets | |||
| 2290 | ||||
| 2291 | // Check the first subnet | |||
| 2292 | auto subnet = subnets->begin(); | |||
| 2293 | const PoolCollection& pools1 = (*subnet)->getPools(Lease::TYPE_V4); | |||
| 2294 | ASSERT_EQ(2, pools1.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "pools1.size()" , 2, pools1.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2294, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2295 | EXPECT_EQ("type=V4, 192.0.2.0-192.0.2.15",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"type=V4, 192.0.2.0-192.0.2.15\"" , "pools1[0]->toText()", "type=V4, 192.0.2.0-192.0.2.15", pools1 [0]->toText()))) ; else ::testing::internal::AssertHelper( ::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2296, gtest_ar.failure_message()) = ::testing::Message() | |||
| 2296 | pools1[0]->toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"type=V4, 192.0.2.0-192.0.2.15\"" , "pools1[0]->toText()", "type=V4, 192.0.2.0-192.0.2.15", pools1 [0]->toText()))) ; else ::testing::internal::AssertHelper( ::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2296, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2297 | EXPECT_EQ("type=V4, 192.0.2.200-192.0.2.255",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"type=V4, 192.0.2.200-192.0.2.255\"" , "pools1[1]->toText()", "type=V4, 192.0.2.200-192.0.2.255" , pools1[1]->toText()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2298, gtest_ar.failure_message()) = ::testing::Message() | |||
| 2298 | pools1[1]->toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"type=V4, 192.0.2.200-192.0.2.255\"" , "pools1[1]->toText()", "type=V4, 192.0.2.200-192.0.2.255" , pools1[1]->toText()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2298, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2299 | // There shouldn't be any TA or PD pools | |||
| 2300 | EXPECT_THROW((*subnet)->getPools(Lease::TYPE_TA), BadValue)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { (*subnet)->getPools(Lease ::TYPE_TA); } 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: " "(*subnet)->getPools(Lease::TYPE_TA)" " 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_2300 ; } catch (...) { gtest_msg.value = "Expected: " "(*subnet)->getPools(Lease::TYPE_TA)" " throws an exception of type " "BadValue" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_2300; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "(*subnet)->getPools(Lease::TYPE_TA)" " throws an exception of type " "BadValue" ".\n Actual: it throws nothing." ; goto gtest_label_testthrow_2300; } } else gtest_label_testthrow_2300 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2300, gtest_msg.value.c_str()) = ::testing::Message(); | |||
| 2301 | EXPECT_THROW((*subnet)->getPools(Lease::TYPE_PD), BadValue)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { (*subnet)->getPools(Lease ::TYPE_PD); } 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: " "(*subnet)->getPools(Lease::TYPE_PD)" " 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_2301 ; } catch (...) { gtest_msg.value = "Expected: " "(*subnet)->getPools(Lease::TYPE_PD)" " throws an exception of type " "BadValue" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_2301; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "(*subnet)->getPools(Lease::TYPE_PD)" " throws an exception of type " "BadValue" ".\n Actual: it throws nothing." ; goto gtest_label_testthrow_2301; } } else gtest_label_testthrow_2301 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2301, gtest_msg.value.c_str()) = ::testing::Message(); | |||
| 2302 | ||||
| 2303 | // Check the second subnet | |||
| 2304 | ++subnet; | |||
| 2305 | const PoolCollection& pools2 = (*subnet)->getPools(Lease::TYPE_V4); | |||
| 2306 | ASSERT_EQ(2, pools2.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "pools2.size()" , 2, pools2.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2306, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2307 | EXPECT_EQ("type=V4, 192.0.3.0-192.0.3.127",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"type=V4, 192.0.3.0-192.0.3.127\"" , "pools2[0]->toText()", "type=V4, 192.0.3.0-192.0.3.127", pools2[0]->toText()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2308, gtest_ar.failure_message()) = ::testing::Message() | |||
| 2308 | pools2[0]->toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"type=V4, 192.0.3.0-192.0.3.127\"" , "pools2[0]->toText()", "type=V4, 192.0.3.0-192.0.3.127", pools2[0]->toText()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2308, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2309 | EXPECT_EQ("type=V4, 192.0.3.128-192.0.3.255",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"type=V4, 192.0.3.128-192.0.3.255\"" , "pools2[1]->toText()", "type=V4, 192.0.3.128-192.0.3.255" , pools2[1]->toText()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2310, gtest_ar.failure_message()) = ::testing::Message() | |||
| 2310 | pools2[1]->toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"type=V4, 192.0.3.128-192.0.3.255\"" , "pools2[1]->toText()", "type=V4, 192.0.3.128-192.0.3.255" , pools2[1]->toText()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2310, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2311 | // There shouldn't be any TA or PD pools | |||
| 2312 | EXPECT_THROW((*subnet)->getPools(Lease::TYPE_TA), BadValue)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { (*subnet)->getPools(Lease ::TYPE_TA); } 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: " "(*subnet)->getPools(Lease::TYPE_TA)" " 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_2312 ; } catch (...) { gtest_msg.value = "Expected: " "(*subnet)->getPools(Lease::TYPE_TA)" " throws an exception of type " "BadValue" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_2312; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "(*subnet)->getPools(Lease::TYPE_TA)" " throws an exception of type " "BadValue" ".\n Actual: it throws nothing." ; goto gtest_label_testthrow_2312; } } else gtest_label_testthrow_2312 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2312, gtest_msg.value.c_str()) = ::testing::Message(); | |||
| 2313 | EXPECT_THROW((*subnet)->getPools(Lease::TYPE_PD), BadValue)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { (*subnet)->getPools(Lease ::TYPE_PD); } 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: " "(*subnet)->getPools(Lease::TYPE_PD)" " 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_2313 ; } catch (...) { gtest_msg.value = "Expected: " "(*subnet)->getPools(Lease::TYPE_PD)" " throws an exception of type " "BadValue" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_2313; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "(*subnet)->getPools(Lease::TYPE_PD)" " throws an exception of type " "BadValue" ".\n Actual: it throws nothing." ; goto gtest_label_testthrow_2313; } } else gtest_label_testthrow_2313 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2313, gtest_msg.value.c_str()) = ::testing::Message(); | |||
| 2314 | } | |||
| 2315 | ||||
| 2316 | // Test verifies that a subnet with pool values that do not belong to that | |||
| 2317 | // pool are rejected. | |||
| 2318 | TEST_F(Dhcp4ParserTest, poolOutOfSubnet)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("poolOutOfSubnet") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_poolOutOfSubnet_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_poolOutOfSubnet_Test() = default; ~ Dhcp4ParserTest_poolOutOfSubnet_Test() override = default; Dhcp4ParserTest_poolOutOfSubnet_Test (const Dhcp4ParserTest_poolOutOfSubnet_Test &) = delete; Dhcp4ParserTest_poolOutOfSubnet_Test & operator=( const Dhcp4ParserTest_poolOutOfSubnet_Test &) = delete; Dhcp4ParserTest_poolOutOfSubnet_Test (Dhcp4ParserTest_poolOutOfSubnet_Test &&) noexcept = delete; Dhcp4ParserTest_poolOutOfSubnet_Test & operator=( Dhcp4ParserTest_poolOutOfSubnet_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_poolOutOfSubnet_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "poolOutOfSubnet", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2318 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2318), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2318), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_poolOutOfSubnet_Test >); void Dhcp4ParserTest_poolOutOfSubnet_Test::TestBody() { | |||
| 2319 | ||||
| 2320 | string config = "{ " + genIfaceConfig() + "," | |||
| 2321 | "\"rebind-timer\": 2000, " | |||
| 2322 | "\"renew-timer\": 1000, " | |||
| 2323 | "\"subnet4\": [ { " | |||
| 2324 | " \"id\": 1," | |||
| 2325 | " \"pools\": [ { \"pool\": \"192.0.4.0/28\" } ]," | |||
| 2326 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 2327 | "\"valid-lifetime\": 4000 }"; | |||
| 2328 | ||||
| 2329 | ConstElementPtr json; | |||
| 2330 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_2330 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2330 ; } } else gtest_label_testnothrow_2330 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2330, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2331 | ||||
| 2332 | ConstElementPtr status; | |||
| 2333 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2333; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2333; } } else gtest_label_testnothrow_2333 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2333, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2334 | ||||
| 2335 | // returned value must be 1 (values error) | |||
| 2336 | // as the pool does not belong to that subnet | |||
| 2337 | checkResult(status, 1); | |||
| 2338 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2338, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 2339 | } | |||
| 2340 | ||||
| 2341 | // Goal of this test is to verify if pools can be defined | |||
| 2342 | // using prefix/length notation. There is no separate test for min-max | |||
| 2343 | // notation as it was tested in several previous tests. | |||
| 2344 | TEST_F(Dhcp4ParserTest, poolPrefixLen)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("poolPrefixLen") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_poolPrefixLen_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_poolPrefixLen_Test() = default; ~Dhcp4ParserTest_poolPrefixLen_Test () override = default; Dhcp4ParserTest_poolPrefixLen_Test (const Dhcp4ParserTest_poolPrefixLen_Test &) = delete; Dhcp4ParserTest_poolPrefixLen_Test & operator=( const Dhcp4ParserTest_poolPrefixLen_Test & ) = delete; Dhcp4ParserTest_poolPrefixLen_Test (Dhcp4ParserTest_poolPrefixLen_Test &&) noexcept = delete; Dhcp4ParserTest_poolPrefixLen_Test & operator=( Dhcp4ParserTest_poolPrefixLen_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_poolPrefixLen_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "poolPrefixLen", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2344 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2344), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2344), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_poolPrefixLen_Test >); void Dhcp4ParserTest_poolPrefixLen_Test::TestBody() { | |||
| 2345 | string config = "{ " + genIfaceConfig() + "," | |||
| 2346 | "\"rebind-timer\": 2000, " | |||
| 2347 | "\"renew-timer\": 1000, " | |||
| 2348 | "\"subnet4\": [ { " | |||
| 2349 | " \"id\": 1," | |||
| 2350 | " \"pools\": [ { \"pool\": \"192.0.2.128/28\" } ]," | |||
| 2351 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 2352 | "\"valid-lifetime\": 4000 }"; | |||
| 2353 | ||||
| 2354 | ConstElementPtr json; | |||
| 2355 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_2355 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2355 ; } } else gtest_label_testnothrow_2355 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2355, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2356 | extractConfig(config); | |||
| 2357 | ||||
| 2358 | ConstElementPtr status; | |||
| 2359 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2359; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2359; } } else gtest_label_testnothrow_2359 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2359, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2360 | ||||
| 2361 | // returned value must be 0 (configuration accepted) | |||
| 2362 | checkResult(status, 0); | |||
| 2363 | ||||
| 2364 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 2365 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200")); | |||
| 2366 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2366, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2367 | EXPECT_EQ(1000, subnet->getT1().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1000", "subnet->getT1().get()" , 1000, subnet->getT1().get()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2367, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2368 | EXPECT_EQ(2000, subnet->getT2().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2000", "subnet->getT2().get()" , 2000, subnet->getT2().get()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2368, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2369 | EXPECT_EQ(4000, subnet->getValid().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("4000", "subnet->getValid().get()" , 4000, subnet->getValid().get()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2369, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2370 | } | |||
| 2371 | ||||
| 2372 | // Goal of this test is to verify if invalid pool definitions | |||
| 2373 | // return a location in the error message. | |||
| 2374 | TEST_F(Dhcp4ParserTest, badPools)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("badPools") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_badPools_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_badPools_Test() = default; ~Dhcp4ParserTest_badPools_Test () override = default; Dhcp4ParserTest_badPools_Test (const Dhcp4ParserTest_badPools_Test &) = delete; Dhcp4ParserTest_badPools_Test & operator =( const Dhcp4ParserTest_badPools_Test &) = delete; Dhcp4ParserTest_badPools_Test (Dhcp4ParserTest_badPools_Test &&) noexcept = delete ; Dhcp4ParserTest_badPools_Test & operator=( Dhcp4ParserTest_badPools_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_badPools_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "badPools", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2374 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2374), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2374), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_badPools_Test >); void Dhcp4ParserTest_badPools_Test::TestBody() { | |||
| 2375 | ||||
| 2376 | // not a prefix | |||
| 2377 | string config_bogus1 = "{ " + genIfaceConfig() + "," | |||
| 2378 | "\"rebind-timer\": 2000, " | |||
| 2379 | "\"renew-timer\": 1000, " | |||
| 2380 | "\"subnet4\": [ { " | |||
| 2381 | " \"id\": 1," | |||
| 2382 | " \"pools\": [ { \"pool\": \"foo/28\" } ]," | |||
| 2383 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 2384 | "\"valid-lifetime\": 4000 }"; | |||
| 2385 | ||||
| 2386 | // not a length | |||
| 2387 | string config_bogus2 = "{ " + genIfaceConfig() + "," | |||
| 2388 | "\"rebind-timer\": 2000, " | |||
| 2389 | "\"renew-timer\": 1000, " | |||
| 2390 | "\"subnet4\": [ { " | |||
| 2391 | " \"id\": 1," | |||
| 2392 | " \"pools\": [ { \"pool\": \"192.0.2.128/foo\" } ]," | |||
| 2393 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 2394 | "\"valid-lifetime\": 4000 }"; | |||
| 2395 | ||||
| 2396 | // invalid prefix length | |||
| 2397 | string config_bogus3 = "{ " + genIfaceConfig() + "," | |||
| 2398 | "\"rebind-timer\": 2000, " | |||
| 2399 | "\"renew-timer\": 1000, " | |||
| 2400 | "\"subnet4\": [ { " | |||
| 2401 | " \"id\": 1," | |||
| 2402 | " \"pools\": [ { \"pool\": \"192.0.2.128/100\" } ]," | |||
| 2403 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 2404 | "\"valid-lifetime\": 4000 }"; | |||
| 2405 | ||||
| 2406 | // not a prefix nor a min-max | |||
| 2407 | string config_bogus4 = "{ " + genIfaceConfig() + "," | |||
| 2408 | "\"rebind-timer\": 2000, " | |||
| 2409 | "\"renew-timer\": 1000, " | |||
| 2410 | "\"subnet4\": [ { " | |||
| 2411 | " \"id\": 1," | |||
| 2412 | " \"pools\": [ { \"pool\": \"foo\" } ]," | |||
| 2413 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 2414 | "\"valid-lifetime\": 4000 }"; | |||
| 2415 | ||||
| 2416 | // not an address | |||
| 2417 | string config_bogus5 = "{ " + genIfaceConfig() + "," | |||
| 2418 | "\"rebind-timer\": 2000, " | |||
| 2419 | "\"renew-timer\": 1000, " | |||
| 2420 | "\"subnet4\": [ { " | |||
| 2421 | " \"id\": 1," | |||
| 2422 | " \"pools\": [ { \"pool\": \"foo - bar\" } ]," | |||
| 2423 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 2424 | "\"valid-lifetime\": 4000 }"; | |||
| 2425 | ||||
| 2426 | // min > max | |||
| 2427 | string config_bogus6 = "{ " + genIfaceConfig() + "," | |||
| 2428 | "\"rebind-timer\": 2000, " | |||
| 2429 | "\"renew-timer\": 1000, " | |||
| 2430 | "\"subnet4\": [ { " | |||
| 2431 | " \"id\": 1," | |||
| 2432 | " \"pools\": [ { \"pool\": \"192.0.2.200 - 192.0.2.100\" } ]," | |||
| 2433 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 2434 | "\"valid-lifetime\": 4000 }"; | |||
| 2435 | ||||
| 2436 | // out of range prefix length (new check) | |||
| 2437 | string config_bogus7 = "{ " + genIfaceConfig() + "," | |||
| 2438 | "\"rebind-timer\": 2000, " | |||
| 2439 | "\"renew-timer\": 1000, " | |||
| 2440 | "\"subnet4\": [ { " | |||
| 2441 | " \"id\": 1," | |||
| 2442 | " \"pools\": [ { \"pool\": \"192.0.2.128/1052\" } ]," | |||
| 2443 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 2444 | "\"valid-lifetime\": 4000 }"; | |||
| 2445 | ||||
| 2446 | ConstElementPtr json1; | |||
| 2447 | ASSERT_NO_THROW(json1 = parseDHCP4(config_bogus1))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json1 = parseDHCP4(config_bogus1); } else static_assert(true , ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2447 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2447 ; } } else gtest_label_testnothrow_2447 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2447, ("Expected: " "json1 = parseDHCP4(config_bogus1)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2448 | ConstElementPtr json2; | |||
| 2449 | ASSERT_NO_THROW(json2 = parseDHCP4(config_bogus2))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json2 = parseDHCP4(config_bogus2); } else static_assert(true , ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2449 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2449 ; } } else gtest_label_testnothrow_2449 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2449, ("Expected: " "json2 = parseDHCP4(config_bogus2)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2450 | ConstElementPtr json3; | |||
| 2451 | ASSERT_NO_THROW(json3 = parseDHCP4(config_bogus3))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json3 = parseDHCP4(config_bogus3); } else static_assert(true , ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2451 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2451 ; } } else gtest_label_testnothrow_2451 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2451, ("Expected: " "json3 = parseDHCP4(config_bogus3)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2452 | ConstElementPtr json4; | |||
| 2453 | ASSERT_NO_THROW(json4 = parseDHCP4(config_bogus4))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json4 = parseDHCP4(config_bogus4); } else static_assert(true , ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2453 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2453 ; } } else gtest_label_testnothrow_2453 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2453, ("Expected: " "json4 = parseDHCP4(config_bogus4)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2454 | ConstElementPtr json5; | |||
| 2455 | ASSERT_NO_THROW(json5 = parseDHCP4(config_bogus5))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json5 = parseDHCP4(config_bogus5); } else static_assert(true , ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2455 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2455 ; } } else gtest_label_testnothrow_2455 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2455, ("Expected: " "json5 = parseDHCP4(config_bogus5)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2456 | ConstElementPtr json6; | |||
| 2457 | ASSERT_NO_THROW(json6 = parseDHCP4(config_bogus6))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json6 = parseDHCP4(config_bogus6); } else static_assert(true , ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2457 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2457 ; } } else gtest_label_testnothrow_2457 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2457, ("Expected: " "json6 = parseDHCP4(config_bogus6)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2458 | ConstElementPtr json7; | |||
| 2459 | ASSERT_NO_THROW(json7 = parseDHCP4(config_bogus7))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json7 = parseDHCP4(config_bogus7); } else static_assert(true , ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2459 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2459 ; } } else gtest_label_testnothrow_2459 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2459, ("Expected: " "json7 = parseDHCP4(config_bogus7)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2460 | ||||
| 2461 | ConstElementPtr status; | |||
| 2462 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json1))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json1); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2462; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2462; } } else gtest_label_testnothrow_2462 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2462, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json1)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2463 | ||||
| 2464 | // check if returned status is always a failure | |||
| 2465 | checkResult(status, 1); | |||
| 2466 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2466, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 2467 | ||||
| 2468 | CfgMgr::instance().clear(); | |||
| 2469 | ||||
| 2470 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json2))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json2); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_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/bin/dhcp4/tests/config_parser_unittest.cc" , 2470, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json2)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2471 | checkResult(status, 1); | |||
| 2472 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2472, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 2473 | ||||
| 2474 | CfgMgr::instance().clear(); | |||
| 2475 | ||||
| 2476 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json3))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json3); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2476; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2476; } } else gtest_label_testnothrow_2476 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2476, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json3)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2477 | checkResult(status, 1); | |||
| 2478 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2478, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 2479 | ||||
| 2480 | CfgMgr::instance().clear(); | |||
| 2481 | ||||
| 2482 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json4))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json4); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2482; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2482; } } else gtest_label_testnothrow_2482 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2482, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json4)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2483 | checkResult(status, 1); | |||
| 2484 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2484, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 2485 | ||||
| 2486 | CfgMgr::instance().clear(); | |||
| 2487 | ||||
| 2488 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json5))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json5); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2488; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2488; } } else gtest_label_testnothrow_2488 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2488, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json5)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2489 | checkResult(status, 1); | |||
| 2490 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2490, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 2491 | ||||
| 2492 | CfgMgr::instance().clear(); | |||
| 2493 | ||||
| 2494 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json6))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json6); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2494; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2494; } } else gtest_label_testnothrow_2494 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2494, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json6)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2495 | checkResult(status, 1); | |||
| 2496 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2496, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 2497 | ||||
| 2498 | CfgMgr::instance().clear(); | |||
| 2499 | ||||
| 2500 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json7))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json7); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2500; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2500; } } else gtest_label_testnothrow_2500 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2500, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json7)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2501 | checkResult(status, 1); | |||
| 2502 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2502, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 2503 | } | |||
| 2504 | ||||
| 2505 | // Goal of this test is to verify no pool definitions is invalid | |||
| 2506 | // and returns a location in the error message. | |||
| 2507 | TEST_F(Dhcp4ParserTest, noPools)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("noPools") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_noPools_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_noPools_Test() = default; ~Dhcp4ParserTest_noPools_Test () override = default; Dhcp4ParserTest_noPools_Test (const Dhcp4ParserTest_noPools_Test &) = delete; Dhcp4ParserTest_noPools_Test & operator =( const Dhcp4ParserTest_noPools_Test &) = delete; Dhcp4ParserTest_noPools_Test (Dhcp4ParserTest_noPools_Test &&) noexcept = delete; Dhcp4ParserTest_noPools_Test & operator=( Dhcp4ParserTest_noPools_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_noPools_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "noPools", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2507 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2507), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2507), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_noPools_Test >); void Dhcp4ParserTest_noPools_Test::TestBody() { | |||
| 2508 | ||||
| 2509 | // Configuration string. | |||
| 2510 | string config = "{ " + genIfaceConfig() + "," | |||
| 2511 | "\"rebind-timer\": 2000, " | |||
| 2512 | "\"renew-timer\": 1000, " | |||
| 2513 | "\"subnet4\": [ { " | |||
| 2514 | " \"id\": 1," | |||
| 2515 | " \"pools\": [ { \"user-context\": { } } ]," | |||
| 2516 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 2517 | "\"valid-lifetime\": 4000 }"; | |||
| 2518 | ||||
| 2519 | EXPECT_THROW(parseDHCP4(config, true), Dhcp4ParseError)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { parseDHCP4(config, true) ; } else static_assert(true, ""); } catch (Dhcp4ParseError const &) { gtest_caught_expected = true; } catch (typename std:: conditional< std::is_same<typename std::remove_cv<typename std::remove_reference< Dhcp4ParseError>::type>::type , std::exception>::value, const ::testing::internal::NeverThrown &, const std::exception&>::type e) { gtest_msg.value = "Expected: " "parseDHCP4(config, true)" " throws an exception of type " "Dhcp4ParseError" ".\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_2519; } catch (... ) { gtest_msg.value = "Expected: " "parseDHCP4(config, true)" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_2519; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "parseDHCP4(config, true)" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws nothing." ; goto gtest_label_testthrow_2519; } } else gtest_label_testthrow_2519 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2519, gtest_msg.value.c_str()) = ::testing::Message(); | |||
| 2520 | } | |||
| 2521 | ||||
| 2522 | ||||
| 2523 | // Goal of this test is to verify that unknown interface fails | |||
| 2524 | // to be parsed. | |||
| 2525 | TEST_F(Dhcp4ParserTest, unknownInterface)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("unknownInterface") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_unknownInterface_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_unknownInterface_Test() = default; ~Dhcp4ParserTest_unknownInterface_Test() override = default; Dhcp4ParserTest_unknownInterface_Test (const Dhcp4ParserTest_unknownInterface_Test &) = delete; Dhcp4ParserTest_unknownInterface_Test & operator=( const Dhcp4ParserTest_unknownInterface_Test & ) = delete; Dhcp4ParserTest_unknownInterface_Test (Dhcp4ParserTest_unknownInterface_Test &&) noexcept = delete; Dhcp4ParserTest_unknownInterface_Test & operator=( Dhcp4ParserTest_unknownInterface_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_unknownInterface_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "unknownInterface", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2525), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2525), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2525), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_unknownInterface_Test >); void Dhcp4ParserTest_unknownInterface_Test::TestBody() { | |||
| 2526 | ||||
| 2527 | // Configuration string. | |||
| 2528 | string config = "{ " + genIfaceConfig() + "," | |||
| 2529 | "\"rebind-timer\": 2000, " | |||
| 2530 | "\"renew-timer\": 1000, " | |||
| 2531 | "\"subnet4\": [ { " | |||
| 2532 | " \"id\": 1," | |||
| 2533 | " \"pools\": [ ]," | |||
| 2534 | " \"subnet\": \"192.0.2.0/24\"," | |||
| 2535 | " \"interface\": \"ethX\" } ]," | |||
| 2536 | "\"valid-lifetime\": 4000 }"; | |||
| 2537 | ||||
| 2538 | ConstElementPtr json; | |||
| 2539 | ASSERT_NO_THROW(json = parseDHCP4(config, true))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(config, 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_2539 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2539 ; } } else gtest_label_testnothrow_2539 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2539, ("Expected: " "json = parseDHCP4(config, true)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2540 | ConstElementPtr status; | |||
| 2541 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2541; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2541; } } else gtest_label_testnothrow_2541 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2541, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2542 | checkResult(status, 1); | |||
| 2543 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2543, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 2544 | } | |||
| 2545 | ||||
| 2546 | // The goal of this test is to check whether an option definition | |||
| 2547 | // that defines an option carrying an IPv4 address can be created. | |||
| 2548 | TEST_F(Dhcp4ParserTest, optionDefIpv4Address)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDefIpv4Address") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionDefIpv4Address_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDefIpv4Address_Test() = default ; ~Dhcp4ParserTest_optionDefIpv4Address_Test() override = default ; Dhcp4ParserTest_optionDefIpv4Address_Test (const Dhcp4ParserTest_optionDefIpv4Address_Test &) = delete; Dhcp4ParserTest_optionDefIpv4Address_Test & operator=( const Dhcp4ParserTest_optionDefIpv4Address_Test & ) = delete; Dhcp4ParserTest_optionDefIpv4Address_Test (Dhcp4ParserTest_optionDefIpv4Address_Test &&) noexcept = delete; Dhcp4ParserTest_optionDefIpv4Address_Test & operator=( Dhcp4ParserTest_optionDefIpv4Address_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionDefIpv4Address_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDefIpv4Address", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2548), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2548), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2548), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDefIpv4Address_Test >); void Dhcp4ParserTest_optionDefIpv4Address_Test::TestBody () { | |||
| 2549 | ||||
| 2550 | // Configuration string. | |||
| 2551 | std::string config = | |||
| 2552 | "{ \"option-def\": [ {" | |||
| 2553 | " \"name\": \"foo\"," | |||
| 2554 | " \"code\": 100," | |||
| 2555 | " \"type\": \"ipv4-address\"," | |||
| 2556 | " \"space\": \"isc\"" | |||
| 2557 | " } ]" | |||
| 2558 | "}"; | |||
| 2559 | ConstElementPtr json; | |||
| 2560 | ASSERT_NO_THROW(json = parseOPTION_DEFS(config, true))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseOPTION_DEFS(config, 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_2560; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2560; } } else gtest_label_testnothrow_2560 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2560, ("Expected: " "json = parseOPTION_DEFS(config, true)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2561 | extractConfig(config); | |||
| 2562 | ||||
| 2563 | // Make sure that the particular option definition does not exist. | |||
| 2564 | OptionDefinitionPtr def = CfgMgr::instance().getStagingCfg()-> | |||
| 2565 | getCfgOptionDef()->get("isc", 100); | |||
| 2566 | ASSERT_FALSE(def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(def))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2566, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def", "true", "false") .c_str()) = ::testing::Message(); | |||
| 2567 | ||||
| 2568 | // Use the configuration string to create new option definition. | |||
| 2569 | ConstElementPtr status; | |||
| 2570 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2570; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2570; } } else gtest_label_testnothrow_2570 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2570, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2571 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2571, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2572 | checkResult(status, 0); | |||
| 2573 | ||||
| 2574 | // We need to commit option definitions because later in this test we | |||
| 2575 | // will be checking if they get removed when "option-def" parameter | |||
| 2576 | // is removed from a configuration. | |||
| 2577 | LibDHCP::commitRuntimeOptionDefs(); | |||
| 2578 | ||||
| 2579 | // The option definition should now be available in the CfgMgr. | |||
| 2580 | def = CfgMgr::instance().getStagingCfg()->getCfgOptionDef()->get("isc", 100); | |||
| 2581 | ASSERT_TRUE(def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(def)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2581 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2582 | ||||
| 2583 | // Verify that the option definition data is valid. | |||
| 2584 | EXPECT_EQ("foo", def->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"foo\"" , "def->getName()", "foo", def->getName()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2584 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2585 | EXPECT_EQ(100, def->getCode())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("100", "def->getCode()" , 100, def->getCode()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2585, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2586 | EXPECT_FALSE(def->getArrayType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(def->getArrayType ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2586, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def->getArrayType()", "true", "false") .c_str()) = ::testing ::Message(); | |||
| 2587 | EXPECT_EQ(OPT_IPV4_ADDRESS_TYPE, def->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("OPT_IPV4_ADDRESS_TYPE" , "def->getType()", OPT_IPV4_ADDRESS_TYPE, def->getType ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2587, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2588 | EXPECT_TRUE(def->getEncapsulatedSpace().empty())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(def->getEncapsulatedSpace ().empty())) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2588, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def->getEncapsulatedSpace().empty()", "false", "true") . c_str()) = ::testing::Message(); | |||
| 2589 | ||||
| 2590 | // The copy of the option definition should be available in the libdhcp++. | |||
| 2591 | OptionDefinitionPtr def_libdhcp = LibDHCP::getRuntimeOptionDef("isc", 100); | |||
| 2592 | ASSERT_TRUE(def_libdhcp)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(def_libdhcp)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2592, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def_libdhcp", "false", "true") .c_str()) = ::testing::Message (); | |||
| 2593 | ||||
| 2594 | // Both definitions should be held in distinct pointers but they should | |||
| 2595 | // be equal. | |||
| 2596 | EXPECT_TRUE(def_libdhcp != def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(def_libdhcp != def)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2596, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def_libdhcp != def", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 2597 | EXPECT_TRUE(*def_libdhcp == *def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(*def_libdhcp == *def) ) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2597, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "*def_libdhcp == *def", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 2598 | ||||
| 2599 | // Let's apply empty configuration. This removes the option definitions | |||
| 2600 | // configuration and should result in removal of the option 100 from the | |||
| 2601 | // libdhcp++. Note DHCP4 or OPTION_DEFS parsers do not accept empty maps. | |||
| 2602 | json.reset(new MapElement()); | |||
| 2603 | ASSERT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2603; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2603; } } else gtest_label_testnothrow_2603 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2603, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2604 | checkResult(status, 0); | |||
| 2605 | ||||
| 2606 | EXPECT_FALSE(LibDHCP::getRuntimeOptionDef("isc", 100))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(LibDHCP::getRuntimeOptionDef ("isc", 100)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2606, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LibDHCP::getRuntimeOptionDef(\"isc\", 100)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 2607 | } | |||
| 2608 | ||||
| 2609 | // The goal of this test is to check whether an option definition | |||
| 2610 | // that defines an option carrying a record of data fields can | |||
| 2611 | // be created. | |||
| 2612 | TEST_F(Dhcp4ParserTest, optionDefRecord)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDefRecord") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionDefRecord_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDefRecord_Test() = default; ~ Dhcp4ParserTest_optionDefRecord_Test() override = default; Dhcp4ParserTest_optionDefRecord_Test (const Dhcp4ParserTest_optionDefRecord_Test &) = delete; Dhcp4ParserTest_optionDefRecord_Test & operator=( const Dhcp4ParserTest_optionDefRecord_Test &) = delete; Dhcp4ParserTest_optionDefRecord_Test (Dhcp4ParserTest_optionDefRecord_Test &&) noexcept = delete; Dhcp4ParserTest_optionDefRecord_Test & operator=( Dhcp4ParserTest_optionDefRecord_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionDefRecord_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDefRecord", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2612 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2612), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2612), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDefRecord_Test >); void Dhcp4ParserTest_optionDefRecord_Test::TestBody() { | |||
| 2613 | ||||
| 2614 | // Configuration string. | |||
| 2615 | std::string config = | |||
| 2616 | "{ \"option-def\": [ {" | |||
| 2617 | " \"name\": \"foo\"," | |||
| 2618 | " \"code\": 100," | |||
| 2619 | " \"type\": \"record\"," | |||
| 2620 | " \"record-types\": \"uint16, ipv4-address, ipv6-address, string\"," | |||
| 2621 | " \"space\": \"isc\"" | |||
| 2622 | " } ]" | |||
| 2623 | "}"; | |||
| 2624 | ConstElementPtr json; | |||
| 2625 | ASSERT_NO_THROW(json = parseOPTION_DEFS(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseOPTION_DEFS(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_2625 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2625 ; } } else gtest_label_testnothrow_2625 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2625, ("Expected: " "json = parseOPTION_DEFS(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2626 | extractConfig(config); | |||
| 2627 | ||||
| 2628 | // Make sure that the particular option definition does not exist. | |||
| 2629 | OptionDefinitionPtr def = CfgMgr::instance().getStagingCfg()-> | |||
| 2630 | getCfgOptionDef()->get("isc", 100); | |||
| 2631 | ASSERT_FALSE(def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(def))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2631, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def", "true", "false") .c_str()) = ::testing::Message(); | |||
| 2632 | ||||
| 2633 | // Use the configuration string to create new option definition. | |||
| 2634 | ConstElementPtr status; | |||
| 2635 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2635; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2635; } } else gtest_label_testnothrow_2635 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2635, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2636 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2636, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2637 | checkResult(status, 0); | |||
| 2638 | ||||
| 2639 | // The option definition should now be available in the CfgMgr. | |||
| 2640 | def = CfgMgr::instance().getStagingCfg()->getCfgOptionDef()->get("isc", 100); | |||
| 2641 | ASSERT_TRUE(def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(def)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2641 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2642 | ||||
| 2643 | // Check the option data. | |||
| 2644 | EXPECT_EQ("foo", def->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"foo\"" , "def->getName()", "foo", def->getName()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2644 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2645 | EXPECT_EQ(100, def->getCode())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("100", "def->getCode()" , 100, def->getCode()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2645, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2646 | EXPECT_EQ(OPT_RECORD_TYPE, def->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("OPT_RECORD_TYPE" , "def->getType()", OPT_RECORD_TYPE, def->getType()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2646, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2647 | EXPECT_FALSE(def->getArrayType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(def->getArrayType ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2647, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def->getArrayType()", "true", "false") .c_str()) = ::testing ::Message(); | |||
| 2648 | EXPECT_TRUE(def->getEncapsulatedSpace().empty())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(def->getEncapsulatedSpace ().empty())) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2648, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def->getEncapsulatedSpace().empty()", "false", "true") . c_str()) = ::testing::Message(); | |||
| 2649 | ||||
| 2650 | // The option comprises the record of data fields. Verify that all | |||
| 2651 | // fields are present and they are of the expected types. | |||
| 2652 | const OptionDefinition::RecordFieldsCollection& record_fields = | |||
| 2653 | def->getRecordFields(); | |||
| 2654 | ASSERT_EQ(4, record_fields.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("4", "record_fields.size()" , 4, record_fields.size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2654, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2655 | EXPECT_EQ(OPT_UINT16_TYPE, record_fields[0])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("OPT_UINT16_TYPE" , "record_fields[0]", OPT_UINT16_TYPE, record_fields[0]))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2655, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2656 | EXPECT_EQ(OPT_IPV4_ADDRESS_TYPE, record_fields[1])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("OPT_IPV4_ADDRESS_TYPE" , "record_fields[1]", OPT_IPV4_ADDRESS_TYPE, record_fields[1] ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2656, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2657 | EXPECT_EQ(OPT_IPV6_ADDRESS_TYPE, record_fields[2])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("OPT_IPV6_ADDRESS_TYPE" , "record_fields[2]", OPT_IPV6_ADDRESS_TYPE, record_fields[2] ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2657, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2658 | EXPECT_EQ(OPT_STRING_TYPE, record_fields[3])switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("OPT_STRING_TYPE" , "record_fields[3]", OPT_STRING_TYPE, record_fields[3]))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2658, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2659 | } | |||
| 2660 | ||||
| 2661 | // The goal of this test is to verify that multiple option definitions | |||
| 2662 | // can be created. | |||
| 2663 | TEST_F(Dhcp4ParserTest, optionDefMultiple)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDefMultiple") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionDefMultiple_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDefMultiple_Test() = default ; ~Dhcp4ParserTest_optionDefMultiple_Test() override = default ; Dhcp4ParserTest_optionDefMultiple_Test (const Dhcp4ParserTest_optionDefMultiple_Test &) = delete; Dhcp4ParserTest_optionDefMultiple_Test & operator=( const Dhcp4ParserTest_optionDefMultiple_Test & ) = delete; Dhcp4ParserTest_optionDefMultiple_Test (Dhcp4ParserTest_optionDefMultiple_Test &&) noexcept = delete; Dhcp4ParserTest_optionDefMultiple_Test & operator=( Dhcp4ParserTest_optionDefMultiple_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionDefMultiple_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDefMultiple", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2663), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2663), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2663), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDefMultiple_Test >); void Dhcp4ParserTest_optionDefMultiple_Test::TestBody( ) { | |||
| 2664 | // Configuration string. | |||
| 2665 | std::string config = | |||
| 2666 | "{ \"option-def\": [ {" | |||
| 2667 | " \"name\": \"foo\"," | |||
| 2668 | " \"code\": 100," | |||
| 2669 | " \"type\": \"uint32\"," | |||
| 2670 | " \"space\": \"isc\"" | |||
| 2671 | " }," | |||
| 2672 | " {" | |||
| 2673 | " \"name\": \"foo-2\"," | |||
| 2674 | " \"code\": 101," | |||
| 2675 | " \"type\": \"ipv4-address\"," | |||
| 2676 | " \"space\": \"isc\"" | |||
| 2677 | " } ]" | |||
| 2678 | "}"; | |||
| 2679 | ConstElementPtr json; | |||
| 2680 | ASSERT_NO_THROW(json = parseOPTION_DEFS(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseOPTION_DEFS(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_2680 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2680 ; } } else gtest_label_testnothrow_2680 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2680, ("Expected: " "json = parseOPTION_DEFS(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2681 | extractConfig(config); | |||
| 2682 | ||||
| 2683 | // Make sure that the option definitions do not exist yet. | |||
| 2684 | ASSERT_FALSE(CfgMgr::instance().getStagingCfg()->switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(CfgMgr::instance(). getStagingCfg()-> getCfgOptionDef()->get("isc", 100)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2685, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()-> getCfgOptionDef()->get(\"isc\", 100)" , "true", "false") .c_str()) = ::testing::Message() | |||
| 2685 | getCfgOptionDef()->get("isc", 100))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(CfgMgr::instance(). getStagingCfg()-> getCfgOptionDef()->get("isc", 100)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2685, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()-> getCfgOptionDef()->get(\"isc\", 100)" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 2686 | ASSERT_FALSE(CfgMgr::instance().getStagingCfg()->switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(CfgMgr::instance(). getStagingCfg()-> getCfgOptionDef()->get("isc", 101)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2687, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()-> getCfgOptionDef()->get(\"isc\", 101)" , "true", "false") .c_str()) = ::testing::Message() | |||
| 2687 | getCfgOptionDef()->get("isc", 101))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(CfgMgr::instance(). getStagingCfg()-> getCfgOptionDef()->get("isc", 101)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2687, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()-> getCfgOptionDef()->get(\"isc\", 101)" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 2688 | ||||
| 2689 | // Use the configuration string to create new option definitions. | |||
| 2690 | ConstElementPtr status; | |||
| 2691 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2691; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2691; } } else gtest_label_testnothrow_2691 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2691, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2692 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2692, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2693 | checkResult(status, 0); | |||
| 2694 | ||||
| 2695 | // Check the first definition we have created. | |||
| 2696 | OptionDefinitionPtr def1 = CfgMgr::instance().getStagingCfg()-> | |||
| 2697 | getCfgOptionDef()->get("isc", 100); | |||
| 2698 | ASSERT_TRUE(def1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(def1)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2698 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def1", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2699 | ||||
| 2700 | // Check the option data. | |||
| 2701 | EXPECT_EQ("foo", def1->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"foo\"" , "def1->getName()", "foo", def1->getName()))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2701 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2702 | EXPECT_EQ(100, def1->getCode())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("100", "def1->getCode()" , 100, def1->getCode()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2702, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2703 | EXPECT_EQ(OPT_UINT32_TYPE, def1->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("OPT_UINT32_TYPE" , "def1->getType()", OPT_UINT32_TYPE, def1->getType())) ) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2703, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2704 | EXPECT_FALSE(def1->getArrayType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(def1->getArrayType ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2704, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def1->getArrayType()", "true", "false") .c_str()) = ::testing ::Message(); | |||
| 2705 | EXPECT_TRUE(def1->getEncapsulatedSpace().empty())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(def1->getEncapsulatedSpace ().empty())) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2705, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def1->getEncapsulatedSpace().empty()", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2706 | ||||
| 2707 | // Check the second option definition we have created. | |||
| 2708 | OptionDefinitionPtr def2 = CfgMgr::instance().getStagingCfg()-> | |||
| 2709 | getCfgOptionDef()->get("isc", 101); | |||
| 2710 | ASSERT_TRUE(def2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(def2)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2710 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def2", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2711 | ||||
| 2712 | // Check the option data. | |||
| 2713 | EXPECT_EQ("foo-2", def2->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"foo-2\"" , "def2->getName()", "foo-2", def2->getName()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2713, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2714 | EXPECT_EQ(101, def2->getCode())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("101", "def2->getCode()" , 101, def2->getCode()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2714, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2715 | EXPECT_EQ(OPT_IPV4_ADDRESS_TYPE, def2->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("OPT_IPV4_ADDRESS_TYPE" , "def2->getType()", OPT_IPV4_ADDRESS_TYPE, def2->getType ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2715, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2716 | EXPECT_FALSE(def2->getArrayType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(def2->getArrayType ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2716, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def2->getArrayType()", "true", "false") .c_str()) = ::testing ::Message(); | |||
| 2717 | EXPECT_TRUE(def2->getEncapsulatedSpace().empty())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(def2->getEncapsulatedSpace ().empty())) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2717, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def2->getEncapsulatedSpace().empty()", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2718 | } | |||
| 2719 | ||||
| 2720 | // The goal of this test is to verify that the duplicated option | |||
| 2721 | // definition is not accepted. | |||
| 2722 | TEST_F(Dhcp4ParserTest, optionDefDuplicate)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDefDuplicate") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionDefDuplicate_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDefDuplicate_Test() = default ; ~Dhcp4ParserTest_optionDefDuplicate_Test() override = default ; Dhcp4ParserTest_optionDefDuplicate_Test (const Dhcp4ParserTest_optionDefDuplicate_Test &) = delete; Dhcp4ParserTest_optionDefDuplicate_Test & operator=( const Dhcp4ParserTest_optionDefDuplicate_Test & ) = delete; Dhcp4ParserTest_optionDefDuplicate_Test (Dhcp4ParserTest_optionDefDuplicate_Test &&) noexcept = delete; Dhcp4ParserTest_optionDefDuplicate_Test & operator=( Dhcp4ParserTest_optionDefDuplicate_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionDefDuplicate_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDefDuplicate", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2722), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2722), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2722), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDefDuplicate_Test >); void Dhcp4ParserTest_optionDefDuplicate_Test::TestBody () { | |||
| 2723 | // Preconfigure libdhcp++ with option definitions. The new configuration | |||
| 2724 | // should override it, but when the new configuration fails, it should | |||
| 2725 | // revert to this original configuration. | |||
| 2726 | OptionDefSpaceContainer defs; | |||
| 2727 | OptionDefinitionPtr def(new OptionDefinition("bar", 233, "isc", "string")); | |||
| 2728 | defs.addItem(def); | |||
| 2729 | LibDHCP::setRuntimeOptionDefs(defs); | |||
| 2730 | LibDHCP::commitRuntimeOptionDefs(); | |||
| 2731 | ||||
| 2732 | // Configuration string. Both option definitions have | |||
| 2733 | // the same code and belong to the same option space. | |||
| 2734 | // This configuration should not be accepted. | |||
| 2735 | std::string config = | |||
| 2736 | "{ \"option-def\": [ {" | |||
| 2737 | " \"name\": \"foo\"," | |||
| 2738 | " \"code\": 100," | |||
| 2739 | " \"type\": \"uint32\"," | |||
| 2740 | " \"space\": \"isc\"" | |||
| 2741 | " }," | |||
| 2742 | " {" | |||
| 2743 | " \"name\": \"foo-2\"," | |||
| 2744 | " \"code\": 100," | |||
| 2745 | " \"type\": \"ipv4-address\"," | |||
| 2746 | " \"space\": \"isc\"" | |||
| 2747 | " } ]" | |||
| 2748 | "}"; | |||
| 2749 | ConstElementPtr json; | |||
| 2750 | ASSERT_NO_THROW(json = parseOPTION_DEFS(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseOPTION_DEFS(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_2750 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2750 ; } } else gtest_label_testnothrow_2750 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2750, ("Expected: " "json = parseOPTION_DEFS(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2751 | ||||
| 2752 | // Make sure that the option definition does not exist yet. | |||
| 2753 | ASSERT_FALSE(CfgMgr::instance().getStagingCfg()->switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(CfgMgr::instance(). getStagingCfg()-> getCfgOptionDef()->get("isc", 100)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2754, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()-> getCfgOptionDef()->get(\"isc\", 100)" , "true", "false") .c_str()) = ::testing::Message() | |||
| 2754 | getCfgOptionDef()->get("isc", 100))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(CfgMgr::instance(). getStagingCfg()-> getCfgOptionDef()->get("isc", 100)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2754, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()-> getCfgOptionDef()->get(\"isc\", 100)" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 2755 | ||||
| 2756 | // Use the configuration string to create new option definitions. | |||
| 2757 | ConstElementPtr status; | |||
| 2758 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2758; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2758; } } else gtest_label_testnothrow_2758 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2758, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2759 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2759, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2760 | checkResult(status, 1); | |||
| 2761 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2761, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 2762 | ||||
| 2763 | // Specific check for incorrect report using default config pair | |||
| 2764 | // as option-def is parsed first. | |||
| 2765 | string expected = "failed to create or run parser for configuration "; | |||
| 2766 | expected += "element option-def: option definition with code '100' "; | |||
| 2767 | expected += "already exists in option space 'isc'"; | |||
| 2768 | EXPECT_EQ(1, countFile(expected))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "countFile(expected)" , 1, countFile(expected)))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2768, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2769 | ||||
| 2770 | // The new configuration should have inserted option 100, but | |||
| 2771 | // once configuration failed (on the duplicate option definition) | |||
| 2772 | // the original configuration in libdhcp++ should be reverted. | |||
| 2773 | EXPECT_FALSE(LibDHCP::getRuntimeOptionDef("isc", 100))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(LibDHCP::getRuntimeOptionDef ("isc", 100)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2773, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "LibDHCP::getRuntimeOptionDef(\"isc\", 100)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 2774 | def = LibDHCP::getRuntimeOptionDef("isc", 233); | |||
| 2775 | ASSERT_TRUE(def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(def)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2775 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2776 | EXPECT_EQ("bar", def->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"bar\"" , "def->getName()", "bar", def->getName()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2776 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2777 | EXPECT_EQ(233, def->getCode())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("233", "def->getCode()" , 233, def->getCode()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2777, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2778 | } | |||
| 2779 | ||||
| 2780 | // The goal of this test is to verify that the option definition | |||
| 2781 | // comprising an array of uint32 values can be created. | |||
| 2782 | TEST_F(Dhcp4ParserTest, optionDefArray)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDefArray") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionDefArray_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDefArray_Test() = default; ~ Dhcp4ParserTest_optionDefArray_Test() override = default; Dhcp4ParserTest_optionDefArray_Test (const Dhcp4ParserTest_optionDefArray_Test &) = delete; Dhcp4ParserTest_optionDefArray_Test & operator=( const Dhcp4ParserTest_optionDefArray_Test & ) = delete; Dhcp4ParserTest_optionDefArray_Test (Dhcp4ParserTest_optionDefArray_Test &&) noexcept = delete; Dhcp4ParserTest_optionDefArray_Test & operator=( Dhcp4ParserTest_optionDefArray_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionDefArray_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDefArray", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2782 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2782), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2782), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDefArray_Test >); void Dhcp4ParserTest_optionDefArray_Test::TestBody() { | |||
| 2783 | ||||
| 2784 | // Configuration string. Created option definition should | |||
| 2785 | // comprise an array of uint32 values. | |||
| 2786 | std::string config = | |||
| 2787 | "{ \"option-def\": [ {" | |||
| 2788 | " \"name\": \"foo\"," | |||
| 2789 | " \"code\": 100," | |||
| 2790 | " \"type\": \"uint32\"," | |||
| 2791 | " \"array\": true," | |||
| 2792 | " \"space\": \"isc\"" | |||
| 2793 | " } ]" | |||
| 2794 | "}"; | |||
| 2795 | ConstElementPtr json; | |||
| 2796 | ASSERT_NO_THROW(json = parseOPTION_DEFS(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseOPTION_DEFS(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_2796 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2796 ; } } else gtest_label_testnothrow_2796 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2796, ("Expected: " "json = parseOPTION_DEFS(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2797 | extractConfig(config); | |||
| 2798 | ||||
| 2799 | // Make sure that the particular option definition does not exist. | |||
| 2800 | OptionDefinitionPtr def = CfgMgr::instance().getStagingCfg()-> | |||
| 2801 | getCfgOptionDef()->get("isc", 100); | |||
| 2802 | ASSERT_FALSE(def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(def))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2802, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def", "true", "false") .c_str()) = ::testing::Message(); | |||
| 2803 | ||||
| 2804 | // Use the configuration string to create new option definition. | |||
| 2805 | ConstElementPtr status; | |||
| 2806 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2806; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2806; } } else gtest_label_testnothrow_2806 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2806, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2807 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2807, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2808 | checkResult(status, 0); | |||
| 2809 | ||||
| 2810 | // The option definition should now be available in the CfgMgr. | |||
| 2811 | def = CfgMgr::instance().getStagingCfg()-> | |||
| 2812 | getCfgOptionDef()->get("isc", 100); | |||
| 2813 | ASSERT_TRUE(def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(def)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2813 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2814 | ||||
| 2815 | // Check the option data. | |||
| 2816 | EXPECT_EQ("foo", def->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"foo\"" , "def->getName()", "foo", def->getName()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2816 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2817 | EXPECT_EQ(100, def->getCode())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("100", "def->getCode()" , 100, def->getCode()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2817, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2818 | EXPECT_EQ(OPT_UINT32_TYPE, def->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("OPT_UINT32_TYPE" , "def->getType()", OPT_UINT32_TYPE, def->getType()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2818, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2819 | EXPECT_TRUE(def->getArrayType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(def->getArrayType( ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2819, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def->getArrayType()", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 2820 | EXPECT_TRUE(def->getEncapsulatedSpace().empty())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(def->getEncapsulatedSpace ().empty())) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2820, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def->getEncapsulatedSpace().empty()", "false", "true") . c_str()) = ::testing::Message(); | |||
| 2821 | } | |||
| 2822 | ||||
| 2823 | // The purpose of this test to verify that encapsulated option | |||
| 2824 | // space name may be specified. | |||
| 2825 | TEST_F(Dhcp4ParserTest, optionDefEncapsulate)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDefEncapsulate") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionDefEncapsulate_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDefEncapsulate_Test() = default ; ~Dhcp4ParserTest_optionDefEncapsulate_Test() override = default ; Dhcp4ParserTest_optionDefEncapsulate_Test (const Dhcp4ParserTest_optionDefEncapsulate_Test &) = delete; Dhcp4ParserTest_optionDefEncapsulate_Test & operator=( const Dhcp4ParserTest_optionDefEncapsulate_Test & ) = delete; Dhcp4ParserTest_optionDefEncapsulate_Test (Dhcp4ParserTest_optionDefEncapsulate_Test &&) noexcept = delete; Dhcp4ParserTest_optionDefEncapsulate_Test & operator=( Dhcp4ParserTest_optionDefEncapsulate_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionDefEncapsulate_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDefEncapsulate", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2825), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2825), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2825), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDefEncapsulate_Test >); void Dhcp4ParserTest_optionDefEncapsulate_Test::TestBody () { | |||
| 2826 | ||||
| 2827 | // Configuration string. Included the encapsulated | |||
| 2828 | // option space name. | |||
| 2829 | std::string config = | |||
| 2830 | "{ \"option-def\": [ {" | |||
| 2831 | " \"name\": \"foo\"," | |||
| 2832 | " \"code\": 100," | |||
| 2833 | " \"type\": \"uint32\"," | |||
| 2834 | " \"space\": \"isc\"," | |||
| 2835 | " \"encapsulate\": \"sub-opts-space\"" | |||
| 2836 | " } ]" | |||
| 2837 | "}"; | |||
| 2838 | ConstElementPtr json; | |||
| 2839 | ASSERT_NO_THROW(json = parseOPTION_DEFS(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseOPTION_DEFS(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_2839 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2839 ; } } else gtest_label_testnothrow_2839 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2839, ("Expected: " "json = parseOPTION_DEFS(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2840 | extractConfig(config); | |||
| 2841 | ||||
| 2842 | // Make sure that the particular option definition does not exist. | |||
| 2843 | OptionDefinitionPtr def = CfgMgr::instance().getStagingCfg()-> | |||
| 2844 | getCfgOptionDef()->get("isc", 100); | |||
| 2845 | ASSERT_FALSE(def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(def))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2845, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def", "true", "false") .c_str()) = ::testing::Message(); | |||
| 2846 | ||||
| 2847 | // Use the configuration string to create new option definition. | |||
| 2848 | ConstElementPtr status; | |||
| 2849 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2849; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2849; } } else gtest_label_testnothrow_2849 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2849, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2850 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2850, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2851 | checkResult(status, 0); | |||
| 2852 | ||||
| 2853 | // The option definition should now be available in the CfgMgr. | |||
| 2854 | def = CfgMgr::instance().getStagingCfg()-> | |||
| 2855 | getCfgOptionDef()->get("isc", 100); | |||
| 2856 | ASSERT_TRUE(def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(def)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2856 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2857 | ||||
| 2858 | // Check the option data. | |||
| 2859 | EXPECT_EQ("foo", def->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"foo\"" , "def->getName()", "foo", def->getName()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 2859 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2860 | EXPECT_EQ(100, def->getCode())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("100", "def->getCode()" , 100, def->getCode()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2860, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2861 | EXPECT_EQ(OPT_UINT32_TYPE, def->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("OPT_UINT32_TYPE" , "def->getType()", OPT_UINT32_TYPE, def->getType()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2861, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2862 | EXPECT_FALSE(def->getArrayType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(def->getArrayType ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2862, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def->getArrayType()", "true", "false") .c_str()) = ::testing ::Message(); | |||
| 2863 | EXPECT_EQ("sub-opts-space", def->getEncapsulatedSpace())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"sub-opts-space\"" , "def->getEncapsulatedSpace()", "sub-opts-space", def-> getEncapsulatedSpace()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2863, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 2864 | } | |||
| 2865 | ||||
| 2866 | /// The purpose of this test is to verify that the option definition | |||
| 2867 | /// with invalid name is not accepted. | |||
| 2868 | TEST_F(Dhcp4ParserTest, optionDefInvalidName)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDefInvalidName") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionDefInvalidName_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDefInvalidName_Test() = default ; ~Dhcp4ParserTest_optionDefInvalidName_Test() override = default ; Dhcp4ParserTest_optionDefInvalidName_Test (const Dhcp4ParserTest_optionDefInvalidName_Test &) = delete; Dhcp4ParserTest_optionDefInvalidName_Test & operator=( const Dhcp4ParserTest_optionDefInvalidName_Test & ) = delete; Dhcp4ParserTest_optionDefInvalidName_Test (Dhcp4ParserTest_optionDefInvalidName_Test &&) noexcept = delete; Dhcp4ParserTest_optionDefInvalidName_Test & operator=( Dhcp4ParserTest_optionDefInvalidName_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionDefInvalidName_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDefInvalidName", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2868), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2868), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2868), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDefInvalidName_Test >); void Dhcp4ParserTest_optionDefInvalidName_Test::TestBody () { | |||
| 2869 | // Configuration string. The option name is invalid as it | |||
| 2870 | // contains the % character. | |||
| 2871 | std::string config = | |||
| 2872 | "{ \"option-def\": [ {" | |||
| 2873 | " \"name\": \"invalid%name\"," | |||
| 2874 | " \"code\": 100," | |||
| 2875 | " \"type\": \"string\"," | |||
| 2876 | " \"space\": \"isc\"" | |||
| 2877 | " } ]" | |||
| 2878 | "}"; | |||
| 2879 | ConstElementPtr json; | |||
| 2880 | ASSERT_NO_THROW(json = parseOPTION_DEFS(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseOPTION_DEFS(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_2880 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2880 ; } } else gtest_label_testnothrow_2880 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2880, ("Expected: " "json = parseOPTION_DEFS(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2881 | ||||
| 2882 | // Use the configuration string to create new option definition. | |||
| 2883 | ConstElementPtr status; | |||
| 2884 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2884; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2884; } } else gtest_label_testnothrow_2884 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2884, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2885 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2885, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2886 | // Expecting parsing error (error code 1). | |||
| 2887 | checkResult(status, 1); | |||
| 2888 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2888, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 2889 | } | |||
| 2890 | ||||
| 2891 | /// The purpose of this test is to verify that the option definition | |||
| 2892 | /// with invalid type is not accepted. | |||
| 2893 | TEST_F(Dhcp4ParserTest, optionDefInvalidType)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDefInvalidType") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionDefInvalidType_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDefInvalidType_Test() = default ; ~Dhcp4ParserTest_optionDefInvalidType_Test() override = default ; Dhcp4ParserTest_optionDefInvalidType_Test (const Dhcp4ParserTest_optionDefInvalidType_Test &) = delete; Dhcp4ParserTest_optionDefInvalidType_Test & operator=( const Dhcp4ParserTest_optionDefInvalidType_Test & ) = delete; Dhcp4ParserTest_optionDefInvalidType_Test (Dhcp4ParserTest_optionDefInvalidType_Test &&) noexcept = delete; Dhcp4ParserTest_optionDefInvalidType_Test & operator=( Dhcp4ParserTest_optionDefInvalidType_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionDefInvalidType_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDefInvalidType", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2893), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2893), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2893), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDefInvalidType_Test >); void Dhcp4ParserTest_optionDefInvalidType_Test::TestBody () { | |||
| 2894 | // Configuration string. The option type is invalid. It is | |||
| 2895 | // "sting" instead of "string". | |||
| 2896 | std::string config = | |||
| 2897 | "{ \"option-def\": [ {" | |||
| 2898 | " \"name\": \"foo\"," | |||
| 2899 | " \"code\": 100," | |||
| 2900 | " \"type\": \"sting\"," | |||
| 2901 | " \"space\": \"isc\"" | |||
| 2902 | " } ]" | |||
| 2903 | "}"; | |||
| 2904 | ConstElementPtr json; | |||
| 2905 | ASSERT_NO_THROW(json = parseOPTION_DEFS(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseOPTION_DEFS(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_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/bin/dhcp4/tests/config_parser_unittest.cc" , 2905, ("Expected: " "json = parseOPTION_DEFS(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2906 | ||||
| 2907 | // Use the configuration string to create new option definition. | |||
| 2908 | ConstElementPtr status; | |||
| 2909 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2909; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2909; } } else gtest_label_testnothrow_2909 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2909, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2910 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2910, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2911 | // Expecting parsing error (error code 1). | |||
| 2912 | checkResult(status, 1); | |||
| 2913 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2913, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 2914 | } | |||
| 2915 | ||||
| 2916 | /// The purpose of this test is to verify that the option definition | |||
| 2917 | /// with invalid type is not accepted. | |||
| 2918 | TEST_F(Dhcp4ParserTest, optionDefInvalidRecordType)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDefInvalidRecordType") > 1, "test_name must not be empty"); class Dhcp4ParserTest_optionDefInvalidRecordType_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDefInvalidRecordType_Test () = default; ~Dhcp4ParserTest_optionDefInvalidRecordType_Test () override = default; Dhcp4ParserTest_optionDefInvalidRecordType_Test (const Dhcp4ParserTest_optionDefInvalidRecordType_Test & ) = delete; Dhcp4ParserTest_optionDefInvalidRecordType_Test & operator=( const Dhcp4ParserTest_optionDefInvalidRecordType_Test &) = delete; Dhcp4ParserTest_optionDefInvalidRecordType_Test (Dhcp4ParserTest_optionDefInvalidRecordType_Test &&) noexcept = delete; Dhcp4ParserTest_optionDefInvalidRecordType_Test & operator=( Dhcp4ParserTest_optionDefInvalidRecordType_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_optionDefInvalidRecordType_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDefInvalidRecordType", nullptr, nullptr, ::testing:: internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2918), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2918), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2918), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDefInvalidRecordType_Test >); void Dhcp4ParserTest_optionDefInvalidRecordType_Test:: TestBody() { | |||
| 2919 | // Configuration string. The third of the record fields | |||
| 2920 | // is invalid. It is "sting" instead of "string". | |||
| 2921 | std::string config = | |||
| 2922 | "{ \"option-def\": [ {" | |||
| 2923 | " \"name\": \"foo\"," | |||
| 2924 | " \"code\": 100," | |||
| 2925 | " \"type\": \"record\"," | |||
| 2926 | " \"record-types\": \"uint32,uint8,sting\"," | |||
| 2927 | " \"space\": \"isc\"" | |||
| 2928 | " } ]" | |||
| 2929 | "}"; | |||
| 2930 | ConstElementPtr json; | |||
| 2931 | ASSERT_NO_THROW(json = parseOPTION_DEFS(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseOPTION_DEFS(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_2931 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2931 ; } } else gtest_label_testnothrow_2931 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2931, ("Expected: " "json = parseOPTION_DEFS(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2932 | ||||
| 2933 | // Use the configuration string to create new option definition. | |||
| 2934 | ConstElementPtr status; | |||
| 2935 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2935; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2935; } } else gtest_label_testnothrow_2935 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2935, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2936 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2936, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2937 | // Expecting parsing error (error code 1). | |||
| 2938 | checkResult(status, 1); | |||
| 2939 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2939, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 2940 | } | |||
| 2941 | ||||
| 2942 | /// The purpose of this test is to verify that various integer types | |||
| 2943 | /// are supported. | |||
| 2944 | TEST_F(Dhcp4ParserTest, optionIntegerTypes)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionIntegerTypes") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionIntegerTypes_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionIntegerTypes_Test() = default ; ~Dhcp4ParserTest_optionIntegerTypes_Test() override = default ; Dhcp4ParserTest_optionIntegerTypes_Test (const Dhcp4ParserTest_optionIntegerTypes_Test &) = delete; Dhcp4ParserTest_optionIntegerTypes_Test & operator=( const Dhcp4ParserTest_optionIntegerTypes_Test & ) = delete; Dhcp4ParserTest_optionIntegerTypes_Test (Dhcp4ParserTest_optionIntegerTypes_Test &&) noexcept = delete; Dhcp4ParserTest_optionIntegerTypes_Test & operator=( Dhcp4ParserTest_optionIntegerTypes_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionIntegerTypes_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionIntegerTypes", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2944), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2944), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2944), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionIntegerTypes_Test >); void Dhcp4ParserTest_optionIntegerTypes_Test::TestBody () { | |||
| 2945 | // Configuration string. The third of the record fields | |||
| 2946 | // is invalid. It is "sting" instead of "string". | |||
| 2947 | std::string config = | |||
| 2948 | "{ \"option-def\": [ {" | |||
| 2949 | " \"name\": \"foo\"," | |||
| 2950 | " \"code\": 100," | |||
| 2951 | " \"type\": \"record\"," | |||
| 2952 | " \"record-types\": \"uint8,uint16,uint32,int8,int16,int32\"," | |||
| 2953 | " \"space\": \"isc\"" | |||
| 2954 | " } ]" | |||
| 2955 | "}"; | |||
| 2956 | ConstElementPtr json; | |||
| 2957 | ASSERT_NO_THROW(json = parseOPTION_DEFS(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseOPTION_DEFS(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_2957 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2957 ; } } else gtest_label_testnothrow_2957 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2957, ("Expected: " "json = parseOPTION_DEFS(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2958 | ||||
| 2959 | // Use the configuration string to create new option definition. | |||
| 2960 | ConstElementPtr status; | |||
| 2961 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2961; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2961; } } else gtest_label_testnothrow_2961 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2961, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2962 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2962, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2963 | // Expecting parsing error (error code 1). | |||
| 2964 | checkResult(status, 0); | |||
| 2965 | } | |||
| 2966 | ||||
| 2967 | /// The goal of this test is to verify that the invalid encapsulated | |||
| 2968 | /// option space name is not accepted. | |||
| 2969 | TEST_F(Dhcp4ParserTest, optionDefInvalidEncapsulatedSpace)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDefInvalidEncapsulatedSpace") > 1, "test_name must not be empty"); class Dhcp4ParserTest_optionDefInvalidEncapsulatedSpace_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDefInvalidEncapsulatedSpace_Test () = default; ~Dhcp4ParserTest_optionDefInvalidEncapsulatedSpace_Test () override = default; Dhcp4ParserTest_optionDefInvalidEncapsulatedSpace_Test (const Dhcp4ParserTest_optionDefInvalidEncapsulatedSpace_Test &) = delete; Dhcp4ParserTest_optionDefInvalidEncapsulatedSpace_Test & operator=( const Dhcp4ParserTest_optionDefInvalidEncapsulatedSpace_Test &) = delete; Dhcp4ParserTest_optionDefInvalidEncapsulatedSpace_Test (Dhcp4ParserTest_optionDefInvalidEncapsulatedSpace_Test && ) noexcept = delete; Dhcp4ParserTest_optionDefInvalidEncapsulatedSpace_Test & operator=( Dhcp4ParserTest_optionDefInvalidEncapsulatedSpace_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_optionDefInvalidEncapsulatedSpace_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDefInvalidEncapsulatedSpace", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2969), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2969), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2969), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDefInvalidEncapsulatedSpace_Test >); void Dhcp4ParserTest_optionDefInvalidEncapsulatedSpace_Test ::TestBody() { | |||
| 2970 | // Configuration string. The encapsulated option space | |||
| 2971 | // name is invalid (% character is not allowed). | |||
| 2972 | std::string config = | |||
| 2973 | "{ \"option-def\": [ {" | |||
| 2974 | " \"name\": \"foo\"," | |||
| 2975 | " \"code\": 100," | |||
| 2976 | " \"type\": \"uint32\"," | |||
| 2977 | " \"space\": \"isc\"," | |||
| 2978 | " \"encapsulate\": \"invalid%space%name\"" | |||
| 2979 | " } ]" | |||
| 2980 | "}"; | |||
| 2981 | ConstElementPtr json; | |||
| 2982 | ASSERT_NO_THROW(json = parseOPTION_DEFS(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseOPTION_DEFS(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_2982 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2982 ; } } else gtest_label_testnothrow_2982 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2982, ("Expected: " "json = parseOPTION_DEFS(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 2983 | ||||
| 2984 | // Use the configuration string to create new option definition. | |||
| 2985 | ConstElementPtr status; | |||
| 2986 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_2986; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_2986; } } else gtest_label_testnothrow_2986 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2986, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 2987 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2987, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 2988 | // Expecting parsing error (error code 1). | |||
| 2989 | checkResult(status, 1); | |||
| 2990 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2990, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 2991 | } | |||
| 2992 | ||||
| 2993 | /// The goal of this test is to verify that the encapsulated | |||
| 2994 | /// option space name can't be specified for the option that | |||
| 2995 | /// comprises an array of data fields. | |||
| 2996 | TEST_F(Dhcp4ParserTest, optionDefEncapsulatedSpaceAndArray)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDefEncapsulatedSpaceAndArray") > 1, "test_name must not be empty"); class Dhcp4ParserTest_optionDefEncapsulatedSpaceAndArray_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDefEncapsulatedSpaceAndArray_Test () = default; ~Dhcp4ParserTest_optionDefEncapsulatedSpaceAndArray_Test () override = default; Dhcp4ParserTest_optionDefEncapsulatedSpaceAndArray_Test (const Dhcp4ParserTest_optionDefEncapsulatedSpaceAndArray_Test &) = delete; Dhcp4ParserTest_optionDefEncapsulatedSpaceAndArray_Test & operator=( const Dhcp4ParserTest_optionDefEncapsulatedSpaceAndArray_Test &) = delete; Dhcp4ParserTest_optionDefEncapsulatedSpaceAndArray_Test (Dhcp4ParserTest_optionDefEncapsulatedSpaceAndArray_Test && ) noexcept = delete; Dhcp4ParserTest_optionDefEncapsulatedSpaceAndArray_Test & operator=( Dhcp4ParserTest_optionDefEncapsulatedSpaceAndArray_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_optionDefEncapsulatedSpaceAndArray_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDefEncapsulatedSpaceAndArray", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2996), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2996), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 2996), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDefEncapsulatedSpaceAndArray_Test >); void Dhcp4ParserTest_optionDefEncapsulatedSpaceAndArray_Test ::TestBody() { | |||
| 2997 | // Configuration string. The encapsulated option space | |||
| 2998 | // name is set to non-empty value and the array flag | |||
| 2999 | // is set. | |||
| 3000 | std::string config = | |||
| 3001 | "{ \"option-def\": [ {" | |||
| 3002 | " \"name\": \"foo\"," | |||
| 3003 | " \"code\": 100," | |||
| 3004 | " \"type\": \"uint32\"," | |||
| 3005 | " \"array\": true," | |||
| 3006 | " \"space\": \"isc\"," | |||
| 3007 | " \"encapsulate\": \"valid-space-name\"" | |||
| 3008 | " } ]" | |||
| 3009 | "}"; | |||
| 3010 | ConstElementPtr json; | |||
| 3011 | ASSERT_NO_THROW(json = parseOPTION_DEFS(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseOPTION_DEFS(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_3011 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3011 ; } } else gtest_label_testnothrow_3011 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3011, ("Expected: " "json = parseOPTION_DEFS(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 3012 | ||||
| 3013 | // Use the configuration string to create new option definition. | |||
| 3014 | ConstElementPtr status; | |||
| 3015 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3015; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3015; } } else gtest_label_testnothrow_3015 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3015, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 3016 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3016, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3017 | // Expecting parsing error (error code 1). | |||
| 3018 | checkResult(status, 1); | |||
| 3019 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3019, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 3020 | } | |||
| 3021 | ||||
| 3022 | /// The goal of this test is to verify that the option may not | |||
| 3023 | /// encapsulate option space it belongs to. | |||
| 3024 | TEST_F(Dhcp4ParserTest, optionDefEncapsulateOwnSpace)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDefEncapsulateOwnSpace") > 1 , "test_name must not be empty"); class Dhcp4ParserTest_optionDefEncapsulateOwnSpace_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDefEncapsulateOwnSpace_Test () = default; ~Dhcp4ParserTest_optionDefEncapsulateOwnSpace_Test () override = default; Dhcp4ParserTest_optionDefEncapsulateOwnSpace_Test (const Dhcp4ParserTest_optionDefEncapsulateOwnSpace_Test & ) = delete; Dhcp4ParserTest_optionDefEncapsulateOwnSpace_Test & operator=( const Dhcp4ParserTest_optionDefEncapsulateOwnSpace_Test &) = delete; Dhcp4ParserTest_optionDefEncapsulateOwnSpace_Test (Dhcp4ParserTest_optionDefEncapsulateOwnSpace_Test && ) noexcept = delete; Dhcp4ParserTest_optionDefEncapsulateOwnSpace_Test & operator=( Dhcp4ParserTest_optionDefEncapsulateOwnSpace_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_optionDefEncapsulateOwnSpace_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDefEncapsulateOwnSpace", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3024), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3024), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3024), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDefEncapsulateOwnSpace_Test >); void Dhcp4ParserTest_optionDefEncapsulateOwnSpace_Test ::TestBody() { | |||
| 3025 | // Configuration string. Option is set to encapsulate | |||
| 3026 | // option space it belongs to. | |||
| 3027 | std::string config = | |||
| 3028 | "{ \"option-def\": [ {" | |||
| 3029 | " \"name\": \"foo\"," | |||
| 3030 | " \"code\": 100," | |||
| 3031 | " \"type\": \"uint32\"," | |||
| 3032 | " \"space\": \"isc\"," | |||
| 3033 | " \"encapsulate\": \"isc\"" | |||
| 3034 | " } ]" | |||
| 3035 | "}"; | |||
| 3036 | ConstElementPtr json; | |||
| 3037 | ASSERT_NO_THROW(json = parseOPTION_DEFS(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseOPTION_DEFS(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_3037 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3037 ; } } else gtest_label_testnothrow_3037 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3037, ("Expected: " "json = parseOPTION_DEFS(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 3038 | ||||
| 3039 | // Use the configuration string to create new option definition. | |||
| 3040 | ConstElementPtr status; | |||
| 3041 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3041; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3041; } } else gtest_label_testnothrow_3041 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3041, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 3042 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3042, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3043 | // Expecting parsing error (error code 1). | |||
| 3044 | checkResult(status, 1); | |||
| 3045 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3045, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 3046 | } | |||
| 3047 | ||||
| 3048 | /// The purpose of this test is to verify that it is not allowed | |||
| 3049 | /// to override the standard option (that belongs to dhcp4 option | |||
| 3050 | /// space and has its definition) and that it is allowed to define | |||
| 3051 | /// option in the dhcp4 option space that has a code which is not | |||
| 3052 | /// used by any of the standard options. | |||
| 3053 | TEST_F(Dhcp4ParserTest, optionStandardDefOverride)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionStandardDefOverride") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionStandardDefOverride_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionStandardDefOverride_Test () = default; ~Dhcp4ParserTest_optionStandardDefOverride_Test () override = default; Dhcp4ParserTest_optionStandardDefOverride_Test (const Dhcp4ParserTest_optionStandardDefOverride_Test &) = delete; Dhcp4ParserTest_optionStandardDefOverride_Test & operator=( const Dhcp4ParserTest_optionStandardDefOverride_Test &) = delete; Dhcp4ParserTest_optionStandardDefOverride_Test (Dhcp4ParserTest_optionStandardDefOverride_Test &&) noexcept = delete; Dhcp4ParserTest_optionStandardDefOverride_Test & operator=( Dhcp4ParserTest_optionStandardDefOverride_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionStandardDefOverride_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionStandardDefOverride", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3053), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3053), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3053), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionStandardDefOverride_Test >); void Dhcp4ParserTest_optionStandardDefOverride_Test::TestBody () { | |||
| 3054 | ||||
| 3055 | // Configuration string. The option code 109 is unassigned | |||
| 3056 | // so it can be used for a custom option definition in | |||
| 3057 | // dhcp4 option space. | |||
| 3058 | std::string config = | |||
| 3059 | "{ \"option-def\": [ {" | |||
| 3060 | " \"name\": \"foo\"," | |||
| 3061 | " \"code\": 109," | |||
| 3062 | " \"type\": \"string\"," | |||
| 3063 | " \"space\": \"dhcp4\"" | |||
| 3064 | " } ]" | |||
| 3065 | "}"; | |||
| 3066 | ConstElementPtr json; | |||
| 3067 | ASSERT_NO_THROW(json = parseOPTION_DEFS(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseOPTION_DEFS(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_3067 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3067 ; } } else gtest_label_testnothrow_3067 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3067, ("Expected: " "json = parseOPTION_DEFS(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 3068 | extractConfig(config); | |||
| 3069 | ||||
| 3070 | OptionDefinitionPtr def = CfgMgr::instance().getStagingCfg()-> | |||
| 3071 | getCfgOptionDef()->get(DHCP4_OPTION_SPACE"dhcp4", 109); | |||
| 3072 | ASSERT_FALSE(def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(def))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3072, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def", "true", "false") .c_str()) = ::testing::Message(); | |||
| 3073 | ||||
| 3074 | // Use the configuration string to create new option definition. | |||
| 3075 | ConstElementPtr status; | |||
| 3076 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3076; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3076; } } else gtest_label_testnothrow_3076 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3076, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 3077 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3077, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3078 | checkResult(status, 0); | |||
| 3079 | ||||
| 3080 | // The option definition should now be available in the CfgMgr. | |||
| 3081 | def = CfgMgr::instance().getStagingCfg()-> | |||
| 3082 | getCfgOptionDef()->get(DHCP4_OPTION_SPACE"dhcp4", 109); | |||
| 3083 | ASSERT_TRUE(def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(def)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 3083 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3084 | ||||
| 3085 | // Check the option data. | |||
| 3086 | EXPECT_EQ("foo", def->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"foo\"" , "def->getName()", "foo", def->getName()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 3086 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3087 | EXPECT_EQ(109, def->getCode())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("109", "def->getCode()" , 109, def->getCode()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3087, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3088 | EXPECT_EQ(OPT_STRING_TYPE, def->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("OPT_STRING_TYPE" , "def->getType()", OPT_STRING_TYPE, def->getType()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3088, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3089 | EXPECT_FALSE(def->getArrayType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(def->getArrayType ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3089, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def->getArrayType()", "true", "false") .c_str()) = ::testing ::Message(); | |||
| 3090 | ||||
| 3091 | // The combination of option space and code is invalid. The 'dhcp4' | |||
| 3092 | // option space groups standard options and the code 3 is reserved | |||
| 3093 | // for one of them. | |||
| 3094 | config = | |||
| 3095 | "{ \"option-def\": [ {" | |||
| 3096 | " \"name\": \"routers\"," | |||
| 3097 | " \"code\": 3," | |||
| 3098 | " \"type\": \"ipv4-address\"," | |||
| 3099 | " \"space\": \"dhcp4\"" | |||
| 3100 | " } ]" | |||
| 3101 | "}"; | |||
| 3102 | ASSERT_NO_THROW(json = parseOPTION_DEFS(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseOPTION_DEFS(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_3102 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3102 ; } } else gtest_label_testnothrow_3102 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3102, ("Expected: " "json = parseOPTION_DEFS(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 3103 | ||||
| 3104 | // Use the configuration string to create new option definition. | |||
| 3105 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3105; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3105; } } else gtest_label_testnothrow_3105 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3105, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 3106 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3106, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3107 | // Expecting parsing error (error code 1). | |||
| 3108 | checkResult(status, 1); | |||
| 3109 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3109, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 3110 | ||||
| 3111 | /// There is no definition for unassigned option 170. | |||
| 3112 | config = | |||
| 3113 | "{ \"option-def\": [ {" | |||
| 3114 | " \"name\": \"unassigned-option-170\"," | |||
| 3115 | " \"code\": 170," | |||
| 3116 | " \"type\": \"string\"," | |||
| 3117 | " \"space\": \"dhcp4\"" | |||
| 3118 | " } ]" | |||
| 3119 | "}"; | |||
| 3120 | ASSERT_NO_THROW(json = parseOPTION_DEFS(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseOPTION_DEFS(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_3120 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3120 ; } } else gtest_label_testnothrow_3120 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3120, ("Expected: " "json = parseOPTION_DEFS(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 3121 | extractConfig(config); | |||
| 3122 | ||||
| 3123 | // Use the configuration string to create new option definition. | |||
| 3124 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3124; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3124; } } else gtest_label_testnothrow_3124 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3124, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 3125 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3125, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3126 | // Expecting success. | |||
| 3127 | checkResult(status, 0); | |||
| 3128 | ||||
| 3129 | def = CfgMgr::instance().getStagingCfg()-> | |||
| 3130 | getCfgOptionDef()->get(DHCP4_OPTION_SPACE"dhcp4", 170); | |||
| 3131 | ASSERT_TRUE(def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(def)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 3131 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3132 | ||||
| 3133 | // Check the option data. | |||
| 3134 | EXPECT_EQ("unassigned-option-170", def->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"unassigned-option-170\"" , "def->getName()", "unassigned-option-170", def->getName ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3134, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3135 | EXPECT_EQ(170, def->getCode())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("170", "def->getCode()" , 170, def->getCode()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3135, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3136 | EXPECT_EQ(OPT_STRING_TYPE, def->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("OPT_STRING_TYPE" , "def->getType()", OPT_STRING_TYPE, def->getType()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3136, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3137 | EXPECT_FALSE(def->getArrayType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(def->getArrayType ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3137, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "def->getArrayType()", "true", "false") .c_str()) = ::testing ::Message(); | |||
| 3138 | } | |||
| 3139 | ||||
| 3140 | // Goal of this test is to verify that global option data is configured | |||
| 3141 | TEST_F(Dhcp4ParserTest, optionDataDefaultsGlobal)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDataDefaultsGlobal") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionDataDefaultsGlobal_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDataDefaultsGlobal_Test () = default; ~Dhcp4ParserTest_optionDataDefaultsGlobal_Test( ) override = default; Dhcp4ParserTest_optionDataDefaultsGlobal_Test (const Dhcp4ParserTest_optionDataDefaultsGlobal_Test &) = delete; Dhcp4ParserTest_optionDataDefaultsGlobal_Test & operator =( const Dhcp4ParserTest_optionDataDefaultsGlobal_Test &) = delete; Dhcp4ParserTest_optionDataDefaultsGlobal_Test (Dhcp4ParserTest_optionDataDefaultsGlobal_Test &&) noexcept = delete; Dhcp4ParserTest_optionDataDefaultsGlobal_Test & operator=( Dhcp4ParserTest_optionDataDefaultsGlobal_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_optionDataDefaultsGlobal_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDataDefaultsGlobal", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3141), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3141), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3141), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDataDefaultsGlobal_Test >); void Dhcp4ParserTest_optionDataDefaultsGlobal_Test::TestBody () { | |||
| 3142 | ConstElementPtr x; | |||
| 3143 | string config = "{ " + genIfaceConfig() + "," | |||
| 3144 | "\"rebind-timer\": 2000," | |||
| 3145 | "\"renew-timer\": 1000," | |||
| 3146 | "\"option-data\": [ {" | |||
| 3147 | " \"name\": \"dhcp-message\"," | |||
| 3148 | " \"data\": \"ABCDEF0105\"," | |||
| 3149 | " \"csv-format\": false" | |||
| 3150 | " }," | |||
| 3151 | " {" | |||
| 3152 | " \"name\": \"default-ip-ttl\"," | |||
| 3153 | " \"data\": \"01\"," | |||
| 3154 | " \"csv-format\": false" | |||
| 3155 | " } ]," | |||
| 3156 | "\"subnet4\": [ { " | |||
| 3157 | " \"id\": 1," | |||
| 3158 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 3159 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 3160 | " } ]," | |||
| 3161 | "\"valid-lifetime\": 4000 }"; | |||
| 3162 | ||||
| 3163 | ConstElementPtr json; | |||
| 3164 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_3164 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3164 ; } } else gtest_label_testnothrow_3164 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3164, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 3165 | extractConfig(config); | |||
| 3166 | ||||
| 3167 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3167; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3167; } } else gtest_label_testnothrow_3167 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3167, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 3168 | checkResult(x, 0); | |||
| 3169 | ||||
| 3170 | // These options are global | |||
| 3171 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 3172 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200")); | |||
| 3173 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3173, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3174 | OptionContainerPtr options = subnet->getCfgOption()->getAll(DHCP4_OPTION_SPACE"dhcp4"); | |||
| 3175 | ASSERT_EQ(0, options->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "options->size()" , 0, options->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3175, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3176 | ||||
| 3177 | options = CfgMgr::instance().getStagingCfg()->getCfgOption()->getAll(DHCP4_OPTION_SPACE"dhcp4"); | |||
| 3178 | ASSERT_EQ(2, options->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "options->size()" , 2, options->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3178, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3179 | ||||
| 3180 | // Get the search index. Index #1 is to search using option code. | |||
| 3181 | const OptionContainerTypeIndex& idx = options->get<1>(); | |||
| 3182 | ||||
| 3183 | // Get the options for specified index. Expecting one option to be | |||
| 3184 | // returned but in theory we may have multiple options with the same | |||
| 3185 | // code so we get the range. | |||
| 3186 | std::pair<OptionContainerTypeIndex::const_iterator, | |||
| 3187 | OptionContainerTypeIndex::const_iterator> range = | |||
| 3188 | idx.equal_range(56); | |||
| 3189 | // Expect single option with the code equal to 56. | |||
| 3190 | ASSERT_EQ(1, std::distance(range.first, range.second))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "std::distance(range.first, range.second)" , 1, std::distance(range.first, range.second)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3190, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3191 | const uint8_t foo_expected[] = { | |||
| 3192 | 0xAB, 0xCD, 0xEF, 0x01, 0x05 | |||
| 3193 | }; | |||
| 3194 | // Check if option is valid in terms of code and carried data. | |||
| 3195 | testOption(*range.first, 56, foo_expected, sizeof(foo_expected)); | |||
| 3196 | ||||
| 3197 | range = idx.equal_range(23); | |||
| 3198 | ASSERT_EQ(1, std::distance(range.first, range.second))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "std::distance(range.first, range.second)" , 1, std::distance(range.first, range.second)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3198, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3199 | // Do another round of testing with second option. | |||
| 3200 | const uint8_t foo2_expected[] = { | |||
| 3201 | 0x01 | |||
| 3202 | }; | |||
| 3203 | testOption(*range.first, 23, foo2_expected, sizeof(foo2_expected)); | |||
| 3204 | ||||
| 3205 | // Check that options with other option codes are not returned. | |||
| 3206 | for (uint8_t code = 24; code < 35; ++code) { | |||
| 3207 | range = idx.equal_range(code); | |||
| 3208 | EXPECT_EQ(0, std::distance(range.first, range.second))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "std::distance(range.first, range.second)" , 0, std::distance(range.first, range.second)))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 3208 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3209 | } | |||
| 3210 | } | |||
| 3211 | ||||
| 3212 | // Goal of this test is to verify that subnet option data is configured | |||
| 3213 | TEST_F(Dhcp4ParserTest, optionDataDefaultsSubnet)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDataDefaultsSubnet") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionDataDefaultsSubnet_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDataDefaultsSubnet_Test () = default; ~Dhcp4ParserTest_optionDataDefaultsSubnet_Test( ) override = default; Dhcp4ParserTest_optionDataDefaultsSubnet_Test (const Dhcp4ParserTest_optionDataDefaultsSubnet_Test &) = delete; Dhcp4ParserTest_optionDataDefaultsSubnet_Test & operator =( const Dhcp4ParserTest_optionDataDefaultsSubnet_Test &) = delete; Dhcp4ParserTest_optionDataDefaultsSubnet_Test (Dhcp4ParserTest_optionDataDefaultsSubnet_Test &&) noexcept = delete; Dhcp4ParserTest_optionDataDefaultsSubnet_Test & operator=( Dhcp4ParserTest_optionDataDefaultsSubnet_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_optionDataDefaultsSubnet_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDataDefaultsSubnet", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3213), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3213), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3213), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDataDefaultsSubnet_Test >); void Dhcp4ParserTest_optionDataDefaultsSubnet_Test::TestBody () { | |||
| 3214 | ConstElementPtr x; | |||
| 3215 | string config = "{ " + genIfaceConfig() + "," | |||
| 3216 | "\"rebind-timer\": 2000," | |||
| 3217 | "\"renew-timer\": 1000," | |||
| 3218 | "\"subnet4\": [ { " | |||
| 3219 | " \"id\": 1," | |||
| 3220 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 3221 | " \"subnet\": \"192.0.2.0/24\"," | |||
| 3222 | " \"option-data\": [ {" | |||
| 3223 | " \"name\": \"dhcp-message\"," | |||
| 3224 | " \"data\": \"ABCDEF0105\"," | |||
| 3225 | " \"csv-format\": false" | |||
| 3226 | " }," | |||
| 3227 | " {" | |||
| 3228 | " \"name\": \"default-ip-ttl\"," | |||
| 3229 | " \"data\": \"01\"," | |||
| 3230 | " \"csv-format\": false" | |||
| 3231 | " } ]" | |||
| 3232 | " } ]," | |||
| 3233 | "\"valid-lifetime\": 4000 }"; | |||
| 3234 | ||||
| 3235 | ConstElementPtr json; | |||
| 3236 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_3236 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3236 ; } } else gtest_label_testnothrow_3236 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3236, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 3237 | extractConfig(config); | |||
| 3238 | ||||
| 3239 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3239; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3239; } } else gtest_label_testnothrow_3239 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3239, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 3240 | checkResult(x, 0); | |||
| 3241 | ||||
| 3242 | // These options are subnet options | |||
| 3243 | OptionContainerPtr options = | |||
| 3244 | CfgMgr::instance().getStagingCfg()->getCfgOption()->getAll(DHCP4_OPTION_SPACE"dhcp4"); | |||
| 3245 | ASSERT_EQ(0, options->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "options->size()" , 0, options->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3245, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3246 | ||||
| 3247 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 3248 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200")); | |||
| 3249 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3249, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3250 | options = subnet->getCfgOption()->getAll(DHCP4_OPTION_SPACE"dhcp4"); | |||
| 3251 | ASSERT_EQ(2, options->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "options->size()" , 2, options->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3251, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3252 | ||||
| 3253 | // Get the search index. Index #1 is to search using option code. | |||
| 3254 | const OptionContainerTypeIndex& idx = options->get<1>(); | |||
| 3255 | ||||
| 3256 | // Get the options for specified index. Expecting one option to be | |||
| 3257 | // returned but in theory we may have multiple options with the same | |||
| 3258 | // code so we get the range. | |||
| 3259 | std::pair<OptionContainerTypeIndex::const_iterator, | |||
| 3260 | OptionContainerTypeIndex::const_iterator> range = | |||
| 3261 | idx.equal_range(56); | |||
| 3262 | // Expect single option with the code equal to 56. | |||
| 3263 | ASSERT_EQ(1, std::distance(range.first, range.second))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "std::distance(range.first, range.second)" , 1, std::distance(range.first, range.second)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3263, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3264 | const uint8_t foo_expected[] = { | |||
| 3265 | 0xAB, 0xCD, 0xEF, 0x01, 0x05 | |||
| 3266 | }; | |||
| 3267 | // Check if option is valid in terms of code and carried data. | |||
| 3268 | testOption(*range.first, 56, foo_expected, sizeof(foo_expected)); | |||
| 3269 | ||||
| 3270 | range = idx.equal_range(23); | |||
| 3271 | ASSERT_EQ(1, std::distance(range.first, range.second))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "std::distance(range.first, range.second)" , 1, std::distance(range.first, range.second)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3271, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3272 | // Do another round of testing with second option. | |||
| 3273 | const uint8_t foo2_expected[] = { | |||
| 3274 | 0x01 | |||
| 3275 | }; | |||
| 3276 | testOption(*range.first, 23, foo2_expected, sizeof(foo2_expected)); | |||
| 3277 | } | |||
| 3278 | ||||
| 3279 | /// The goal of this test is to verify that two options having the same | |||
| 3280 | /// option code can be added to different option spaces. | |||
| 3281 | TEST_F(Dhcp4ParserTest, optionDataTwoSpaces)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDataTwoSpaces") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionDataTwoSpaces_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDataTwoSpaces_Test() = default ; ~Dhcp4ParserTest_optionDataTwoSpaces_Test() override = default ; Dhcp4ParserTest_optionDataTwoSpaces_Test (const Dhcp4ParserTest_optionDataTwoSpaces_Test &) = delete; Dhcp4ParserTest_optionDataTwoSpaces_Test & operator=( const Dhcp4ParserTest_optionDataTwoSpaces_Test & ) = delete; Dhcp4ParserTest_optionDataTwoSpaces_Test (Dhcp4ParserTest_optionDataTwoSpaces_Test &&) noexcept = delete; Dhcp4ParserTest_optionDataTwoSpaces_Test & operator=( Dhcp4ParserTest_optionDataTwoSpaces_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionDataTwoSpaces_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDataTwoSpaces", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3281), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3281), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3281), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDataTwoSpaces_Test >); void Dhcp4ParserTest_optionDataTwoSpaces_Test::TestBody () { | |||
| 3282 | ||||
| 3283 | // This configuration string is to configure two options | |||
| 3284 | // sharing the code 56 and having different definitions | |||
| 3285 | // and belonging to the different option spaces. | |||
| 3286 | // The option definition must be provided for the | |||
| 3287 | // option that belongs to the 'isc' option space. | |||
| 3288 | // The definition is not required for the option that | |||
| 3289 | // belongs to the 'dhcp4' option space as it is the | |||
| 3290 | // standard option. | |||
| 3291 | string config = "{ " + genIfaceConfig() + "," | |||
| 3292 | "\"valid-lifetime\": 4000," | |||
| 3293 | "\"rebind-timer\": 2000," | |||
| 3294 | "\"renew-timer\": 1000," | |||
| 3295 | "\"option-data\": [ {" | |||
| 3296 | " \"name\": \"dhcp-message\"," | |||
| 3297 | " \"data\": \"ABCDEF0105\"," | |||
| 3298 | " \"csv-format\": false" | |||
| 3299 | " }," | |||
| 3300 | " {" | |||
| 3301 | " \"name\": \"foo\"," | |||
| 3302 | " \"space\": \"isc\"," | |||
| 3303 | " \"data\": \"1234\"" | |||
| 3304 | " } ]," | |||
| 3305 | "\"option-def\": [ {" | |||
| 3306 | " \"name\": \"foo\"," | |||
| 3307 | " \"code\": 56," | |||
| 3308 | " \"type\": \"uint32\"," | |||
| 3309 | " \"space\": \"isc\"" | |||
| 3310 | " } ]," | |||
| 3311 | "\"subnet4\": [ { " | |||
| 3312 | " \"id\": 1," | |||
| 3313 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 3314 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 3315 | " } ]" | |||
| 3316 | "}"; | |||
| 3317 | ||||
| 3318 | ConstElementPtr json; | |||
| 3319 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_3319 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3319 ; } } else gtest_label_testnothrow_3319 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3319, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 3320 | extractConfig(config); | |||
| 3321 | ||||
| 3322 | ConstElementPtr status; | |||
| 3323 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3323; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3323; } } else gtest_label_testnothrow_3323 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3323, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 3324 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3324, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3325 | checkResult(status, 0); | |||
| 3326 | ||||
| 3327 | // Options should be now available | |||
| 3328 | // Try to get the option from the space dhcp4. | |||
| 3329 | OptionDescriptor desc1 = | |||
| 3330 | CfgMgr::instance().getStagingCfg()->getCfgOption()->get(DHCP4_OPTION_SPACE"dhcp4", 56); | |||
| 3331 | ASSERT_TRUE(desc1.option_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(desc1.option_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3331, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "desc1.option_", "false", "true") .c_str()) = ::testing::Message (); | |||
| 3332 | EXPECT_EQ(56, desc1.option_->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("56", "desc1.option_->getType()" , 56, desc1.option_->getType()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3332, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3333 | // Try to get the option from the space isc. | |||
| 3334 | OptionDescriptor desc2 = | |||
| 3335 | CfgMgr::instance().getStagingCfg()->getCfgOption()->get("isc", 56); | |||
| 3336 | ASSERT_TRUE(desc2.option_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(desc2.option_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3336, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "desc2.option_", "false", "true") .c_str()) = ::testing::Message (); | |||
| 3337 | EXPECT_EQ(56, desc1.option_->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("56", "desc1.option_->getType()" , 56, desc1.option_->getType()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3337, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3338 | // Try to get the non-existing option from the non-existing | |||
| 3339 | // option space and expect that option is not returned. | |||
| 3340 | OptionDescriptor desc3 = CfgMgr::instance().getStagingCfg()-> | |||
| 3341 | getCfgOption()->get("non-existing", 56); | |||
| 3342 | ASSERT_FALSE(desc3.option_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(desc3.option_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3342, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "desc3.option_", "true", "false") .c_str()) = ::testing::Message (); | |||
| 3343 | } | |||
| 3344 | ||||
| 3345 | // The goal of this test is to verify that it is possible to | |||
| 3346 | // encapsulate option space containing some options with | |||
| 3347 | // another option. In this test we create base option that | |||
| 3348 | // encapsulates option space 'isc' that comprises two other | |||
| 3349 | // options. Also, for all options their definitions are | |||
| 3350 | // created. | |||
| 3351 | TEST_F(Dhcp4ParserTest, optionDataEncapsulate)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDataEncapsulate") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionDataEncapsulate_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDataEncapsulate_Test() = default ; ~Dhcp4ParserTest_optionDataEncapsulate_Test() override = default ; Dhcp4ParserTest_optionDataEncapsulate_Test (const Dhcp4ParserTest_optionDataEncapsulate_Test &) = delete; Dhcp4ParserTest_optionDataEncapsulate_Test & operator=( const Dhcp4ParserTest_optionDataEncapsulate_Test & ) = delete; Dhcp4ParserTest_optionDataEncapsulate_Test (Dhcp4ParserTest_optionDataEncapsulate_Test &&) noexcept = delete; Dhcp4ParserTest_optionDataEncapsulate_Test & operator=( Dhcp4ParserTest_optionDataEncapsulate_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionDataEncapsulate_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDataEncapsulate", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3351), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3351), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3351), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDataEncapsulate_Test >); void Dhcp4ParserTest_optionDataEncapsulate_Test::TestBody () { | |||
| 3352 | ||||
| 3353 | // @todo DHCP configurations has many dependencies between | |||
| 3354 | // parameters. First of all, configuration for subnet is | |||
| 3355 | // inherited from the global values. Thus subnet has to be | |||
| 3356 | // configured when all global values have been configured. | |||
| 3357 | // Also, an option can encapsulate another option only | |||
| 3358 | // if the latter has been configured. For this reason in this | |||
| 3359 | // test we created two-stage configuration where first we | |||
| 3360 | // created options that belong to encapsulated option space. | |||
| 3361 | // In the second stage we add the base option. Also, the Subnet | |||
| 3362 | // object is configured in the second stage so it is created | |||
| 3363 | // at the very end (when all other parameters are configured). | |||
| 3364 | ||||
| 3365 | // Starting stage 1. Configure sub-options and their definitions. | |||
| 3366 | string config = "{ " + genIfaceConfig() + "," | |||
| 3367 | "\"valid-lifetime\": 4000," | |||
| 3368 | "\"rebind-timer\": 2000," | |||
| 3369 | "\"renew-timer\": 1000," | |||
| 3370 | "\"option-data\": [ {" | |||
| 3371 | " \"name\": \"foo\"," | |||
| 3372 | " \"space\": \"isc\"," | |||
| 3373 | " \"data\": \"1234\"" | |||
| 3374 | " }," | |||
| 3375 | " {" | |||
| 3376 | " \"name\": \"foo2\"," | |||
| 3377 | " \"space\": \"isc\"," | |||
| 3378 | " \"data\": \"192.168.2.1\"" | |||
| 3379 | " } ]," | |||
| 3380 | "\"option-def\": [ {" | |||
| 3381 | " \"name\": \"foo\"," | |||
| 3382 | " \"code\": 1," | |||
| 3383 | " \"type\": \"uint32\"," | |||
| 3384 | " \"space\": \"isc\"" | |||
| 3385 | " }," | |||
| 3386 | " {" | |||
| 3387 | " \"name\": \"foo2\"," | |||
| 3388 | " \"code\": 2," | |||
| 3389 | " \"type\": \"ipv4-address\"," | |||
| 3390 | " \"space\": \"isc\"" | |||
| 3391 | " } ]" | |||
| 3392 | "}"; | |||
| 3393 | ||||
| 3394 | ConstElementPtr json; | |||
| 3395 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_3395 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3395 ; } } else gtest_label_testnothrow_3395 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3395, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 3396 | extractConfig(config); | |||
| 3397 | ||||
| 3398 | ConstElementPtr status; | |||
| 3399 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3399; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3399; } } else gtest_label_testnothrow_3399 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3399, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 3400 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3400, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3401 | checkResult(status, 0); | |||
| 3402 | ||||
| 3403 | CfgMgr::instance().clear(); | |||
| 3404 | ||||
| 3405 | // Stage 2. Configure base option and a subnet. Please note that | |||
| 3406 | // the configuration from the stage 2 is repeated because Kea | |||
| 3407 | // configuration manager sends whole configuration for the lists | |||
| 3408 | // where at least one element is being modified or added. | |||
| 3409 | config = "{ " + genIfaceConfig() + "," | |||
| 3410 | "\"valid-lifetime\": 3000," | |||
| 3411 | "\"rebind-timer\": 2000," | |||
| 3412 | "\"renew-timer\": 1000," | |||
| 3413 | "\"option-data\": [ {" | |||
| 3414 | " \"name\": \"base-option\"," | |||
| 3415 | " \"data\": \"11\"" | |||
| 3416 | " }," | |||
| 3417 | " {" | |||
| 3418 | " \"name\": \"foo\"," | |||
| 3419 | " \"space\": \"isc\"," | |||
| 3420 | " \"data\": \"1234\"" | |||
| 3421 | " }," | |||
| 3422 | " {" | |||
| 3423 | " \"name\": \"foo2\"," | |||
| 3424 | " \"space\": \"isc\"," | |||
| 3425 | " \"data\": \"192.168.2.1\"" | |||
| 3426 | " } ]," | |||
| 3427 | "\"option-def\": [ {" | |||
| 3428 | " \"name\": \"base-option\"," | |||
| 3429 | " \"code\": 222," | |||
| 3430 | " \"type\": \"uint8\"," | |||
| 3431 | " \"space\": \"dhcp4\"," | |||
| 3432 | " \"encapsulate\": \"isc\"" | |||
| 3433 | "}," | |||
| 3434 | "{" | |||
| 3435 | " \"name\": \"foo\"," | |||
| 3436 | " \"code\": 1," | |||
| 3437 | " \"type\": \"uint32\"," | |||
| 3438 | " \"space\": \"isc\"" | |||
| 3439 | " }," | |||
| 3440 | " {" | |||
| 3441 | " \"name\": \"foo2\"," | |||
| 3442 | " \"code\": 2," | |||
| 3443 | " \"type\": \"ipv4-address\"," | |||
| 3444 | " \"space\": \"isc\"" | |||
| 3445 | " } ]," | |||
| 3446 | "\"subnet4\": [ { " | |||
| 3447 | " \"id\": 1," | |||
| 3448 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 3449 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 3450 | " } ]" | |||
| 3451 | "}"; | |||
| 3452 | ||||
| 3453 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_3453 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3453 ; } } else gtest_label_testnothrow_3453 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3453, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 3454 | extractConfig(config); | |||
| 3455 | ||||
| 3456 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3456; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3456; } } else gtest_label_testnothrow_3456 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3456, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 3457 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3457, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3458 | checkResult(status, 0); | |||
| 3459 | ||||
| 3460 | // We should have one option available. | |||
| 3461 | OptionContainerPtr options = | |||
| 3462 | CfgMgr::instance().getStagingCfg()->getCfgOption()->getAll(DHCP4_OPTION_SPACE"dhcp4"); | |||
| 3463 | ASSERT_TRUE(options)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(options)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3463, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "options", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 3464 | ASSERT_EQ(1, options->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "options->size()" , 1, options->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3464, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3465 | ||||
| 3466 | // Get the option. | |||
| 3467 | OptionDescriptor desc = | |||
| 3468 | CfgMgr::instance().getStagingCfg()->getCfgOption()->get(DHCP4_OPTION_SPACE"dhcp4", 222); | |||
| 3469 | EXPECT_TRUE(desc.option_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(desc.option_)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3469, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "desc.option_", "false", "true") .c_str()) = ::testing::Message (); | |||
| 3470 | EXPECT_EQ(222, desc.option_->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("222", "desc.option_->getType()" , 222, desc.option_->getType()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3470, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3471 | ||||
| 3472 | // This option should comprise two sub-options. | |||
| 3473 | // One of them is 'foo' with code 1. | |||
| 3474 | OptionPtr option_foo = desc.option_->getOption(1); | |||
| 3475 | ASSERT_TRUE(option_foo)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(option_foo)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3475, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "option_foo", "false", "true") .c_str()) = ::testing::Message (); | |||
| 3476 | EXPECT_EQ(1, option_foo->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "option_foo->getType()" , 1, option_foo->getType()))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3476, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3477 | ||||
| 3478 | // ...another one 'foo2' with code 2. | |||
| 3479 | OptionPtr option_foo2 = desc.option_->getOption(2); | |||
| 3480 | ASSERT_TRUE(option_foo2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(option_foo2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3480, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "option_foo2", "false", "true") .c_str()) = ::testing::Message (); | |||
| 3481 | EXPECT_EQ(2, option_foo2->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "option_foo2->getType()" , 2, option_foo2->getType()))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3481, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3482 | } | |||
| 3483 | ||||
| 3484 | // Goal of this test is to verify options configuration | |||
| 3485 | // for a single subnet. In particular this test checks | |||
| 3486 | // that local options configuration overrides global | |||
| 3487 | // option setting. | |||
| 3488 | TEST_F(Dhcp4ParserTest, optionDataInSingleSubnet)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDataInSingleSubnet") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionDataInSingleSubnet_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDataInSingleSubnet_Test () = default; ~Dhcp4ParserTest_optionDataInSingleSubnet_Test( ) override = default; Dhcp4ParserTest_optionDataInSingleSubnet_Test (const Dhcp4ParserTest_optionDataInSingleSubnet_Test &) = delete; Dhcp4ParserTest_optionDataInSingleSubnet_Test & operator =( const Dhcp4ParserTest_optionDataInSingleSubnet_Test &) = delete; Dhcp4ParserTest_optionDataInSingleSubnet_Test (Dhcp4ParserTest_optionDataInSingleSubnet_Test &&) noexcept = delete; Dhcp4ParserTest_optionDataInSingleSubnet_Test & operator=( Dhcp4ParserTest_optionDataInSingleSubnet_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_optionDataInSingleSubnet_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDataInSingleSubnet", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3488), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3488), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3488), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDataInSingleSubnet_Test >); void Dhcp4ParserTest_optionDataInSingleSubnet_Test::TestBody () { | |||
| 3489 | ConstElementPtr x; | |||
| 3490 | string config = "{ " + genIfaceConfig() + "," | |||
| 3491 | "\"rebind-timer\": 2000, " | |||
| 3492 | "\"renew-timer\": 1000, " | |||
| 3493 | "\"option-data\": [ {" | |||
| 3494 | " \"name\": \"dhcp-message\"," | |||
| 3495 | " \"data\": \"AB\"," | |||
| 3496 | " \"csv-format\": false" | |||
| 3497 | " } ]," | |||
| 3498 | "\"subnet4\": [ { " | |||
| 3499 | " \"id\": 1," | |||
| 3500 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 3501 | " \"subnet\": \"192.0.2.0/24\", " | |||
| 3502 | " \"option-data\": [ {" | |||
| 3503 | " \"name\": \"dhcp-message\"," | |||
| 3504 | " \"data\": \"ABCDEF0105\"," | |||
| 3505 | " \"csv-format\": false" | |||
| 3506 | " }," | |||
| 3507 | " {" | |||
| 3508 | " \"name\": \"default-ip-ttl\"," | |||
| 3509 | " \"data\": \"01\"," | |||
| 3510 | " \"csv-format\": false" | |||
| 3511 | " } ]" | |||
| 3512 | " } ]," | |||
| 3513 | "\"valid-lifetime\": 4000 }"; | |||
| 3514 | ||||
| 3515 | ConstElementPtr json; | |||
| 3516 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_3516 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3516 ; } } else gtest_label_testnothrow_3516 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3516, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 3517 | extractConfig(config); | |||
| 3518 | ||||
| 3519 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3519; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3519; } } else gtest_label_testnothrow_3519 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3519, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 3520 | checkResult(x, 0); | |||
| 3521 | ||||
| 3522 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 3523 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.24")); | |||
| 3524 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3524, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3525 | OptionContainerPtr options = subnet->getCfgOption()->getAll(DHCP4_OPTION_SPACE"dhcp4"); | |||
| 3526 | ASSERT_EQ(2, options->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "options->size()" , 2, options->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3526, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3527 | ||||
| 3528 | // Get the search index. Index #1 is to search using option code. | |||
| 3529 | const OptionContainerTypeIndex& idx = options->get<1>(); | |||
| 3530 | ||||
| 3531 | // Get the options for specified index. Expecting one option to be | |||
| 3532 | // returned but in theory we may have multiple options with the same | |||
| 3533 | // code so we get the range. | |||
| 3534 | std::pair<OptionContainerTypeIndex::const_iterator, | |||
| 3535 | OptionContainerTypeIndex::const_iterator> range = | |||
| 3536 | idx.equal_range(56); | |||
| 3537 | // Expect single option with the code equal to 100. | |||
| 3538 | ASSERT_EQ(1, std::distance(range.first, range.second))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "std::distance(range.first, range.second)" , 1, std::distance(range.first, range.second)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3538, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3539 | const uint8_t foo_expected[] = { | |||
| 3540 | 0xAB, 0xCD, 0xEF, 0x01, 0x05 | |||
| 3541 | }; | |||
| 3542 | // Check if option is valid in terms of code and carried data. | |||
| 3543 | testOption(*range.first, 56, foo_expected, sizeof(foo_expected)); | |||
| 3544 | ||||
| 3545 | range = idx.equal_range(23); | |||
| 3546 | ASSERT_EQ(1, std::distance(range.first, range.second))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "std::distance(range.first, range.second)" , 1, std::distance(range.first, range.second)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3546, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3547 | // Do another round of testing with second option. | |||
| 3548 | const uint8_t foo2_expected[] = { | |||
| 3549 | 0x01 | |||
| 3550 | }; | |||
| 3551 | testOption(*range.first, 23, foo2_expected, sizeof(foo2_expected)); | |||
| 3552 | } | |||
| 3553 | ||||
| 3554 | // The goal of this test is to check that the option carrying a boolean | |||
| 3555 | // value can be configured using one of the values: "true", "false", "0" | |||
| 3556 | // or "1". | |||
| 3557 | TEST_F(Dhcp4ParserTest, optionDataBoolean)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDataBoolean") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionDataBoolean_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDataBoolean_Test() = default ; ~Dhcp4ParserTest_optionDataBoolean_Test() override = default ; Dhcp4ParserTest_optionDataBoolean_Test (const Dhcp4ParserTest_optionDataBoolean_Test &) = delete; Dhcp4ParserTest_optionDataBoolean_Test & operator=( const Dhcp4ParserTest_optionDataBoolean_Test & ) = delete; Dhcp4ParserTest_optionDataBoolean_Test (Dhcp4ParserTest_optionDataBoolean_Test &&) noexcept = delete; Dhcp4ParserTest_optionDataBoolean_Test & operator=( Dhcp4ParserTest_optionDataBoolean_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionDataBoolean_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDataBoolean", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3557), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3557), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3557), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDataBoolean_Test >); void Dhcp4ParserTest_optionDataBoolean_Test::TestBody( ) { | |||
| 3558 | // Create configuration. Use standard option 19 (ip-forwarding). | |||
| 3559 | std::map<std::string, std::string> params; | |||
| 3560 | params["name"] = "ip-forwarding"; | |||
| 3561 | params["space"] = DHCP4_OPTION_SPACE"dhcp4"; | |||
| 3562 | params["code"] = "19"; | |||
| 3563 | params["data"] = "true"; | |||
| 3564 | params["csv-format"] = "true"; | |||
| 3565 | ||||
| 3566 | std::string config = createConfigWithOption(params); | |||
| 3567 | ASSERT_TRUE(executeConfiguration(config, "parse configuration with a"switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(executeConfiguration( config, "parse configuration with a" " boolean value"))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3568, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "executeConfiguration(config, \"parse configuration with a\" \" boolean value\")" , "false", "true") .c_str()) = ::testing::Message() | |||
| 3568 | " boolean value"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(executeConfiguration( config, "parse configuration with a" " boolean value"))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3568, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "executeConfiguration(config, \"parse configuration with a\" \" boolean value\")" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 3569 | ||||
| 3570 | // The subnet should now hold one option with the code 19. | |||
| 3571 | OptionDescriptor desc = getOptionFromSubnet(IOAddress("192.0.2.24"), 19); | |||
| 3572 | ASSERT_TRUE(desc.option_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(desc.option_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3572, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "desc.option_", "false", "true") .c_str()) = ::testing::Message (); | |||
| 3573 | ||||
| 3574 | // This option should be set to "true", represented as 0x1 in the option | |||
| 3575 | // buffer. | |||
| 3576 | uint8_t expected_option_data[] = { | |||
| 3577 | 0x1 | |||
| 3578 | }; | |||
| 3579 | testConfiguration(params, 19, expected_option_data, | |||
| 3580 | sizeof(expected_option_data)); | |||
| 3581 | ||||
| 3582 | // Configure the option with the "1" value. This should have the same | |||
| 3583 | // effect as if "true" was specified. | |||
| 3584 | params["data"] = "1"; | |||
| 3585 | testConfiguration(params, 19, expected_option_data, | |||
| 3586 | sizeof(expected_option_data)); | |||
| 3587 | ||||
| 3588 | // The value of "1" with a few leading zeros should work too. | |||
| 3589 | params["data"] = "00001"; | |||
| 3590 | testConfiguration(params, 19, expected_option_data, | |||
| 3591 | sizeof(expected_option_data)); | |||
| 3592 | ||||
| 3593 | // Configure the option with the "false" value. | |||
| 3594 | params["data"] = "false"; | |||
| 3595 | // The option buffer should now hold the value of 0. | |||
| 3596 | expected_option_data[0] = 0; | |||
| 3597 | testConfiguration(params, 19, expected_option_data, | |||
| 3598 | sizeof(expected_option_data)); | |||
| 3599 | ||||
| 3600 | // Specifying "0" should have the same effect as "false". | |||
| 3601 | params["data"] = "0"; | |||
| 3602 | testConfiguration(params, 19, expected_option_data, | |||
| 3603 | sizeof(expected_option_data)); | |||
| 3604 | ||||
| 3605 | // The same effect should be for multiple 0 chars. | |||
| 3606 | params["data"] = "00000"; | |||
| 3607 | testConfiguration(params, 19, expected_option_data, | |||
| 3608 | sizeof(expected_option_data)); | |||
| 3609 | ||||
| 3610 | // Bogus values should not be accepted. | |||
| 3611 | params["data"] = "bogus"; | |||
| 3612 | testInvalidOptionParam(params); | |||
| 3613 | ||||
| 3614 | params["data"] = "2"; | |||
| 3615 | testInvalidOptionParam(params); | |||
| 3616 | ||||
| 3617 | // Now let's test that it is possible to use binary format. | |||
| 3618 | params["data"] = "0"; | |||
| 3619 | params["csv-format"] = "false"; | |||
| 3620 | testConfiguration(params, 19, expected_option_data, | |||
| 3621 | sizeof(expected_option_data)); | |||
| 3622 | ||||
| 3623 | // The binary 1 should work as well. | |||
| 3624 | params["data"] = "1"; | |||
| 3625 | expected_option_data[0] = 1; | |||
| 3626 | testConfiguration(params, 19, expected_option_data, | |||
| 3627 | sizeof(expected_option_data)); | |||
| 3628 | ||||
| 3629 | // As well as an even number of digits. | |||
| 3630 | params["data"] = "01"; | |||
| 3631 | testConfiguration(params, 19, expected_option_data, | |||
| 3632 | sizeof(expected_option_data)); | |||
| 3633 | } | |||
| 3634 | ||||
| 3635 | // Goal of this test is to verify options configuration | |||
| 3636 | // for multiple subnets. | |||
| 3637 | TEST_F(Dhcp4ParserTest, optionDataInMultipleSubnets)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDataInMultipleSubnets") > 1 , "test_name must not be empty"); class Dhcp4ParserTest_optionDataInMultipleSubnets_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDataInMultipleSubnets_Test () = default; ~Dhcp4ParserTest_optionDataInMultipleSubnets_Test () override = default; Dhcp4ParserTest_optionDataInMultipleSubnets_Test (const Dhcp4ParserTest_optionDataInMultipleSubnets_Test & ) = delete; Dhcp4ParserTest_optionDataInMultipleSubnets_Test & operator=( const Dhcp4ParserTest_optionDataInMultipleSubnets_Test &) = delete; Dhcp4ParserTest_optionDataInMultipleSubnets_Test (Dhcp4ParserTest_optionDataInMultipleSubnets_Test && ) noexcept = delete; Dhcp4ParserTest_optionDataInMultipleSubnets_Test & operator=( Dhcp4ParserTest_optionDataInMultipleSubnets_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_optionDataInMultipleSubnets_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDataInMultipleSubnets", nullptr, nullptr, ::testing:: internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3637), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3637), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3637), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDataInMultipleSubnets_Test >); void Dhcp4ParserTest_optionDataInMultipleSubnets_Test:: TestBody() { | |||
| 3638 | ConstElementPtr x; | |||
| 3639 | string config = "{ " + genIfaceConfig() + "," | |||
| 3640 | "\"rebind-timer\": 2000, " | |||
| 3641 | "\"renew-timer\": 1000, " | |||
| 3642 | "\"subnet4\": [ { " | |||
| 3643 | " \"id\": 1," | |||
| 3644 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 3645 | " \"subnet\": \"192.0.2.0/24\", " | |||
| 3646 | " \"option-data\": [ {" | |||
| 3647 | " \"name\": \"dhcp-message\"," | |||
| 3648 | " \"data\": \"0102030405060708090A\"," | |||
| 3649 | " \"csv-format\": false" | |||
| 3650 | " } ]" | |||
| 3651 | " }," | |||
| 3652 | " {" | |||
| 3653 | " \"id\": 2," | |||
| 3654 | " \"pools\": [ { \"pool\": \"192.0.3.101 - 192.0.3.150\" } ]," | |||
| 3655 | " \"subnet\": \"192.0.3.0/24\", " | |||
| 3656 | " \"option-data\": [ {" | |||
| 3657 | " \"name\": \"default-ip-ttl\"," | |||
| 3658 | " \"data\": \"FF\"," | |||
| 3659 | " \"csv-format\": false" | |||
| 3660 | " } ]" | |||
| 3661 | " } ]," | |||
| 3662 | "\"valid-lifetime\": 4000 }"; | |||
| 3663 | ||||
| 3664 | ConstElementPtr json; | |||
| 3665 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_3665 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3665 ; } } else gtest_label_testnothrow_3665 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3665, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 3666 | extractConfig(config); | |||
| 3667 | ||||
| 3668 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3668; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3668; } } else gtest_label_testnothrow_3668 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3668, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 3669 | checkResult(x, 0); | |||
| 3670 | ||||
| 3671 | ConstSubnet4Ptr subnet1 = CfgMgr::instance().getStagingCfg()-> | |||
| 3672 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.100")); | |||
| 3673 | ASSERT_TRUE(subnet1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet1)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3673, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 3674 | OptionContainerPtr options1 = subnet1->getCfgOption()->getAll(DHCP4_OPTION_SPACE"dhcp4"); | |||
| 3675 | ASSERT_EQ(1, options1->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "options1->size()" , 1, options1->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3675, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3676 | ||||
| 3677 | // Get the search index. Index #1 is to search using option code. | |||
| 3678 | const OptionContainerTypeIndex& idx1 = options1->get<1>(); | |||
| 3679 | ||||
| 3680 | // Get the options for specified index. Expecting one option to be | |||
| 3681 | // returned but in theory we may have multiple options with the same | |||
| 3682 | // code so we get the range. | |||
| 3683 | std::pair<OptionContainerTypeIndex::const_iterator, | |||
| 3684 | OptionContainerTypeIndex::const_iterator> range1 = | |||
| 3685 | idx1.equal_range(56); | |||
| 3686 | // Expect single option with the code equal to 56. | |||
| 3687 | ASSERT_EQ(1, std::distance(range1.first, range1.second))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "std::distance(range1.first, range1.second)" , 1, std::distance(range1.first, range1.second)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3687, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3688 | const uint8_t foo_expected[] = { | |||
| 3689 | 0x01, 0x02, 0x03, 0x04, 0x05, | |||
| 3690 | 0x06, 0x07, 0x08, 0x09, 0x0A | |||
| 3691 | }; | |||
| 3692 | // Check if option is valid in terms of code and carried data. | |||
| 3693 | testOption(*range1.first, 56, foo_expected, sizeof(foo_expected)); | |||
| 3694 | ||||
| 3695 | // Test another subnet in the same way. | |||
| 3696 | ConstSubnet4Ptr subnet2 = CfgMgr::instance().getStagingCfg()-> | |||
| 3697 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.3.102")); | |||
| 3698 | ASSERT_TRUE(subnet2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3698, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 3699 | OptionContainerPtr options2 = subnet2->getCfgOption()->getAll(DHCP4_OPTION_SPACE"dhcp4"); | |||
| 3700 | ASSERT_EQ(1, options2->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "options2->size()" , 1, options2->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3700, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3701 | ||||
| 3702 | const OptionContainerTypeIndex& idx2 = options2->get<1>(); | |||
| 3703 | std::pair<OptionContainerTypeIndex::const_iterator, | |||
| 3704 | OptionContainerTypeIndex::const_iterator> range2 = | |||
| 3705 | idx2.equal_range(23); | |||
| 3706 | ASSERT_EQ(1, std::distance(range2.first, range2.second))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "std::distance(range2.first, range2.second)" , 1, std::distance(range2.first, range2.second)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3706, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3707 | ||||
| 3708 | const uint8_t foo2_expected[] = { 0xFF }; | |||
| 3709 | testOption(*range2.first, 23, foo2_expected, sizeof(foo2_expected)); | |||
| 3710 | } | |||
| 3711 | ||||
| 3712 | // This test verifies that it is possible to specify options on | |||
| 3713 | // pool levels. | |||
| 3714 | TEST_F(Dhcp4ParserTest, optionDataSinglePool)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDataSinglePool") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionDataSinglePool_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDataSinglePool_Test() = default ; ~Dhcp4ParserTest_optionDataSinglePool_Test() override = default ; Dhcp4ParserTest_optionDataSinglePool_Test (const Dhcp4ParserTest_optionDataSinglePool_Test &) = delete; Dhcp4ParserTest_optionDataSinglePool_Test & operator=( const Dhcp4ParserTest_optionDataSinglePool_Test & ) = delete; Dhcp4ParserTest_optionDataSinglePool_Test (Dhcp4ParserTest_optionDataSinglePool_Test &&) noexcept = delete; Dhcp4ParserTest_optionDataSinglePool_Test & operator=( Dhcp4ParserTest_optionDataSinglePool_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionDataSinglePool_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDataSinglePool", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3714), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3714), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3714), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDataSinglePool_Test >); void Dhcp4ParserTest_optionDataSinglePool_Test::TestBody () { | |||
| 3715 | ConstElementPtr x; | |||
| 3716 | string config = "{ " + genIfaceConfig() + "," | |||
| 3717 | "\"rebind-timer\": 2000, " | |||
| 3718 | "\"renew-timer\": 1000, " | |||
| 3719 | "\"subnet4\": [ { " | |||
| 3720 | " \"id\": 1," | |||
| 3721 | " \"pools\": [ { " | |||
| 3722 | " \"pool\": \"192.0.2.1 - 192.0.2.100\"," | |||
| 3723 | " \"option-data\": [ {" | |||
| 3724 | " \"name\": \"dhcp-message\"," | |||
| 3725 | " \"data\": \"ABCDEF0105\"," | |||
| 3726 | " \"csv-format\": false" | |||
| 3727 | " }," | |||
| 3728 | " {" | |||
| 3729 | " \"name\": \"default-ip-ttl\"," | |||
| 3730 | " \"data\": \"01\"," | |||
| 3731 | " \"csv-format\": false" | |||
| 3732 | " } ]" | |||
| 3733 | " } ]," | |||
| 3734 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 3735 | " } ]," | |||
| 3736 | "\"valid-lifetime\": 4000 }"; | |||
| 3737 | ||||
| 3738 | ConstElementPtr json; | |||
| 3739 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_3739 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3739 ; } } else gtest_label_testnothrow_3739 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3739, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 3740 | extractConfig(config); | |||
| 3741 | ||||
| 3742 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3742; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3742; } } else gtest_label_testnothrow_3742 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3742, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 3743 | checkResult(x, 0); | |||
| 3744 | ||||
| 3745 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 3746 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.24"), classify_); | |||
| 3747 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3747, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3748 | ||||
| 3749 | PoolPtr pool = subnet->getPool(Lease::TYPE_V4, IOAddress("192.0.2.24"), false); | |||
| 3750 | ASSERT_TRUE(pool)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 3750 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3751 | Pool4Ptr pool4 = boost::dynamic_pointer_cast<Pool4>(pool); | |||
| 3752 | ASSERT_TRUE(pool4)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool4)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3752, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool4", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3753 | ||||
| 3754 | OptionContainerPtr options = | |||
| 3755 | pool4->getCfgOption()->getAll(DHCP4_OPTION_SPACE"dhcp4"); | |||
| 3756 | ASSERT_EQ(2, options->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "options->size()" , 2, options->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3756, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3757 | ||||
| 3758 | // Get the search index. Index #1 is to search using option code. | |||
| 3759 | const OptionContainerTypeIndex& idx = options->get<1>(); | |||
| 3760 | ||||
| 3761 | // Get the options for specified index. Expecting one option to be | |||
| 3762 | // returned but in theory we may have multiple options with the same | |||
| 3763 | // code so we get the range. | |||
| 3764 | std::pair<OptionContainerTypeIndex::const_iterator, | |||
| 3765 | OptionContainerTypeIndex::const_iterator> range = | |||
| 3766 | idx.equal_range(56); | |||
| 3767 | // Expect a single option with the code equal to 100. | |||
| 3768 | ASSERT_EQ(1, std::distance(range.first, range.second))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "std::distance(range.first, range.second)" , 1, std::distance(range.first, range.second)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3768, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3769 | const uint8_t foo_expected[] = { | |||
| 3770 | 0xAB, 0xCD, 0xEF, 0x01, 0x05 | |||
| 3771 | }; | |||
| 3772 | // Check if option is valid in terms of code and carried data. | |||
| 3773 | testOption(*range.first, 56, foo_expected, sizeof(foo_expected)); | |||
| 3774 | ||||
| 3775 | range = idx.equal_range(23); | |||
| 3776 | ASSERT_EQ(1, std::distance(range.first, range.second))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "std::distance(range.first, range.second)" , 1, std::distance(range.first, range.second)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3776, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3777 | // Do another round of testing with second option. | |||
| 3778 | ||||
| 3779 | const uint8_t foo2_expected[] = { | |||
| 3780 | 0x01 | |||
| 3781 | }; | |||
| 3782 | testOption(*range.first, 23, foo2_expected, sizeof(foo2_expected)); | |||
| 3783 | } | |||
| 3784 | ||||
| 3785 | // This test verifies that it's possible to define different options in | |||
| 3786 | // different pools and those options are not confused. | |||
| 3787 | TEST_F(Dhcp4ParserTest, optionDataMultiplePools)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDataMultiplePools") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionDataMultiplePools_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDataMultiplePools_Test () = default; ~Dhcp4ParserTest_optionDataMultiplePools_Test() override = default; Dhcp4ParserTest_optionDataMultiplePools_Test (const Dhcp4ParserTest_optionDataMultiplePools_Test &) = delete; Dhcp4ParserTest_optionDataMultiplePools_Test & operator =( const Dhcp4ParserTest_optionDataMultiplePools_Test &) = delete; Dhcp4ParserTest_optionDataMultiplePools_Test (Dhcp4ParserTest_optionDataMultiplePools_Test &&) noexcept = delete; Dhcp4ParserTest_optionDataMultiplePools_Test & operator=( Dhcp4ParserTest_optionDataMultiplePools_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_optionDataMultiplePools_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDataMultiplePools", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3787), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3787), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3787), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDataMultiplePools_Test >); void Dhcp4ParserTest_optionDataMultiplePools_Test::TestBody () { | |||
| 3788 | ConstElementPtr x; | |||
| 3789 | string config = "{ " + genIfaceConfig() + "," | |||
| 3790 | "\"rebind-timer\": 2000, " | |||
| 3791 | "\"renew-timer\": 1000, " | |||
| 3792 | "\"subnet4\": [ { " | |||
| 3793 | " \"id\": 1," | |||
| 3794 | " \"pools\": [ { " | |||
| 3795 | " \"pool\": \"192.0.2.1 - 192.0.2.100\"," | |||
| 3796 | " \"option-data\": [ {" | |||
| 3797 | " \"name\": \"dhcp-message\"," | |||
| 3798 | " \"data\": \"ABCDEF0105\"," | |||
| 3799 | " \"csv-format\": false" | |||
| 3800 | " } ]" | |||
| 3801 | " }," | |||
| 3802 | " {" | |||
| 3803 | " \"pool\": \"192.0.2.200 - 192.0.2.250\"," | |||
| 3804 | " \"option-data\": [ {" | |||
| 3805 | " \"name\": \"default-ip-ttl\"," | |||
| 3806 | " \"data\": \"01\"," | |||
| 3807 | " \"csv-format\": false" | |||
| 3808 | " } ]" | |||
| 3809 | " } ]," | |||
| 3810 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 3811 | " } ]," | |||
| 3812 | "\"valid-lifetime\": 4000 }"; | |||
| 3813 | ||||
| 3814 | ConstElementPtr json; | |||
| 3815 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_3815 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3815 ; } } else gtest_label_testnothrow_3815 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3815, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 3816 | extractConfig(config); | |||
| 3817 | ||||
| 3818 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3818; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3818; } } else gtest_label_testnothrow_3818 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3818, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 3819 | checkResult(x, 0); | |||
| 3820 | ||||
| 3821 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 3822 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.24"), classify_); | |||
| 3823 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3823, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3824 | ||||
| 3825 | PoolPtr pool1 = subnet->getPool(Lease::TYPE_V4, IOAddress("192.0.2.24"), false); | |||
| 3826 | ASSERT_TRUE(pool1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool1)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3826, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool1", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3827 | Pool4Ptr pool41 = boost::dynamic_pointer_cast<Pool4>(pool1); | |||
| 3828 | ASSERT_TRUE(pool41)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool41)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3828, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool41", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3829 | ||||
| 3830 | OptionContainerPtr options1 = | |||
| 3831 | pool41->getCfgOption()->getAll(DHCP4_OPTION_SPACE"dhcp4"); | |||
| 3832 | ASSERT_EQ(1, options1->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "options1->size()" , 1, options1->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3832, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3833 | ||||
| 3834 | // Get the search index. Index #1 is to search using option code. | |||
| 3835 | const OptionContainerTypeIndex& idx1 = options1->get<1>(); | |||
| 3836 | ||||
| 3837 | // Get the options for specified index. Expecting one option to be | |||
| 3838 | // returned but in theory we may have multiple options with the same | |||
| 3839 | // code so we get the range. | |||
| 3840 | std::pair<OptionContainerTypeIndex::const_iterator, | |||
| 3841 | OptionContainerTypeIndex::const_iterator> range1 = | |||
| 3842 | idx1.equal_range(56); | |||
| 3843 | // Expect a single option with the code equal to 100. | |||
| 3844 | ASSERT_EQ(1, std::distance(range1.first, range1.second))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "std::distance(range1.first, range1.second)" , 1, std::distance(range1.first, range1.second)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3844, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3845 | const uint8_t foo_expected[] = { | |||
| 3846 | 0xAB, 0xCD, 0xEF, 0x01, 0x05 | |||
| 3847 | }; | |||
| 3848 | // Check if option is valid in terms of code and carried data. | |||
| 3849 | testOption(*range1.first, 56, foo_expected, sizeof(foo_expected)); | |||
| 3850 | ||||
| 3851 | // Test another pool in the same way. | |||
| 3852 | PoolPtr pool2 = subnet->getPool(Lease::TYPE_V4, IOAddress("192.0.2.240"), false); | |||
| 3853 | ASSERT_TRUE(pool2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3853, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool2", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3854 | Pool4Ptr pool42 = boost::dynamic_pointer_cast<Pool4>(pool2); | |||
| 3855 | ASSERT_TRUE(pool42)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool42)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3855, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool42", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3856 | ||||
| 3857 | OptionContainerPtr options2 = | |||
| 3858 | pool42->getCfgOption()->getAll(DHCP4_OPTION_SPACE"dhcp4"); | |||
| 3859 | ASSERT_EQ(1, options2->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "options2->size()" , 1, options2->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3859, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3860 | ||||
| 3861 | const OptionContainerTypeIndex& idx2 = options2->get<1>(); | |||
| 3862 | std::pair<OptionContainerTypeIndex::const_iterator, | |||
| 3863 | OptionContainerTypeIndex::const_iterator> range2 = | |||
| 3864 | idx2.equal_range(23); | |||
| 3865 | ASSERT_EQ(1, std::distance(range2.first, range2.second))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "std::distance(range2.first, range2.second)" , 1, std::distance(range2.first, range2.second)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3865, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3866 | const uint8_t foo2_expected[] = { | |||
| 3867 | 0x01 | |||
| 3868 | }; | |||
| 3869 | testOption(*range2.first, 23, foo2_expected, sizeof(foo2_expected)); | |||
| 3870 | } | |||
| 3871 | ||||
| 3872 | // Verify that empty option name is rejected in the configuration. | |||
| 3873 | TEST_F(Dhcp4ParserTest, optionNameEmpty)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionNameEmpty") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionNameEmpty_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionNameEmpty_Test() = default; ~ Dhcp4ParserTest_optionNameEmpty_Test() override = default; Dhcp4ParserTest_optionNameEmpty_Test (const Dhcp4ParserTest_optionNameEmpty_Test &) = delete; Dhcp4ParserTest_optionNameEmpty_Test & operator=( const Dhcp4ParserTest_optionNameEmpty_Test &) = delete; Dhcp4ParserTest_optionNameEmpty_Test (Dhcp4ParserTest_optionNameEmpty_Test &&) noexcept = delete; Dhcp4ParserTest_optionNameEmpty_Test & operator=( Dhcp4ParserTest_optionNameEmpty_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionNameEmpty_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionNameEmpty", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 3873 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3873), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3873), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionNameEmpty_Test >); void Dhcp4ParserTest_optionNameEmpty_Test::TestBody() { | |||
| 3874 | // Empty option names not allowed. | |||
| 3875 | testInvalidOptionParam("", "name"); | |||
| 3876 | } | |||
| 3877 | ||||
| 3878 | // Verify that empty option name with spaces is rejected | |||
| 3879 | // in the configuration. | |||
| 3880 | TEST_F(Dhcp4ParserTest, optionNameSpaces)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionNameSpaces") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionNameSpaces_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionNameSpaces_Test() = default; ~Dhcp4ParserTest_optionNameSpaces_Test() override = default; Dhcp4ParserTest_optionNameSpaces_Test (const Dhcp4ParserTest_optionNameSpaces_Test &) = delete; Dhcp4ParserTest_optionNameSpaces_Test & operator=( const Dhcp4ParserTest_optionNameSpaces_Test & ) = delete; Dhcp4ParserTest_optionNameSpaces_Test (Dhcp4ParserTest_optionNameSpaces_Test &&) noexcept = delete; Dhcp4ParserTest_optionNameSpaces_Test & operator=( Dhcp4ParserTest_optionNameSpaces_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionNameSpaces_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionNameSpaces", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3880), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3880), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3880), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionNameSpaces_Test >); void Dhcp4ParserTest_optionNameSpaces_Test::TestBody() { | |||
| 3881 | // Spaces in option names not allowed. | |||
| 3882 | testInvalidOptionParam("option foo", "name"); | |||
| 3883 | } | |||
| 3884 | ||||
| 3885 | // Verify that negative option code is rejected in the configuration. | |||
| 3886 | TEST_F(Dhcp4ParserTest, optionCodeNegative)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionCodeNegative") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionCodeNegative_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionCodeNegative_Test() = default ; ~Dhcp4ParserTest_optionCodeNegative_Test() override = default ; Dhcp4ParserTest_optionCodeNegative_Test (const Dhcp4ParserTest_optionCodeNegative_Test &) = delete; Dhcp4ParserTest_optionCodeNegative_Test & operator=( const Dhcp4ParserTest_optionCodeNegative_Test & ) = delete; Dhcp4ParserTest_optionCodeNegative_Test (Dhcp4ParserTest_optionCodeNegative_Test &&) noexcept = delete; Dhcp4ParserTest_optionCodeNegative_Test & operator=( Dhcp4ParserTest_optionCodeNegative_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionCodeNegative_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionCodeNegative", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3886), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3886), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3886), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionCodeNegative_Test >); void Dhcp4ParserTest_optionCodeNegative_Test::TestBody () { | |||
| 3887 | // Check negative option code -4. This should fail too. | |||
| 3888 | testInvalidOptionParam("-4", "code"); | |||
| 3889 | } | |||
| 3890 | ||||
| 3891 | // Verify that out of bounds option code is rejected in the configuration. | |||
| 3892 | TEST_F(Dhcp4ParserTest, optionCodeNonUint8)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionCodeNonUint8") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionCodeNonUint8_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionCodeNonUint8_Test() = default ; ~Dhcp4ParserTest_optionCodeNonUint8_Test() override = default ; Dhcp4ParserTest_optionCodeNonUint8_Test (const Dhcp4ParserTest_optionCodeNonUint8_Test &) = delete; Dhcp4ParserTest_optionCodeNonUint8_Test & operator=( const Dhcp4ParserTest_optionCodeNonUint8_Test & ) = delete; Dhcp4ParserTest_optionCodeNonUint8_Test (Dhcp4ParserTest_optionCodeNonUint8_Test &&) noexcept = delete; Dhcp4ParserTest_optionCodeNonUint8_Test & operator=( Dhcp4ParserTest_optionCodeNonUint8_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionCodeNonUint8_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionCodeNonUint8", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3892), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3892), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3892), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionCodeNonUint8_Test >); void Dhcp4ParserTest_optionCodeNonUint8_Test::TestBody () { | |||
| 3893 | // The valid option codes are uint8_t values so passing | |||
| 3894 | // uint8_t maximum value incremented by 1 should result | |||
| 3895 | // in failure. | |||
| 3896 | testInvalidOptionParam("257", "code"); | |||
| 3897 | } | |||
| 3898 | ||||
| 3899 | // Verify that out of bounds option code is rejected in the configuration. | |||
| 3900 | TEST_F(Dhcp4ParserTest, optionCodeHighNonUint8)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionCodeHighNonUint8") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionCodeHighNonUint8_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionCodeHighNonUint8_Test () = default; ~Dhcp4ParserTest_optionCodeHighNonUint8_Test() override = default; Dhcp4ParserTest_optionCodeHighNonUint8_Test (const Dhcp4ParserTest_optionCodeHighNonUint8_Test &) = delete; Dhcp4ParserTest_optionCodeHighNonUint8_Test & operator=( const Dhcp4ParserTest_optionCodeHighNonUint8_Test &) = delete ; Dhcp4ParserTest_optionCodeHighNonUint8_Test (Dhcp4ParserTest_optionCodeHighNonUint8_Test &&) noexcept = delete; Dhcp4ParserTest_optionCodeHighNonUint8_Test & operator=( Dhcp4ParserTest_optionCodeHighNonUint8_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_optionCodeHighNonUint8_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionCodeHighNonUint8", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3900), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3900), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3900), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionCodeHighNonUint8_Test >); void Dhcp4ParserTest_optionCodeHighNonUint8_Test::TestBody () { | |||
| 3901 | // Another check for uint8_t overflow but this time | |||
| 3902 | // let's pass even greater option code value. | |||
| 3903 | testInvalidOptionParam("500", "code"); | |||
| 3904 | } | |||
| 3905 | ||||
| 3906 | // Verify that zero option code is rejected in the configuration. | |||
| 3907 | TEST_F(Dhcp4ParserTest, optionCodeZero)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionCodeZero") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_optionCodeZero_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionCodeZero_Test() = default; ~ Dhcp4ParserTest_optionCodeZero_Test() override = default; Dhcp4ParserTest_optionCodeZero_Test (const Dhcp4ParserTest_optionCodeZero_Test &) = delete; Dhcp4ParserTest_optionCodeZero_Test & operator=( const Dhcp4ParserTest_optionCodeZero_Test & ) = delete; Dhcp4ParserTest_optionCodeZero_Test (Dhcp4ParserTest_optionCodeZero_Test &&) noexcept = delete; Dhcp4ParserTest_optionCodeZero_Test & operator=( Dhcp4ParserTest_optionCodeZero_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_optionCodeZero_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionCodeZero", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 3907 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3907), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3907), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionCodeZero_Test >); void Dhcp4ParserTest_optionCodeZero_Test::TestBody() { | |||
| 3908 | // Option code 0 is reserved and should not be accepted | |||
| 3909 | // by configuration parser. | |||
| 3910 | testInvalidOptionParam("0", "code"); | |||
| 3911 | } | |||
| 3912 | ||||
| 3913 | // Verify that invalid hex literals for option data are detected. | |||
| 3914 | TEST_F(Dhcp4ParserTest, optionDataInvalidHexLiterals)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDataInvalidHexLiterals") > 1 , "test_name must not be empty"); class Dhcp4ParserTest_optionDataInvalidHexLiterals_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDataInvalidHexLiterals_Test () = default; ~Dhcp4ParserTest_optionDataInvalidHexLiterals_Test () override = default; Dhcp4ParserTest_optionDataInvalidHexLiterals_Test (const Dhcp4ParserTest_optionDataInvalidHexLiterals_Test & ) = delete; Dhcp4ParserTest_optionDataInvalidHexLiterals_Test & operator=( const Dhcp4ParserTest_optionDataInvalidHexLiterals_Test &) = delete; Dhcp4ParserTest_optionDataInvalidHexLiterals_Test (Dhcp4ParserTest_optionDataInvalidHexLiterals_Test && ) noexcept = delete; Dhcp4ParserTest_optionDataInvalidHexLiterals_Test & operator=( Dhcp4ParserTest_optionDataInvalidHexLiterals_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_optionDataInvalidHexLiterals_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDataInvalidHexLiterals", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3914), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3914), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3914), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDataInvalidHexLiterals_Test >); void Dhcp4ParserTest_optionDataInvalidHexLiterals_Test ::TestBody() { | |||
| 3915 | testInvalidOptionParam("01020R", "data"); // non hex digit | |||
| 3916 | testInvalidOptionParam("0x01:02", "data"); // 0x prefix with colon separator | |||
| 3917 | testInvalidOptionParam("0x01 02", "data"); // 0x prefix with space separator | |||
| 3918 | testInvalidOptionParam("0X0102", "data"); // 0X upper case X in prefix | |||
| 3919 | testInvalidOptionParam("01.02", "data"); // invalid separator | |||
| 3920 | } | |||
| 3921 | ||||
| 3922 | // Verify the valid forms hex literals in option data are supported. | |||
| 3923 | TEST_F(Dhcp4ParserTest, optionDataValidHexLiterals)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionDataValidHexLiterals") > 1, "test_name must not be empty"); class Dhcp4ParserTest_optionDataValidHexLiterals_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionDataValidHexLiterals_Test () = default; ~Dhcp4ParserTest_optionDataValidHexLiterals_Test () override = default; Dhcp4ParserTest_optionDataValidHexLiterals_Test (const Dhcp4ParserTest_optionDataValidHexLiterals_Test & ) = delete; Dhcp4ParserTest_optionDataValidHexLiterals_Test & operator=( const Dhcp4ParserTest_optionDataValidHexLiterals_Test &) = delete; Dhcp4ParserTest_optionDataValidHexLiterals_Test (Dhcp4ParserTest_optionDataValidHexLiterals_Test &&) noexcept = delete; Dhcp4ParserTest_optionDataValidHexLiterals_Test & operator=( Dhcp4ParserTest_optionDataValidHexLiterals_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_optionDataValidHexLiterals_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionDataValidHexLiterals", nullptr, nullptr, ::testing:: internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3923), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3923), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3923), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionDataValidHexLiterals_Test >); void Dhcp4ParserTest_optionDataValidHexLiterals_Test:: TestBody() { | |||
| 3924 | ||||
| 3925 | std::vector<std::string> valid_hexes = | |||
| 3926 | { | |||
| 3927 | "0a0b0C0D", // upper and lower case | |||
| 3928 | "0A:0B:0C:0D", // colon seperator | |||
| 3929 | "0A 0B 0C 0D", // space seperator | |||
| 3930 | "A0B0C0D", // odd number of digits | |||
| 3931 | "0xA0B0C0D" // 0x prefix | |||
| 3932 | }; | |||
| 3933 | ||||
| 3934 | for (auto const& valid_hex : valid_hexes) { | |||
| 3935 | ConstElementPtr x; | |||
| 3936 | std::string config = createConfigWithOption(valid_hex, "data"); | |||
| 3937 | ConstElementPtr json; | |||
| 3938 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_3938 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3938 ; } } else gtest_label_testnothrow_3938 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3938, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 3939 | ||||
| 3940 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3940; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3940; } } else gtest_label_testnothrow_3940 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3940, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 3941 | checkResult(x, 0); | |||
| 3942 | ||||
| 3943 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 3944 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.5")); | |||
| 3945 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3945, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3946 | OptionContainerPtr options = subnet->getCfgOption()->getAll(DHCP4_OPTION_SPACE"dhcp4"); | |||
| 3947 | ASSERT_EQ(1, options->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "options->size()" , 1, options->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3947, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3948 | ||||
| 3949 | // Get the search index. Index #1 is to search using option code. | |||
| 3950 | const OptionContainerTypeIndex& idx = options->get<1>(); | |||
| 3951 | ||||
| 3952 | // Get the options for specified index. Expecting one option to be | |||
| 3953 | // returned but in theory we may have multiple options with the same | |||
| 3954 | // code so we get the range. | |||
| 3955 | std::pair<OptionContainerTypeIndex::const_iterator, | |||
| 3956 | OptionContainerTypeIndex::const_iterator> range = | |||
| 3957 | idx.equal_range(56); | |||
| 3958 | ||||
| 3959 | // Expect single option with the code equal to 100. | |||
| 3960 | ASSERT_EQ(1, std::distance(range.first, range.second))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "std::distance(range.first, range.second)" , 1, std::distance(range.first, range.second)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3960, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3961 | const uint8_t foo_expected[] = { 0x0A, 0x0B, 0x0C, 0x0D }; | |||
| 3962 | ||||
| 3963 | // Check if option is valid in terms of code and carried data. | |||
| 3964 | testOption(*range.first, 56, foo_expected, sizeof(foo_expected)); | |||
| 3965 | ||||
| 3966 | // Clear configuration for the next pass. | |||
| 3967 | resetConfiguration(); | |||
| 3968 | } | |||
| 3969 | } | |||
| 3970 | ||||
| 3971 | // Verify that specific option object is returned for standard | |||
| 3972 | // option which has dedicated option class derived from Option. | |||
| 3973 | TEST_F(Dhcp4ParserTest, stdOptionData)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("stdOptionData") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_stdOptionData_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_stdOptionData_Test() = default; ~Dhcp4ParserTest_stdOptionData_Test () override = default; Dhcp4ParserTest_stdOptionData_Test (const Dhcp4ParserTest_stdOptionData_Test &) = delete; Dhcp4ParserTest_stdOptionData_Test & operator=( const Dhcp4ParserTest_stdOptionData_Test & ) = delete; Dhcp4ParserTest_stdOptionData_Test (Dhcp4ParserTest_stdOptionData_Test &&) noexcept = delete; Dhcp4ParserTest_stdOptionData_Test & operator=( Dhcp4ParserTest_stdOptionData_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_stdOptionData_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "stdOptionData", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 3973 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3973), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3973), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_stdOptionData_Test >); void Dhcp4ParserTest_stdOptionData_Test::TestBody() { | |||
| 3974 | ConstElementPtr x; | |||
| 3975 | std::map<std::string, std::string> params; | |||
| 3976 | params["name"] = "nis-servers"; | |||
| 3977 | params["space"] = DHCP4_OPTION_SPACE"dhcp4"; | |||
| 3978 | // Option code 41 means nis-servers. | |||
| 3979 | params["code"] = "41"; | |||
| 3980 | // Specify option values in a CSV (user friendly) format. | |||
| 3981 | params["data"] = "192.0.2.10, 192.0.2.1, 192.0.2.3"; | |||
| 3982 | params["csv-format"] = "true"; | |||
| 3983 | ||||
| 3984 | std::string config = createConfigWithOption(params); | |||
| 3985 | ConstElementPtr json; | |||
| 3986 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_3986 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3986 ; } } else gtest_label_testnothrow_3986 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3986, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 3987 | ||||
| 3988 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_3988; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_3988; } } else gtest_label_testnothrow_3988 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3988, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 3989 | checkResult(x, 0); | |||
| 3990 | ||||
| 3991 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 3992 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.5")); | |||
| 3993 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3993, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 3994 | OptionContainerPtr options = subnet->getCfgOption()->getAll(DHCP4_OPTION_SPACE"dhcp4"); | |||
| 3995 | ASSERT_TRUE(options)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(options)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3995, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "options", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 3996 | ASSERT_EQ(1, options->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "options->size()" , 1, options->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 3996, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 3997 | ||||
| 3998 | // Get the search index. Index #1 is to search using option code. | |||
| 3999 | const OptionContainerTypeIndex& idx = options->get<1>(); | |||
| 4000 | ||||
| 4001 | // Get the options for specified index. Expecting one option to be | |||
| 4002 | // returned but in theory we may have multiple options with the same | |||
| 4003 | // code so we get the range. | |||
| 4004 | std::pair<OptionContainerTypeIndex::const_iterator, | |||
| 4005 | OptionContainerTypeIndex::const_iterator> range = | |||
| 4006 | idx.equal_range(DHO_NIS_SERVERS); | |||
| 4007 | // Expect single option with the code equal to NIS_SERVERS option code. | |||
| 4008 | ASSERT_EQ(1, std::distance(range.first, range.second))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "std::distance(range.first, range.second)" , 1, std::distance(range.first, range.second)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4008, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4009 | // The actual pointer to the option is held in the option field | |||
| 4010 | // in the structure returned. | |||
| 4011 | OptionPtr option = range.first->option_; | |||
| 4012 | ASSERT_TRUE(option)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(option)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4012, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "option", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4013 | // Option object returned for here is expected to be Option4AddrLst | |||
| 4014 | // which is derived from Option. This class is dedicated to | |||
| 4015 | // represent standard option DHO_NIS_SERVERS. | |||
| 4016 | boost::shared_ptr<Option4AddrLst> option_addrs = | |||
| 4017 | boost::dynamic_pointer_cast<Option4AddrLst>(option); | |||
| 4018 | // If cast is unsuccessful than option returned was of a | |||
| 4019 | // different type than Option4AddrLst. This is wrong. | |||
| 4020 | ASSERT_TRUE(option_addrs)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(option_addrs)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4020, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "option_addrs", "false", "true") .c_str()) = ::testing::Message (); | |||
| 4021 | ||||
| 4022 | // Get addresses from the option. | |||
| 4023 | Option4AddrLst::AddressContainer addrs = option_addrs->getAddresses(); | |||
| 4024 | // Verify that the addresses have been configured correctly. | |||
| 4025 | ASSERT_EQ(3, addrs.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("3", "addrs.size()" , 3, addrs.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4025, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4026 | EXPECT_EQ("192.0.2.10", addrs[0].toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.10\"" , "addrs[0].toText()", "192.0.2.10", addrs[0].toText()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4026, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4027 | EXPECT_EQ("192.0.2.1", addrs[1].toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.1\"" , "addrs[1].toText()", "192.0.2.1", addrs[1].toText()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4027, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4028 | EXPECT_EQ("192.0.2.3", addrs[2].toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.2.3\"" , "addrs[2].toText()", "192.0.2.3", addrs[2].toText()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4028, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4029 | } | |||
| 4030 | ||||
| 4031 | /// This test checks if Uint32Parser can really parse the whole range | |||
| 4032 | /// and properly err of out of range values. As we can't call Uint32Parser | |||
| 4033 | /// directly, we are exploiting the fact that it is used to parse global | |||
| 4034 | /// parameter renew-timer and the results are stored in uint32_defaults. | |||
| 4035 | /// We get the uint32_defaults using a getUint32Defaults functions which | |||
| 4036 | /// is defined only to access the values from this test. | |||
| 4037 | TEST_F(Dhcp4ParserTest, DISABLED_Uint32Parser)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("DISABLED_Uint32Parser") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_DISABLED_Uint32Parser_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_DISABLED_Uint32Parser_Test() = default ; ~Dhcp4ParserTest_DISABLED_Uint32Parser_Test() override = default ; Dhcp4ParserTest_DISABLED_Uint32Parser_Test (const Dhcp4ParserTest_DISABLED_Uint32Parser_Test &) = delete; Dhcp4ParserTest_DISABLED_Uint32Parser_Test & operator=( const Dhcp4ParserTest_DISABLED_Uint32Parser_Test & ) = delete; Dhcp4ParserTest_DISABLED_Uint32Parser_Test (Dhcp4ParserTest_DISABLED_Uint32Parser_Test &&) noexcept = delete; Dhcp4ParserTest_DISABLED_Uint32Parser_Test & operator=( Dhcp4ParserTest_DISABLED_Uint32Parser_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_DISABLED_Uint32Parser_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "DISABLED_Uint32Parser", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4037), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4037), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4037), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_DISABLED_Uint32Parser_Test >); void Dhcp4ParserTest_DISABLED_Uint32Parser_Test::TestBody () { | |||
| 4038 | ||||
| 4039 | ConstElementPtr status; | |||
| 4040 | ||||
| 4041 | // CASE 1: 0 - minimum value, should work | |||
| 4042 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_,switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, parseDHCP4("{\"renew-timer\": 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_4043; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4043 ; } } else gtest_label_testnothrow_4043 : ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4043, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, parseDHCP4(\"{\\\"renew-timer\\\": 0}\"))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() | |||
| 4043 | parseDHCP4("{\"renew-timer\": 0}")))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, parseDHCP4("{\"renew-timer\": 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_4043; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4043 ; } } else gtest_label_testnothrow_4043 : ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4043, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, parseDHCP4(\"{\\\"renew-timer\\\": 0}\"))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4044 | ||||
| 4045 | // returned value must be ok (0 is a proper value) | |||
| 4046 | checkResult(status, 0); | |||
| 4047 | /// @todo: check that the renew-timer is really 0 | |||
| 4048 | ||||
| 4049 | // CASE 2: 4294967295U (UINT_MAX) should work as well | |||
| 4050 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_,switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, parseDHCP4("{\"renew-timer\": 4294967295}" )); } else static_assert(true, ""); } catch (std::exception const & e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg .value += "\"."; goto gtest_label_testnothrow_4051; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4051 ; } } else gtest_label_testnothrow_4051 : ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4051, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, parseDHCP4(\"{\\\"renew-timer\\\": 4294967295}\"))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() | |||
| 4051 | parseDHCP4("{\"renew-timer\": 4294967295}")))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, parseDHCP4("{\"renew-timer\": 4294967295}" )); } else static_assert(true, ""); } catch (std::exception const & e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg .value += "\"."; goto gtest_label_testnothrow_4051; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4051 ; } } else gtest_label_testnothrow_4051 : ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4051, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, parseDHCP4(\"{\\\"renew-timer\\\": 4294967295}\"))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4052 | ||||
| 4053 | // returned value must be ok (0 is a proper value) | |||
| 4054 | checkResult(status, 0); | |||
| 4055 | /// @todo: check that the renew-timer is really 4294967295U | |||
| 4056 | ||||
| 4057 | // CASE 3: 4294967296U (UINT_MAX + 1) should not work | |||
| 4058 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_,switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, parseJSON("{\"renew-timer\": 4294967296}" )); } else static_assert(true, ""); } catch (std::exception const & e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg .value += "\"."; goto gtest_label_testnothrow_4059; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4059 ; } } else gtest_label_testnothrow_4059 : ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4059, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, parseJSON(\"{\\\"renew-timer\\\": 4294967296}\"))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() | |||
| 4059 | parseJSON("{\"renew-timer\": 4294967296}")))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, parseJSON("{\"renew-timer\": 4294967296}" )); } else static_assert(true, ""); } catch (std::exception const & e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName(typeid(e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg .value += "\"."; goto gtest_label_testnothrow_4059; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4059 ; } } else gtest_label_testnothrow_4059 : ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4059, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, parseJSON(\"{\\\"renew-timer\\\": 4294967296}\"))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4060 | ||||
| 4061 | // returned value must be rejected (1 configuration error) | |||
| 4062 | checkResult(status, 1); | |||
| 4063 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4063, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 4064 | ||||
| 4065 | // CASE 4: -1 (UINT_MIN -1 ) should not work | |||
| 4066 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_,switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, parseJSON("{\"renew-timer\": -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_4067; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4067 ; } } else gtest_label_testnothrow_4067 : ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4067, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, parseJSON(\"{\\\"renew-timer\\\": -1}\"))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() | |||
| 4067 | parseJSON("{\"renew-timer\": -1}")))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, parseJSON("{\"renew-timer\": -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_4067; } catch ( ...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4067 ; } } else gtest_label_testnothrow_4067 : ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4067, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, parseJSON(\"{\\\"renew-timer\\\": -1}\"))" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4068 | ||||
| 4069 | // returned value must be rejected (1 configuration error) | |||
| 4070 | checkResult(status, 1); | |||
| 4071 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4071, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 4072 | } | |||
| 4073 | ||||
| 4074 | // The goal of this test is to verify that the domain-search option | |||
| 4075 | // can be set using domain names | |||
| 4076 | TEST_F(Dhcp4ParserTest, domainSearchOption)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("domainSearchOption") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_domainSearchOption_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_domainSearchOption_Test() = default ; ~Dhcp4ParserTest_domainSearchOption_Test() override = default ; Dhcp4ParserTest_domainSearchOption_Test (const Dhcp4ParserTest_domainSearchOption_Test &) = delete; Dhcp4ParserTest_domainSearchOption_Test & operator=( const Dhcp4ParserTest_domainSearchOption_Test & ) = delete; Dhcp4ParserTest_domainSearchOption_Test (Dhcp4ParserTest_domainSearchOption_Test &&) noexcept = delete; Dhcp4ParserTest_domainSearchOption_Test & operator=( Dhcp4ParserTest_domainSearchOption_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_domainSearchOption_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "domainSearchOption", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4076), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4076), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4076), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_domainSearchOption_Test >); void Dhcp4ParserTest_domainSearchOption_Test::TestBody () { | |||
| 4077 | // Create configuration. | |||
| 4078 | std::map<std::string, std::string> params; | |||
| 4079 | params["name"] = "domain-search"; | |||
| 4080 | params["space"] = DHCP4_OPTION_SPACE"dhcp4"; | |||
| 4081 | params["code"] = "119"; // DHO_DOMAIN_SEARCH | |||
| 4082 | params["data"] = "mydomain.example.com, example.com"; | |||
| 4083 | params["csv-format"] = "true"; | |||
| 4084 | ||||
| 4085 | std::string config = createConfigWithOption(params); | |||
| 4086 | EXPECT_TRUE(executeConfiguration(config, "parse configuration with a"switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(executeConfiguration( config, "parse configuration with a" " domain-search option") )) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4087, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "executeConfiguration(config, \"parse configuration with a\" \" domain-search option\")" , "false", "true") .c_str()) = ::testing::Message() | |||
| 4087 | " domain-search option"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(executeConfiguration( config, "parse configuration with a" " domain-search option") )) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4087, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "executeConfiguration(config, \"parse configuration with a\" \" domain-search option\")" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 4088 | } | |||
| 4089 | ||||
| 4090 | // The goal of this test is to verify that the slp-directory-agent | |||
| 4091 | // option can be set using a trailing array of addresses and | |||
| 4092 | // slp-service-scope without option scope list | |||
| 4093 | TEST_F(Dhcp4ParserTest, slpOptions)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("slpOptions") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_slpOptions_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_slpOptions_Test() = default; ~Dhcp4ParserTest_slpOptions_Test () override = default; Dhcp4ParserTest_slpOptions_Test (const Dhcp4ParserTest_slpOptions_Test &) = delete; Dhcp4ParserTest_slpOptions_Test & operator=( const Dhcp4ParserTest_slpOptions_Test & ) = delete; Dhcp4ParserTest_slpOptions_Test (Dhcp4ParserTest_slpOptions_Test &&) noexcept = delete; Dhcp4ParserTest_slpOptions_Test & operator=( Dhcp4ParserTest_slpOptions_Test &&) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_slpOptions_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "slpOptions", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 4093 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4093), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4093), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_slpOptions_Test >); void Dhcp4ParserTest_slpOptions_Test::TestBody() { | |||
| 4094 | ConstElementPtr x; | |||
| 4095 | string config = "{ " + genIfaceConfig() + "," | |||
| 4096 | "\"rebind-timer\": 2000," | |||
| 4097 | "\"renew-timer\": 1000," | |||
| 4098 | "\"option-data\": [ {" | |||
| 4099 | " \"name\": \"slp-directory-agent\"," | |||
| 4100 | " \"data\": \"true, 10.0.0.3, 127.0.0.1\"" | |||
| 4101 | " }," | |||
| 4102 | " {" | |||
| 4103 | " \"name\": \"slp-service-scope\"," | |||
| 4104 | " \"data\": \"false, \"" | |||
| 4105 | " } ]," | |||
| 4106 | "\"subnet4\": [ { " | |||
| 4107 | " \"id\": 1," | |||
| 4108 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 4109 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 4110 | " } ]," | |||
| 4111 | "\"valid-lifetime\": 4000 }"; | |||
| 4112 | ||||
| 4113 | ConstElementPtr json; | |||
| 4114 | ASSERT_NO_THROW(json = parseDHCP4(config, true))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(config, 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_4114 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4114 ; } } else gtest_label_testnothrow_4114 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4114, ("Expected: " "json = parseDHCP4(config, true)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 4115 | extractConfig(config); | |||
| 4116 | ||||
| 4117 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4117; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4117; } } else gtest_label_testnothrow_4117 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4117, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4118 | checkResult(x, 0); | |||
| 4119 | ||||
| 4120 | // Get options | |||
| 4121 | OptionContainerPtr options = CfgMgr::instance().getStagingCfg()-> | |||
| 4122 | getCfgOption()->getAll(DHCP4_OPTION_SPACE"dhcp4"); | |||
| 4123 | ASSERT_EQ(2, options->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "options->size()" , 2, options->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4123, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4124 | ||||
| 4125 | // Get the search index. Index #1 is to search using option code. | |||
| 4126 | const OptionContainerTypeIndex& idx = options->get<1>(); | |||
| 4127 | ||||
| 4128 | // Get the options for specified index. Expecting one option to be | |||
| 4129 | // returned but in theory we may have multiple options with the same | |||
| 4130 | // code so we get the range. | |||
| 4131 | std::pair<OptionContainerTypeIndex::const_iterator, | |||
| 4132 | OptionContainerTypeIndex::const_iterator> range = | |||
| 4133 | idx.equal_range(DHO_DIRECTORY_AGENT); | |||
| 4134 | // Expect a single option with the code equal to 78. | |||
| 4135 | ASSERT_EQ(1, std::distance(range.first, range.second))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "std::distance(range.first, range.second)" , 1, std::distance(range.first, range.second)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4135, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4136 | const uint8_t sda_expected[] = { | |||
| 4137 | 0x01, 0x0a, 0x00, 0x00, 0x03, 0x7f, 0x00, 0x00, 0x01 | |||
| 4138 | }; | |||
| 4139 | // Check if option is valid in terms of code and carried data. | |||
| 4140 | testOption(*range.first, 78, sda_expected, sizeof(sda_expected)); | |||
| 4141 | ||||
| 4142 | range = idx.equal_range(DHO_SERVICE_SCOPE); | |||
| 4143 | ASSERT_EQ(1, std::distance(range.first, range.second))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "std::distance(range.first, range.second)" , 1, std::distance(range.first, range.second)))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4143, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4144 | // Do another round of testing with second option. | |||
| 4145 | const uint8_t sss_expected[] = { | |||
| 4146 | 0x00 | |||
| 4147 | }; | |||
| 4148 | testOption(*range.first, 79, sss_expected, sizeof(sss_expected)); | |||
| 4149 | } | |||
| 4150 | ||||
| 4151 | // The goal of this test is to verify that the standard option can | |||
| 4152 | // be configured to encapsulate multiple other options. | |||
| 4153 | TEST_F(Dhcp4ParserTest, stdOptionDataEncapsulate)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("stdOptionDataEncapsulate") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_stdOptionDataEncapsulate_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_stdOptionDataEncapsulate_Test () = default; ~Dhcp4ParserTest_stdOptionDataEncapsulate_Test( ) override = default; Dhcp4ParserTest_stdOptionDataEncapsulate_Test (const Dhcp4ParserTest_stdOptionDataEncapsulate_Test &) = delete; Dhcp4ParserTest_stdOptionDataEncapsulate_Test & operator =( const Dhcp4ParserTest_stdOptionDataEncapsulate_Test &) = delete; Dhcp4ParserTest_stdOptionDataEncapsulate_Test (Dhcp4ParserTest_stdOptionDataEncapsulate_Test &&) noexcept = delete; Dhcp4ParserTest_stdOptionDataEncapsulate_Test & operator=( Dhcp4ParserTest_stdOptionDataEncapsulate_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_stdOptionDataEncapsulate_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "stdOptionDataEncapsulate", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4153), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4153), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4153), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_stdOptionDataEncapsulate_Test >); void Dhcp4ParserTest_stdOptionDataEncapsulate_Test::TestBody () { | |||
| 4154 | ||||
| 4155 | // The configuration is two stage process in this test. | |||
| 4156 | // In the first stage we create definitions of suboptions | |||
| 4157 | // that we will add to the base option. | |||
| 4158 | // Let's create some dummy options: foo and foo2. | |||
| 4159 | string config = "{ " + genIfaceConfig() + "," | |||
| 4160 | "\"valid-lifetime\": 4000," | |||
| 4161 | "\"rebind-timer\": 2000," | |||
| 4162 | "\"renew-timer\": 1000," | |||
| 4163 | "\"option-data\": [ {" | |||
| 4164 | " \"name\": \"foo\"," | |||
| 4165 | " \"space\": \"vendor-encapsulated-options-space\"," | |||
| 4166 | " \"data\": \"1234\"" | |||
| 4167 | " }," | |||
| 4168 | " {" | |||
| 4169 | " \"name\": \"foo2\"," | |||
| 4170 | " \"space\": \"vendor-encapsulated-options-space\"," | |||
| 4171 | " \"data\": \"192.168.2.1\"" | |||
| 4172 | " } ]," | |||
| 4173 | "\"option-def\": [ {" | |||
| 4174 | " \"name\": \"foo\"," | |||
| 4175 | " \"code\": 1," | |||
| 4176 | " \"type\": \"uint32\"," | |||
| 4177 | " \"space\": \"vendor-encapsulated-options-space\"" | |||
| 4178 | " }," | |||
| 4179 | " {" | |||
| 4180 | " \"name\": \"foo2\"," | |||
| 4181 | " \"code\": 2," | |||
| 4182 | " \"type\": \"ipv4-address\"," | |||
| 4183 | " \"space\": \"vendor-encapsulated-options-space\"" | |||
| 4184 | " } ]" | |||
| 4185 | "}"; | |||
| 4186 | ||||
| 4187 | ConstElementPtr json; | |||
| 4188 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_4188 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4188 ; } } else gtest_label_testnothrow_4188 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4188, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 4189 | extractConfig(config); | |||
| 4190 | ||||
| 4191 | ConstElementPtr status; | |||
| 4192 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4192; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4192; } } else gtest_label_testnothrow_4192 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4192, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4193 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4193, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4194 | checkResult(status, 0); | |||
| 4195 | ||||
| 4196 | CfgMgr::instance().clear(); | |||
| 4197 | ||||
| 4198 | // Once the definitions have been added we can configure the | |||
| 4199 | // standard option #43. This option comprises an enterprise | |||
| 4200 | // number and sub options. By convention (introduced in | |||
| 4201 | // std_option_defs.h) option named 'vendor-encapsulated-options' | |||
| 4202 | // encapsulates the option space named 'vendor-encapsulated-options-space'. | |||
| 4203 | // We add our dummy options to this option space and thus | |||
| 4204 | // they should be included as sub-options in the | |||
| 4205 | // 'vendor-encapsulated-options' option. | |||
| 4206 | config = "{ " + genIfaceConfig() + "," | |||
| 4207 | "\"valid-lifetime\": 3000," | |||
| 4208 | "\"rebind-timer\": 2000," | |||
| 4209 | "\"renew-timer\": 1000," | |||
| 4210 | "\"option-data\": [ {" | |||
| 4211 | " \"name\": \"vendor-encapsulated-options\"," | |||
| 4212 | " \"csv-format\": false" | |||
| 4213 | " }," | |||
| 4214 | " {" | |||
| 4215 | " \"name\": \"foo\"," | |||
| 4216 | " \"space\": \"vendor-encapsulated-options-space\"," | |||
| 4217 | " \"data\": \"1234\"" | |||
| 4218 | " }," | |||
| 4219 | " {" | |||
| 4220 | " \"name\": \"foo2\"," | |||
| 4221 | " \"space\": \"vendor-encapsulated-options-space\"," | |||
| 4222 | " \"code\": 2," | |||
| 4223 | " \"data\": \"192.168.2.1\"," | |||
| 4224 | " \"csv-format\": true" | |||
| 4225 | " } ]," | |||
| 4226 | "\"option-def\": [ {" | |||
| 4227 | " \"name\": \"foo\"," | |||
| 4228 | " \"code\": 1," | |||
| 4229 | " \"type\": \"uint32\"," | |||
| 4230 | " \"space\": \"vendor-encapsulated-options-space\"" | |||
| 4231 | " }," | |||
| 4232 | " {" | |||
| 4233 | " \"name\": \"foo2\"," | |||
| 4234 | " \"code\": 2," | |||
| 4235 | " \"type\": \"ipv4-address\"," | |||
| 4236 | " \"space\": \"vendor-encapsulated-options-space\"" | |||
| 4237 | " } ]," | |||
| 4238 | "\"subnet4\": [ { " | |||
| 4239 | " \"id\": 1," | |||
| 4240 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 4241 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 4242 | " } ]" | |||
| 4243 | "}"; | |||
| 4244 | ||||
| 4245 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_4245 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4245 ; } } else gtest_label_testnothrow_4245 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4245, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 4246 | extractConfig(config); | |||
| 4247 | ||||
| 4248 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4248; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4248; } } else gtest_label_testnothrow_4248 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4248, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4249 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4249, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4250 | checkResult(status, 0); | |||
| 4251 | ||||
| 4252 | // We should have one option available. | |||
| 4253 | OptionContainerPtr options = | |||
| 4254 | CfgMgr::instance().getStagingCfg()->getCfgOption()->getAll(DHCP4_OPTION_SPACE"dhcp4"); | |||
| 4255 | ASSERT_TRUE(options)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(options)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4255, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "options", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 4256 | ASSERT_EQ(1, options->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "options->size()" , 1, options->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4256, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4257 | ||||
| 4258 | // Get the option. | |||
| 4259 | OptionDescriptor desc = CfgMgr::instance().getStagingCfg()-> | |||
| 4260 | getCfgOption()->get(DHCP4_OPTION_SPACE"dhcp4", DHO_VENDOR_ENCAPSULATED_OPTIONS); | |||
| 4261 | EXPECT_TRUE(desc.option_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(desc.option_)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4261, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "desc.option_", "false", "true") .c_str()) = ::testing::Message (); | |||
| 4262 | EXPECT_EQ(DHO_VENDOR_ENCAPSULATED_OPTIONS, desc.option_->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("DHO_VENDOR_ENCAPSULATED_OPTIONS" , "desc.option_->getType()", DHO_VENDOR_ENCAPSULATED_OPTIONS , desc.option_->getType()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4262, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4263 | ||||
| 4264 | // Option with the code 1 should be added as a sub-option. | |||
| 4265 | OptionPtr option_foo = desc.option_->getOption(1); | |||
| 4266 | ASSERT_TRUE(option_foo)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(option_foo)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4266, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "option_foo", "false", "true") .c_str()) = ::testing::Message (); | |||
| 4267 | EXPECT_EQ(1, option_foo->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "option_foo->getType()" , 1, option_foo->getType()))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4267, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4268 | // This option comprises a single uint32_t value thus it is | |||
| 4269 | // represented by OptionInt<uint32_t> class. Let's get the | |||
| 4270 | // object of this type. | |||
| 4271 | boost::shared_ptr<OptionInt<uint32_t> > option_foo_uint32 = | |||
| 4272 | boost::dynamic_pointer_cast<OptionInt<uint32_t> >(option_foo); | |||
| 4273 | ASSERT_TRUE(option_foo_uint32)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(option_foo_uint32)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4273, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "option_foo_uint32", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 4274 | // Validate the value according to the configuration. | |||
| 4275 | EXPECT_EQ(1234, option_foo_uint32->getValue())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1234", "option_foo_uint32->getValue()" , 1234, option_foo_uint32->getValue()))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 4275 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4276 | ||||
| 4277 | // Option with the code 2 should be added as a sub-option. | |||
| 4278 | OptionPtr option_foo2 = desc.option_->getOption(2); | |||
| 4279 | ASSERT_TRUE(option_foo2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(option_foo2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4279, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "option_foo2", "false", "true") .c_str()) = ::testing::Message (); | |||
| 4280 | EXPECT_EQ(2, option_foo2->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "option_foo2->getType()" , 2, option_foo2->getType()))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4280, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4281 | // This option comprises the IPV4 address. Such option is | |||
| 4282 | // represented by OptionCustom object. | |||
| 4283 | OptionCustomPtr option_foo2_v4 = | |||
| 4284 | boost::dynamic_pointer_cast<OptionCustom>(option_foo2); | |||
| 4285 | ASSERT_TRUE(option_foo2_v4)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(option_foo2_v4)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4285, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "option_foo2_v4", "false", "true") .c_str()) = ::testing::Message (); | |||
| 4286 | // Get the IP address carried by this option and validate it. | |||
| 4287 | EXPECT_EQ("192.168.2.1", option_foo2_v4->readAddress().toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.168.2.1\"" , "option_foo2_v4->readAddress().toText()", "192.168.2.1", option_foo2_v4->readAddress().toText()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 4287 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4288 | ||||
| 4289 | // Option with the code 3 should not be added. | |||
| 4290 | EXPECT_FALSE(desc.option_->getOption(3))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(desc.option_->getOption (3)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4290, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "desc.option_->getOption(3)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4291 | } | |||
| 4292 | ||||
| 4293 | // This test checks if vendor options can be specified in the config file | |||
| 4294 | // (in hex format), and later retrieved from configured subnet | |||
| 4295 | TEST_F(Dhcp4ParserTest, vendorOptionsHex)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("vendorOptionsHex") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_vendorOptionsHex_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_vendorOptionsHex_Test() = default; ~Dhcp4ParserTest_vendorOptionsHex_Test() override = default; Dhcp4ParserTest_vendorOptionsHex_Test (const Dhcp4ParserTest_vendorOptionsHex_Test &) = delete; Dhcp4ParserTest_vendorOptionsHex_Test & operator=( const Dhcp4ParserTest_vendorOptionsHex_Test & ) = delete; Dhcp4ParserTest_vendorOptionsHex_Test (Dhcp4ParserTest_vendorOptionsHex_Test &&) noexcept = delete; Dhcp4ParserTest_vendorOptionsHex_Test & operator=( Dhcp4ParserTest_vendorOptionsHex_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_vendorOptionsHex_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "vendorOptionsHex", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4295), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4295), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4295), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_vendorOptionsHex_Test >); void Dhcp4ParserTest_vendorOptionsHex_Test::TestBody() { | |||
| 4296 | ||||
| 4297 | // This configuration string is to configure two options | |||
| 4298 | // sharing the code 1 and belonging to the different vendor spaces. | |||
| 4299 | // (different vendor-id values). | |||
| 4300 | string config = "{ " + genIfaceConfig() + "," | |||
| 4301 | "\"valid-lifetime\": 4000," | |||
| 4302 | "\"rebind-timer\": 2000," | |||
| 4303 | "\"renew-timer\": 1000," | |||
| 4304 | "\"option-data\": [ {" | |||
| 4305 | " \"name\": \"option-one\"," | |||
| 4306 | " \"space\": \"vendor-4491\"," // VENDOR_ID_CABLE_LABS = 4491 | |||
| 4307 | " \"code\": 100," // just a random code | |||
| 4308 | " \"data\": \"ABCDEF0105\"," | |||
| 4309 | " \"csv-format\": false" | |||
| 4310 | " }," | |||
| 4311 | " {" | |||
| 4312 | " \"name\": \"option-two\"," | |||
| 4313 | " \"space\": \"vendor-1234\"," | |||
| 4314 | " \"code\": 100," | |||
| 4315 | " \"data\": \"1234\"," | |||
| 4316 | " \"csv-format\": false" | |||
| 4317 | " } ]," | |||
| 4318 | "\"subnet4\": [ { " | |||
| 4319 | " \"id\": 1," | |||
| 4320 | " \"pools\": [ { \"pool\": \"192.0.2.1-192.0.2.10\" } ]," | |||
| 4321 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 4322 | " } ]" | |||
| 4323 | "}"; | |||
| 4324 | ||||
| 4325 | ConstElementPtr json; | |||
| 4326 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_4326 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4326 ; } } else gtest_label_testnothrow_4326 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4326, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 4327 | extractConfig(config); | |||
| 4328 | ||||
| 4329 | ConstElementPtr status; | |||
| 4330 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4330; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4330; } } else gtest_label_testnothrow_4330 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4330, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4331 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4331, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4332 | checkResult(status, 0); | |||
| 4333 | ||||
| 4334 | // Options should be now available | |||
| 4335 | // Try to get the option from the vendor space 4491 | |||
| 4336 | OptionDescriptor desc1 = CfgMgr::instance().getStagingCfg()-> | |||
| 4337 | getCfgOption()->get(VENDOR_ID_CABLE_LABS4491, 100); | |||
| 4338 | ASSERT_TRUE(desc1.option_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(desc1.option_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4338, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "desc1.option_", "false", "true") .c_str()) = ::testing::Message (); | |||
| 4339 | EXPECT_EQ(100, desc1.option_->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("100", "desc1.option_->getType()" , 100, desc1.option_->getType()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4339, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4340 | // Try to get the option from the vendor space 1234 | |||
| 4341 | OptionDescriptor desc2 = | |||
| 4342 | CfgMgr::instance().getStagingCfg()->getCfgOption()->get(1234, 100); | |||
| 4343 | ASSERT_TRUE(desc2.option_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(desc2.option_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4343, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "desc2.option_", "false", "true") .c_str()) = ::testing::Message (); | |||
| 4344 | EXPECT_EQ(100, desc1.option_->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("100", "desc1.option_->getType()" , 100, desc1.option_->getType()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4344, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4345 | ||||
| 4346 | // Try to get the non-existing option from the non-existing | |||
| 4347 | // option space and expect that option is not returned. | |||
| 4348 | OptionDescriptor desc3 = | |||
| 4349 | CfgMgr::instance().getStagingCfg()->getCfgOption()->get(5678, 100); | |||
| 4350 | ASSERT_FALSE(desc3.option_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(desc3.option_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4350, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "desc3.option_", "true", "false") .c_str()) = ::testing::Message (); | |||
| 4351 | } | |||
| 4352 | ||||
| 4353 | // This test checks if vendor options can be specified in the config file, | |||
| 4354 | // (in csv format), and later retrieved from configured subnet | |||
| 4355 | TEST_F(Dhcp4ParserTest, vendorOptionsCsv)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("vendorOptionsCsv") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_vendorOptionsCsv_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_vendorOptionsCsv_Test() = default; ~Dhcp4ParserTest_vendorOptionsCsv_Test() override = default; Dhcp4ParserTest_vendorOptionsCsv_Test (const Dhcp4ParserTest_vendorOptionsCsv_Test &) = delete; Dhcp4ParserTest_vendorOptionsCsv_Test & operator=( const Dhcp4ParserTest_vendorOptionsCsv_Test & ) = delete; Dhcp4ParserTest_vendorOptionsCsv_Test (Dhcp4ParserTest_vendorOptionsCsv_Test &&) noexcept = delete; Dhcp4ParserTest_vendorOptionsCsv_Test & operator=( Dhcp4ParserTest_vendorOptionsCsv_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_vendorOptionsCsv_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "vendorOptionsCsv", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4355), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4355), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4355), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_vendorOptionsCsv_Test >); void Dhcp4ParserTest_vendorOptionsCsv_Test::TestBody() { | |||
| 4356 | ||||
| 4357 | // This configuration string is to configure two options | |||
| 4358 | // sharing the code 1 and belonging to the different vendor spaces. | |||
| 4359 | // (different vendor-id values). | |||
| 4360 | string config = "{ " + genIfaceConfig() + "," | |||
| 4361 | "\"valid-lifetime\": 4000," | |||
| 4362 | "\"rebind-timer\": 2000," | |||
| 4363 | "\"renew-timer\": 1000," | |||
| 4364 | "\"option-data\": [ {" | |||
| 4365 | " \"name\": \"foo\"," | |||
| 4366 | " \"space\": \"vendor-4491\"," | |||
| 4367 | " \"code\": 100," | |||
| 4368 | " \"data\": \"this is a string vendor-opt\"" | |||
| 4369 | " } ]," | |||
| 4370 | "\"option-def\": [ {" | |||
| 4371 | " \"name\": \"foo\"," | |||
| 4372 | " \"code\": 100," | |||
| 4373 | " \"type\": \"string\"," | |||
| 4374 | " \"space\": \"vendor-4491\"" | |||
| 4375 | " } ]," | |||
| 4376 | "\"subnet4\": [ { " | |||
| 4377 | " \"id\": 1," | |||
| 4378 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 4379 | " \"subnet\": \"192.0.2.0/24\" " | |||
| 4380 | " } ]" | |||
| 4381 | "}"; | |||
| 4382 | ||||
| 4383 | ConstElementPtr status; | |||
| 4384 | ||||
| 4385 | ConstElementPtr json; | |||
| 4386 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_4386 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4386 ; } } else gtest_label_testnothrow_4386 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4386, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 4387 | extractConfig(config); | |||
| 4388 | ||||
| 4389 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4389; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4389; } } else gtest_label_testnothrow_4389 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4389, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4390 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4390, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4391 | checkResult(status, 0); | |||
| 4392 | ||||
| 4393 | // Options should be now available. | |||
| 4394 | // Try to get the option from the vendor space 4491 | |||
| 4395 | OptionDescriptor desc1 = CfgMgr::instance().getStagingCfg()-> | |||
| 4396 | getCfgOption()->get(VENDOR_ID_CABLE_LABS4491, 100); | |||
| 4397 | ASSERT_TRUE(desc1.option_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(desc1.option_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4397, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "desc1.option_", "false", "true") .c_str()) = ::testing::Message (); | |||
| 4398 | EXPECT_EQ(100, desc1.option_->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("100", "desc1.option_->getType()" , 100, desc1.option_->getType()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4398, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4399 | ||||
| 4400 | // Try to get the non-existing option from the non-existing | |||
| 4401 | // option space and expect that option is not returned. | |||
| 4402 | OptionDescriptor desc2 = | |||
| 4403 | CfgMgr::instance().getStagingCfg()->getCfgOption()->get(5678, 100); | |||
| 4404 | ASSERT_FALSE(desc2.option_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(desc2.option_))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4404, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "desc2.option_", "true", "false") .c_str()) = ::testing::Message (); | |||
| 4405 | } | |||
| 4406 | ||||
| 4407 | // Tests of the hooks libraries configuration. All tests have the pre- | |||
| 4408 | // condition (checked in the test fixture's SetUp() method) that no hooks | |||
| 4409 | // libraries are loaded at the start of the tests. | |||
| 4410 | ||||
| 4411 | // Helper function to return a configuration containing an arbitrary number | |||
| 4412 | // of hooks libraries. | |||
| 4413 | std::string | |||
| 4414 | buildHooksLibrariesConfig(const std::vector<std::string>& libraries = {}, | |||
| 4415 | bool multi_threading = true) { | |||
| 4416 | const string lbrace("{"); | |||
| 4417 | const string rbrace("}"); | |||
| 4418 | const string liblabel("\"library\": "); | |||
| 4419 | const string quote("\""); | |||
| 4420 | ||||
| 4421 | // Create the first part of the configuration string. | |||
| 4422 | string config = | |||
| 4423 | "{ \"interfaces-config\": { \"interfaces\": [] }," | |||
| 4424 | "\"hooks-libraries\": ["; | |||
| 4425 | ||||
| 4426 | // Append the libraries (separated by commas if needed) | |||
| 4427 | for (unsigned int i = 0; i < libraries.size(); ++i) { | |||
| 4428 | if (i > 0) { | |||
| 4429 | config += string(", "); | |||
| 4430 | } | |||
| 4431 | config += (lbrace + liblabel + quote + libraries[i] + quote + rbrace); | |||
| 4432 | } | |||
| 4433 | ||||
| 4434 | // Append the remainder of the configuration. | |||
| 4435 | config += string( | |||
| 4436 | "]," | |||
| 4437 | "\"valid-lifetime\": 4000," | |||
| 4438 | "\"rebind-timer\": 2000," | |||
| 4439 | "\"renew-timer\": 1000," | |||
| 4440 | "\"option-data\": [ {" | |||
| 4441 | " \"name\": \"dhcp-message\"," | |||
| 4442 | " \"data\": \"ABCDEF0105\"," | |||
| 4443 | " \"csv-format\": false" | |||
| 4444 | " }," | |||
| 4445 | " {" | |||
| 4446 | " \"name\": \"foo\"," | |||
| 4447 | " \"space\": \"isc\"," | |||
| 4448 | " \"data\": \"1234\"" | |||
| 4449 | " } ]," | |||
| 4450 | "\"option-def\": [ {" | |||
| 4451 | " \"name\": \"foo\"," | |||
| 4452 | " \"code\": 56," | |||
| 4453 | " \"type\": \"uint32\"," | |||
| 4454 | " \"space\": \"isc\"" | |||
| 4455 | " } ]," | |||
| 4456 | "\"subnet4\": [ { " | |||
| 4457 | " \"id\": 1," | |||
| 4458 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 4459 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 4460 | " } ]"); | |||
| 4461 | ||||
| 4462 | config += R"(, | |||
| 4463 | "multi-threading": { | |||
| 4464 | "enable-multi-threading": )" + | |||
| 4465 | string(multi_threading ? "true" : "false") + R"( | |||
| 4466 | })"; | |||
| 4467 | ||||
| 4468 | config += string("}"); | |||
| 4469 | ||||
| 4470 | return (config); | |||
| 4471 | } | |||
| 4472 | ||||
| 4473 | // The goal of this test is to verify the configuration of hooks libraries if | |||
| 4474 | // none are specified. | |||
| 4475 | TEST_F(Dhcp4ParserTest, NoHooksLibraries)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("NoHooksLibraries") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_NoHooksLibraries_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_NoHooksLibraries_Test() = default; ~Dhcp4ParserTest_NoHooksLibraries_Test() override = default; Dhcp4ParserTest_NoHooksLibraries_Test (const Dhcp4ParserTest_NoHooksLibraries_Test &) = delete; Dhcp4ParserTest_NoHooksLibraries_Test & operator=( const Dhcp4ParserTest_NoHooksLibraries_Test & ) = delete; Dhcp4ParserTest_NoHooksLibraries_Test (Dhcp4ParserTest_NoHooksLibraries_Test &&) noexcept = delete; Dhcp4ParserTest_NoHooksLibraries_Test & operator=( Dhcp4ParserTest_NoHooksLibraries_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_NoHooksLibraries_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "NoHooksLibraries", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4475), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4475), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4475), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_NoHooksLibraries_Test >); void Dhcp4ParserTest_NoHooksLibraries_Test::TestBody() { | |||
| 4476 | // Parse a configuration containing no names. | |||
| 4477 | string config = buildHooksLibrariesConfig(); | |||
| 4478 | if (!executeConfiguration(config, | |||
| 4479 | "set configuration with no hooks libraries")) { | |||
| 4480 | FAIL()return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4480, "Failed") = ::testing::Message() << "Unable to execute configuration"; | |||
| 4481 | ||||
| 4482 | } else { | |||
| 4483 | // No libraries should be loaded at the end of the test. | |||
| 4484 | std::vector<std::string> libraries = HooksManager::getLibraryNames(); | |||
| 4485 | EXPECT_TRUE(libraries.empty())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(libraries.empty())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4485, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "libraries.empty()", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 4486 | } | |||
| 4487 | } | |||
| 4488 | ||||
| 4489 | // Verify parsing fails with one library that will fail validation. | |||
| 4490 | TEST_F(Dhcp4ParserTest, InvalidLibrary)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("InvalidLibrary") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_InvalidLibrary_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_InvalidLibrary_Test() = default; ~ Dhcp4ParserTest_InvalidLibrary_Test() override = default; Dhcp4ParserTest_InvalidLibrary_Test (const Dhcp4ParserTest_InvalidLibrary_Test &) = delete; Dhcp4ParserTest_InvalidLibrary_Test & operator=( const Dhcp4ParserTest_InvalidLibrary_Test & ) = delete; Dhcp4ParserTest_InvalidLibrary_Test (Dhcp4ParserTest_InvalidLibrary_Test &&) noexcept = delete; Dhcp4ParserTest_InvalidLibrary_Test & operator=( Dhcp4ParserTest_InvalidLibrary_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_InvalidLibrary_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "InvalidLibrary", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 4490 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4490), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4490), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_InvalidLibrary_Test >); void Dhcp4ParserTest_InvalidLibrary_Test::TestBody() { | |||
| 4491 | // Parse a configuration containing a failing library. | |||
| 4492 | string config = buildHooksLibrariesConfig({NOT_PRESENT_LIBRARY}); | |||
| 4493 | ||||
| 4494 | ConstElementPtr json; | |||
| 4495 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_4495 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4495 ; } } else gtest_label_testnothrow_4495 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4495, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 4496 | ||||
| 4497 | ConstElementPtr status; | |||
| 4498 | ASSERT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4498; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4498; } } else gtest_label_testnothrow_4498 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4498, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4499 | ||||
| 4500 | // The status object must not be NULL | |||
| 4501 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4501, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4502 | ||||
| 4503 | // Returned value should not be 0 | |||
| 4504 | comment_ = parseAnswer(rcode_, status); | |||
| 4505 | EXPECT_NE(0, rcode_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("0", "rcode_", 0 , rcode_))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4505, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4506 | } | |||
| 4507 | ||||
| 4508 | // Verify the configuration of hooks libraries with two being specified. | |||
| 4509 | TEST_F(Dhcp4ParserTest, LibrariesSpecified)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("LibrariesSpecified") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_LibrariesSpecified_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_LibrariesSpecified_Test() = default ; ~Dhcp4ParserTest_LibrariesSpecified_Test() override = default ; Dhcp4ParserTest_LibrariesSpecified_Test (const Dhcp4ParserTest_LibrariesSpecified_Test &) = delete; Dhcp4ParserTest_LibrariesSpecified_Test & operator=( const Dhcp4ParserTest_LibrariesSpecified_Test & ) = delete; Dhcp4ParserTest_LibrariesSpecified_Test (Dhcp4ParserTest_LibrariesSpecified_Test &&) noexcept = delete; Dhcp4ParserTest_LibrariesSpecified_Test & operator=( Dhcp4ParserTest_LibrariesSpecified_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_LibrariesSpecified_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "LibrariesSpecified", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4509), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4509), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4509), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_LibrariesSpecified_Test >); void Dhcp4ParserTest_LibrariesSpecified_Test::TestBody () { | |||
| 4510 | setHooksTestPath(); | |||
| 4511 | ||||
| 4512 | // Marker files should not be present. | |||
| 4513 | EXPECT_FALSE(checkMarkerFileExists(LOAD_MARKER_FILE))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(checkMarkerFileExists (LOAD_MARKER_FILE)))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4513, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "checkMarkerFileExists(LOAD_MARKER_FILE)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4514 | EXPECT_FALSE(checkMarkerFileExists(UNLOAD_MARKER_FILE))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(checkMarkerFileExists (UNLOAD_MARKER_FILE)))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4514, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "checkMarkerFileExists(UNLOAD_MARKER_FILE)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4515 | ||||
| 4516 | // Set up the configuration with two libraries and load them. | |||
| 4517 | // Disable multi-threading since one of the libraries is single-threaded. | |||
| 4518 | string config = buildHooksLibrariesConfig({CALLOUT_LIBRARY_1, CALLOUT_LIBRARY_2}, | |||
| 4519 | /* multi_threading = */ false); | |||
| 4520 | ASSERT_TRUE(executeConfiguration(config,switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(executeConfiguration( config, "load two valid libraries"))) ; else return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 4521 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "executeConfiguration(config, \"load two valid libraries\")" , "false", "true") .c_str()) = ::testing::Message() | |||
| 4521 | "load two valid libraries"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(executeConfiguration( config, "load two valid libraries"))) ; else return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 4521 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "executeConfiguration(config, \"load two valid libraries\")" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 4522 | ||||
| 4523 | // Expect two libraries to be loaded in the correct order (load marker file | |||
| 4524 | // is present, no unload marker file). | |||
| 4525 | std::vector<std::string> libraries = HooksManager::getLibraryNames(); | |||
| 4526 | ASSERT_EQ(2, libraries.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "libraries.size()" , 2, libraries.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4526, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4527 | EXPECT_TRUE(checkMarkerFile(LOAD_MARKER_FILE, "12"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(checkMarkerFile(LOAD_MARKER_FILE , "12"))) ; else ::testing::internal::AssertHelper(::testing:: TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4527, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "checkMarkerFile(LOAD_MARKER_FILE, \"12\")", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 4528 | EXPECT_FALSE(checkMarkerFileExists(UNLOAD_MARKER_FILE))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(checkMarkerFileExists (UNLOAD_MARKER_FILE)))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4528, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "checkMarkerFileExists(UNLOAD_MARKER_FILE)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4529 | ||||
| 4530 | // Commit the changes so as we get the fresh configuration for the | |||
| 4531 | // second part of this test. | |||
| 4532 | CfgMgr::instance().commit(); | |||
| 4533 | ||||
| 4534 | // Unload the libraries. The load file should not have changed, but | |||
| 4535 | // the unload one should indicate the unload() functions have been run. | |||
| 4536 | config = buildHooksLibrariesConfig(); | |||
| 4537 | ASSERT_TRUE(executeConfiguration(config, "unloading libraries"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(executeConfiguration( config, "unloading libraries"))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4537, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "executeConfiguration(config, \"unloading libraries\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 4538 | EXPECT_TRUE(checkMarkerFile(LOAD_MARKER_FILE, "12"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(checkMarkerFile(LOAD_MARKER_FILE , "12"))) ; else ::testing::internal::AssertHelper(::testing:: TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4538, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "checkMarkerFile(LOAD_MARKER_FILE, \"12\")", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 4539 | EXPECT_TRUE(checkMarkerFile(UNLOAD_MARKER_FILE, "21"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(checkMarkerFile(UNLOAD_MARKER_FILE , "21"))) ; else ::testing::internal::AssertHelper(::testing:: TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4539, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "checkMarkerFile(UNLOAD_MARKER_FILE, \"21\")", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 4540 | ||||
| 4541 | // Expect the hooks system to say that none are loaded. | |||
| 4542 | libraries = HooksManager::getLibraryNames(); | |||
| 4543 | EXPECT_TRUE(libraries.empty())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(libraries.empty())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4543, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "libraries.empty()", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 4544 | } | |||
| 4545 | ||||
| 4546 | // Verify the configuration of hooks libraries which are not compatible with | |||
| 4547 | // multi threading is rejected. | |||
| 4548 | TEST_F(Dhcp4ParserTest, IncompatibleLibrary2Specified)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("IncompatibleLibrary2Specified") > 1, "test_name must not be empty"); class Dhcp4ParserTest_IncompatibleLibrary2Specified_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_IncompatibleLibrary2Specified_Test () = default; ~Dhcp4ParserTest_IncompatibleLibrary2Specified_Test () override = default; Dhcp4ParserTest_IncompatibleLibrary2Specified_Test (const Dhcp4ParserTest_IncompatibleLibrary2Specified_Test & ) = delete; Dhcp4ParserTest_IncompatibleLibrary2Specified_Test & operator=( const Dhcp4ParserTest_IncompatibleLibrary2Specified_Test &) = delete; Dhcp4ParserTest_IncompatibleLibrary2Specified_Test (Dhcp4ParserTest_IncompatibleLibrary2Specified_Test && ) noexcept = delete; Dhcp4ParserTest_IncompatibleLibrary2Specified_Test & operator=( Dhcp4ParserTest_IncompatibleLibrary2Specified_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_IncompatibleLibrary2Specified_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "IncompatibleLibrary2Specified", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4548), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4548), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4548), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_IncompatibleLibrary2Specified_Test >); void Dhcp4ParserTest_IncompatibleLibrary2Specified_Test ::TestBody() { | |||
| 4549 | // Marker files should not be present. | |||
| 4550 | EXPECT_FALSE(checkMarkerFileExists(LOAD_MARKER_FILE))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(checkMarkerFileExists (LOAD_MARKER_FILE)))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4550, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "checkMarkerFileExists(LOAD_MARKER_FILE)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4551 | EXPECT_FALSE(checkMarkerFileExists(UNLOAD_MARKER_FILE))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(checkMarkerFileExists (UNLOAD_MARKER_FILE)))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4551, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "checkMarkerFileExists(UNLOAD_MARKER_FILE)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4552 | ||||
| 4553 | std::vector<std::string> libraries; | |||
| 4554 | libraries.push_back(string(CALLOUT_LIBRARY_2)); | |||
| 4555 | ||||
| 4556 | // Set up the configuration with two libraries and load them. | |||
| 4557 | string config = buildHooksLibrariesConfig(libraries, true); | |||
| 4558 | ConstElementPtr json; | |||
| 4559 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_4559 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4559 ; } } else gtest_label_testnothrow_4559 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4559, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 4560 | ConstElementPtr status; | |||
| 4561 | ASSERT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4561; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4561; } } else gtest_label_testnothrow_4561 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4561, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4562 | ||||
| 4563 | // The status object must not be NULL | |||
| 4564 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4564, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4565 | ||||
| 4566 | // Returned value should not be 0 | |||
| 4567 | comment_ = parseAnswer(rcode_, status); | |||
| 4568 | EXPECT_NE(0, rcode_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("0", "rcode_", 0 , rcode_))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4568, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4569 | ||||
| 4570 | // Expect the library to be rejected by the server (no load marker file, no | |||
| 4571 | // unload marker file). | |||
| 4572 | EXPECT_FALSE(checkMarkerFileExists(LOAD_MARKER_FILE))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(checkMarkerFileExists (LOAD_MARKER_FILE)))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4572, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "checkMarkerFileExists(LOAD_MARKER_FILE)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4573 | EXPECT_FALSE(checkMarkerFileExists(UNLOAD_MARKER_FILE))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(checkMarkerFileExists (UNLOAD_MARKER_FILE)))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4573, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "checkMarkerFileExists(UNLOAD_MARKER_FILE)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4574 | ||||
| 4575 | // Expect the hooks system to say that none are loaded. | |||
| 4576 | libraries = HooksManager::getLibraryNames(); | |||
| 4577 | EXPECT_TRUE(libraries.empty())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(libraries.empty())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4577, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "libraries.empty()", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 4578 | } | |||
| 4579 | ||||
| 4580 | // Verify the configuration of hooks libraries which are not compatible with | |||
| 4581 | // multi threading is rejected. | |||
| 4582 | TEST_F(Dhcp4ParserTest, IncompatibleLibrary3Specified)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("IncompatibleLibrary3Specified") > 1, "test_name must not be empty"); class Dhcp4ParserTest_IncompatibleLibrary3Specified_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_IncompatibleLibrary3Specified_Test () = default; ~Dhcp4ParserTest_IncompatibleLibrary3Specified_Test () override = default; Dhcp4ParserTest_IncompatibleLibrary3Specified_Test (const Dhcp4ParserTest_IncompatibleLibrary3Specified_Test & ) = delete; Dhcp4ParserTest_IncompatibleLibrary3Specified_Test & operator=( const Dhcp4ParserTest_IncompatibleLibrary3Specified_Test &) = delete; Dhcp4ParserTest_IncompatibleLibrary3Specified_Test (Dhcp4ParserTest_IncompatibleLibrary3Specified_Test && ) noexcept = delete; Dhcp4ParserTest_IncompatibleLibrary3Specified_Test & operator=( Dhcp4ParserTest_IncompatibleLibrary3Specified_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_IncompatibleLibrary3Specified_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "IncompatibleLibrary3Specified", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4582), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4582), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4582), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_IncompatibleLibrary3Specified_Test >); void Dhcp4ParserTest_IncompatibleLibrary3Specified_Test ::TestBody() { | |||
| 4583 | // Marker files should not be present. | |||
| 4584 | EXPECT_FALSE(checkMarkerFileExists(LOAD_MARKER_FILE))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(checkMarkerFileExists (LOAD_MARKER_FILE)))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4584, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "checkMarkerFileExists(LOAD_MARKER_FILE)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4585 | EXPECT_FALSE(checkMarkerFileExists(UNLOAD_MARKER_FILE))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(checkMarkerFileExists (UNLOAD_MARKER_FILE)))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4585, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "checkMarkerFileExists(UNLOAD_MARKER_FILE)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4586 | ||||
| 4587 | std::vector<std::string> libraries; | |||
| 4588 | libraries.push_back(string(CALLOUT_LIBRARY_3)); | |||
| 4589 | ||||
| 4590 | // Set up the configuration with two libraries and load them. | |||
| 4591 | string config = buildHooksLibrariesConfig(libraries, true); | |||
| 4592 | ConstElementPtr json; | |||
| 4593 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_4593 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4593 ; } } else gtest_label_testnothrow_4593 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4593, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 4594 | ConstElementPtr status; | |||
| 4595 | ASSERT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4595; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4595; } } else gtest_label_testnothrow_4595 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4595, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4596 | ||||
| 4597 | // The status object must not be NULL | |||
| 4598 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4598, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4599 | ||||
| 4600 | // Returned value should not be 0 | |||
| 4601 | comment_ = parseAnswer(rcode_, status); | |||
| 4602 | EXPECT_NE(0, rcode_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("0", "rcode_", 0 , rcode_))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4602, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4603 | ||||
| 4604 | // Expect the library to be rejected by the server (no load marker file, no | |||
| 4605 | // unload marker file). | |||
| 4606 | EXPECT_FALSE(checkMarkerFileExists(LOAD_MARKER_FILE))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(checkMarkerFileExists (LOAD_MARKER_FILE)))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4606, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "checkMarkerFileExists(LOAD_MARKER_FILE)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4607 | EXPECT_FALSE(checkMarkerFileExists(UNLOAD_MARKER_FILE))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(checkMarkerFileExists (UNLOAD_MARKER_FILE)))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4607, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "checkMarkerFileExists(UNLOAD_MARKER_FILE)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4608 | ||||
| 4609 | // Expect the hooks system to say that none are loaded. | |||
| 4610 | libraries = HooksManager::getLibraryNames(); | |||
| 4611 | EXPECT_TRUE(libraries.empty())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(libraries.empty())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4611, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "libraries.empty()", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 4612 | } | |||
| 4613 | ||||
| 4614 | // This test verifies that it is possible to select subset of interfaces | |||
| 4615 | // on which server should listen. | |||
| 4616 | TEST_F(Dhcp4ParserTest, selectedInterfaces)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("selectedInterfaces") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_selectedInterfaces_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_selectedInterfaces_Test() = default ; ~Dhcp4ParserTest_selectedInterfaces_Test() override = default ; Dhcp4ParserTest_selectedInterfaces_Test (const Dhcp4ParserTest_selectedInterfaces_Test &) = delete; Dhcp4ParserTest_selectedInterfaces_Test & operator=( const Dhcp4ParserTest_selectedInterfaces_Test & ) = delete; Dhcp4ParserTest_selectedInterfaces_Test (Dhcp4ParserTest_selectedInterfaces_Test &&) noexcept = delete; Dhcp4ParserTest_selectedInterfaces_Test & operator=( Dhcp4ParserTest_selectedInterfaces_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_selectedInterfaces_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "selectedInterfaces", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4616), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4616), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4616), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_selectedInterfaces_Test >); void Dhcp4ParserTest_selectedInterfaces_Test::TestBody () { | |||
| 4617 | IfaceMgrTestConfig test_config(true); | |||
| 4618 | ||||
| 4619 | // Make sure the config manager is clean and there is no hanging | |||
| 4620 | // interface configuration. | |||
| 4621 | ASSERT_FALSE(test_config.socketOpen("eth0", AF_INET))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(test_config.socketOpen ("eth0", 2)))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4621, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "test_config.socketOpen(\"eth0\", 2)", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 4622 | ASSERT_FALSE(test_config.socketOpen("eth1", AF_INET))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(test_config.socketOpen ("eth1", 2)))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4622, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "test_config.socketOpen(\"eth1\", 2)", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 4623 | ||||
| 4624 | string config = "{ \"interfaces-config\": {" | |||
| 4625 | " \"interfaces\": [ \"eth0\", \"eth1\" ]" | |||
| 4626 | "}," | |||
| 4627 | "\"rebind-timer\": 2000, " | |||
| 4628 | "\"renew-timer\": 1000, " | |||
| 4629 | "\"valid-lifetime\": 4000 }"; | |||
| 4630 | ||||
| 4631 | ConstElementPtr json; | |||
| 4632 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_4632 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4632 ; } } else gtest_label_testnothrow_4632 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4632, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 4633 | extractConfig(config); | |||
| 4634 | ||||
| 4635 | ConstElementPtr status; | |||
| 4636 | // Apply configuration. | |||
| 4637 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4637; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4637; } } else gtest_label_testnothrow_4637 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4637, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4638 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4638, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4639 | // returned value must be 0 (configuration accepted) | |||
| 4640 | checkResult(status, 0); | |||
| 4641 | ||||
| 4642 | CfgMgr::instance().getStagingCfg()->getCfgIface()->openSockets(AF_INET2, 10000); | |||
| 4643 | ||||
| 4644 | // eth0 and eth1 were explicitly selected. eth2 was not. | |||
| 4645 | EXPECT_TRUE(test_config.socketOpen("eth0", AF_INET))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(test_config.socketOpen ("eth0", 2))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4645, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "test_config.socketOpen(\"eth0\", 2)", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 4646 | EXPECT_TRUE(test_config.socketOpen("eth1", AF_INET))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(test_config.socketOpen ("eth1", 2))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4646, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "test_config.socketOpen(\"eth1\", 2)", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 4647 | } | |||
| 4648 | ||||
| 4649 | // This test verifies that it is possible to configure the server in such a way | |||
| 4650 | // that it listens on all interfaces. | |||
| 4651 | TEST_F(Dhcp4ParserTest, allInterfaces)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("allInterfaces") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_allInterfaces_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_allInterfaces_Test() = default; ~Dhcp4ParserTest_allInterfaces_Test () override = default; Dhcp4ParserTest_allInterfaces_Test (const Dhcp4ParserTest_allInterfaces_Test &) = delete; Dhcp4ParserTest_allInterfaces_Test & operator=( const Dhcp4ParserTest_allInterfaces_Test & ) = delete; Dhcp4ParserTest_allInterfaces_Test (Dhcp4ParserTest_allInterfaces_Test &&) noexcept = delete; Dhcp4ParserTest_allInterfaces_Test & operator=( Dhcp4ParserTest_allInterfaces_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_allInterfaces_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "allInterfaces", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 4651 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4651), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4651), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_allInterfaces_Test >); void Dhcp4ParserTest_allInterfaces_Test::TestBody() { | |||
| 4652 | IfaceMgrTestConfig test_config(true); | |||
| 4653 | ||||
| 4654 | // Make sure there is no old configuration. | |||
| 4655 | ASSERT_FALSE(test_config.socketOpen("eth0", AF_INET))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(test_config.socketOpen ("eth0", 2)))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4655, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "test_config.socketOpen(\"eth0\", 2)", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 4656 | ASSERT_FALSE(test_config.socketOpen("eth1", AF_INET))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(test_config.socketOpen ("eth1", 2)))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4656, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "test_config.socketOpen(\"eth1\", 2)", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 4657 | ||||
| 4658 | // This configuration specifies two interfaces on which server should listen | |||
| 4659 | // but it also includes asterisk. The asterisk switches server into the | |||
| 4660 | // mode when it listens on all interfaces regardless of what interface names | |||
| 4661 | // were specified in the "interfaces" parameter. | |||
| 4662 | string config = "{ \"interfaces-config\": {" | |||
| 4663 | " \"interfaces\": [ \"eth0\", \"*\", \"eth1\" ]" | |||
| 4664 | "}," | |||
| 4665 | "\"rebind-timer\": 2000, " | |||
| 4666 | "\"renew-timer\": 1000, " | |||
| 4667 | "\"valid-lifetime\": 4000 }"; | |||
| 4668 | ||||
| 4669 | ConstElementPtr json; | |||
| 4670 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_4670 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4670 ; } } else gtest_label_testnothrow_4670 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4670, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 4671 | extractConfig(config); | |||
| 4672 | ||||
| 4673 | ConstElementPtr status; | |||
| 4674 | ||||
| 4675 | // Apply configuration. | |||
| 4676 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4676; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4676; } } else gtest_label_testnothrow_4676 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4676, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4677 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4677, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4678 | checkResult(status, 0); | |||
| 4679 | ||||
| 4680 | CfgMgr::instance().getStagingCfg()->getCfgIface()->openSockets(AF_INET2, 10000); | |||
| 4681 | ||||
| 4682 | // All interfaces should be now active. | |||
| 4683 | ASSERT_TRUE(test_config.socketOpen("eth0", AF_INET))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(test_config.socketOpen ("eth0", 2))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4683, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "test_config.socketOpen(\"eth0\", 2)", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 4684 | ASSERT_TRUE(test_config.socketOpen("eth1", AF_INET))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(test_config.socketOpen ("eth1", 2))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4684, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "test_config.socketOpen(\"eth1\", 2)", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 4685 | } | |||
| 4686 | ||||
| 4687 | // This test verifies that it is possible to select subset of interfaces | |||
| 4688 | // and addresses. | |||
| 4689 | TEST_F(Dhcp4ParserTest, selectedInterfacesAndAddresses)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("selectedInterfacesAndAddresses") > 1, "test_name must not be empty"); class Dhcp4ParserTest_selectedInterfacesAndAddresses_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_selectedInterfacesAndAddresses_Test () = default; ~Dhcp4ParserTest_selectedInterfacesAndAddresses_Test () override = default; Dhcp4ParserTest_selectedInterfacesAndAddresses_Test (const Dhcp4ParserTest_selectedInterfacesAndAddresses_Test & ) = delete; Dhcp4ParserTest_selectedInterfacesAndAddresses_Test & operator=( const Dhcp4ParserTest_selectedInterfacesAndAddresses_Test &) = delete; Dhcp4ParserTest_selectedInterfacesAndAddresses_Test (Dhcp4ParserTest_selectedInterfacesAndAddresses_Test && ) noexcept = delete; Dhcp4ParserTest_selectedInterfacesAndAddresses_Test & operator=( Dhcp4ParserTest_selectedInterfacesAndAddresses_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_selectedInterfacesAndAddresses_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "selectedInterfacesAndAddresses", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4689), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4689), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4689), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_selectedInterfacesAndAddresses_Test >); void Dhcp4ParserTest_selectedInterfacesAndAddresses_Test ::TestBody() { | |||
| 4690 | IfaceMgrTestConfig test_config(true); | |||
| 4691 | ||||
| 4692 | ConstElementPtr x; | |||
| 4693 | string config = "{ \"interfaces-config\": {" | |||
| 4694 | " \"interfaces\": [ \"eth0/10.0.0.1\", \"eth1/192.0.2.3\" ]" | |||
| 4695 | "}," | |||
| 4696 | "\"rebind-timer\": 2000, " | |||
| 4697 | "\"renew-timer\": 1000, " | |||
| 4698 | "\"valid-lifetime\": 4000 }"; | |||
| 4699 | ||||
| 4700 | ConstElementPtr json; | |||
| 4701 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_4701 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4701 ; } } else gtest_label_testnothrow_4701 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4701, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 4702 | ||||
| 4703 | ConstElementPtr status; | |||
| 4704 | ||||
| 4705 | // Make sure the config manager is clean and there is no hanging | |||
| 4706 | // interface configuration. | |||
| 4707 | ASSERT_FALSE(test_config.socketOpen("eth0", "10.0.0.1"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(test_config.socketOpen ("eth0", "10.0.0.1")))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4707, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "test_config.socketOpen(\"eth0\", \"10.0.0.1\")", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4708 | ASSERT_FALSE(test_config.socketOpen("eth1", "192.0.2.3"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(test_config.socketOpen ("eth1", "192.0.2.3")))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4708, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "test_config.socketOpen(\"eth1\", \"192.0.2.3\")", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4709 | ASSERT_FALSE(test_config.socketOpen("eth1", "192.0.2.5"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(test_config.socketOpen ("eth1", "192.0.2.5")))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4709, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "test_config.socketOpen(\"eth1\", \"192.0.2.5\")", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4710 | ||||
| 4711 | // Apply configuration. | |||
| 4712 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4712; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4712; } } else gtest_label_testnothrow_4712 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4712, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4713 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4713, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4714 | checkResult(status, 0); | |||
| 4715 | ||||
| 4716 | CfgMgr::instance().getStagingCfg()->getCfgIface()->openSockets(AF_INET2, 10000); | |||
| 4717 | ||||
| 4718 | // An address on eth0 was selected | |||
| 4719 | EXPECT_TRUE(test_config.socketOpen("eth0", "10.0.0.1"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(test_config.socketOpen ("eth0", "10.0.0.1"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4719, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "test_config.socketOpen(\"eth0\", \"10.0.0.1\")", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 4720 | // The 192.0.2.3 address on eth1 was selected. | |||
| 4721 | EXPECT_TRUE(test_config.socketOpen("eth1", "192.0.2.3"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(test_config.socketOpen ("eth1", "192.0.2.3"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4721, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "test_config.socketOpen(\"eth1\", \"192.0.2.3\")", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4722 | // The 192.0.2.5 was not selected, thus the socket should not | |||
| 4723 | // be bound to this address. | |||
| 4724 | EXPECT_FALSE(test_config.socketOpen("eth1", "192.0.2.5"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(test_config.socketOpen ("eth1", "192.0.2.5")))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4724, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "test_config.socketOpen(\"eth1\", \"192.0.2.5\")", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4725 | } | |||
| 4726 | ||||
| 4727 | // This test checks if it is possible to specify relay information | |||
| 4728 | TEST_F(Dhcp4ParserTest, subnetRelayInfo)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("subnetRelayInfo") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_subnetRelayInfo_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_subnetRelayInfo_Test() = default; ~ Dhcp4ParserTest_subnetRelayInfo_Test() override = default; Dhcp4ParserTest_subnetRelayInfo_Test (const Dhcp4ParserTest_subnetRelayInfo_Test &) = delete; Dhcp4ParserTest_subnetRelayInfo_Test & operator=( const Dhcp4ParserTest_subnetRelayInfo_Test &) = delete; Dhcp4ParserTest_subnetRelayInfo_Test (Dhcp4ParserTest_subnetRelayInfo_Test &&) noexcept = delete; Dhcp4ParserTest_subnetRelayInfo_Test & operator=( Dhcp4ParserTest_subnetRelayInfo_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_subnetRelayInfo_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "subnetRelayInfo", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 4728 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4728), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4728), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_subnetRelayInfo_Test >); void Dhcp4ParserTest_subnetRelayInfo_Test::TestBody() { | |||
| 4729 | ||||
| 4730 | // A config with relay information. | |||
| 4731 | string config = "{ " + genIfaceConfig() + "," | |||
| 4732 | "\"rebind-timer\": 2000, " | |||
| 4733 | "\"renew-timer\": 1000, " | |||
| 4734 | "\"subnet4\": [ { " | |||
| 4735 | " \"id\": 1," | |||
| 4736 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 4737 | " \"renew-timer\": 1, " | |||
| 4738 | " \"rebind-timer\": 2, " | |||
| 4739 | " \"valid-lifetime\": 4," | |||
| 4740 | " \"relay\": { " | |||
| 4741 | " \"ip-addresses\": [ \"192.0.2.123\" ]" | |||
| 4742 | " }," | |||
| 4743 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 4744 | "\"valid-lifetime\": 4000 }"; | |||
| 4745 | ||||
| 4746 | ConstElementPtr json; | |||
| 4747 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_4747 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4747 ; } } else gtest_label_testnothrow_4747 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4747, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 4748 | extractConfig(config); | |||
| 4749 | ||||
| 4750 | ConstElementPtr status; | |||
| 4751 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4751; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4751; } } else gtest_label_testnothrow_4751 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4751, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4752 | ||||
| 4753 | // returned value should be 0 (configuration success) | |||
| 4754 | checkResult(status, 0); | |||
| 4755 | ||||
| 4756 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 4757 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200")); | |||
| 4758 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4758, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4759 | ||||
| 4760 | EXPECT_TRUE(subnet->hasRelays())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->hasRelays( ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4760, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->hasRelays()", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 4761 | EXPECT_TRUE(subnet->hasRelayAddress(IOAddress("192.0.2.123")))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->hasRelayAddress (IOAddress("192.0.2.123")))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4761, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->hasRelayAddress(IOAddress(\"192.0.2.123\"))", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 4762 | } | |||
| 4763 | ||||
| 4764 | // This test checks if it is possible to specify a list of relays | |||
| 4765 | TEST_F(Dhcp4ParserTest, subnetRelayInfoList)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("subnetRelayInfoList") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_subnetRelayInfoList_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_subnetRelayInfoList_Test() = default ; ~Dhcp4ParserTest_subnetRelayInfoList_Test() override = default ; Dhcp4ParserTest_subnetRelayInfoList_Test (const Dhcp4ParserTest_subnetRelayInfoList_Test &) = delete; Dhcp4ParserTest_subnetRelayInfoList_Test & operator=( const Dhcp4ParserTest_subnetRelayInfoList_Test & ) = delete; Dhcp4ParserTest_subnetRelayInfoList_Test (Dhcp4ParserTest_subnetRelayInfoList_Test &&) noexcept = delete; Dhcp4ParserTest_subnetRelayInfoList_Test & operator=( Dhcp4ParserTest_subnetRelayInfoList_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_subnetRelayInfoList_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "subnetRelayInfoList", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4765), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4765), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4765), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_subnetRelayInfoList_Test >); void Dhcp4ParserTest_subnetRelayInfoList_Test::TestBody () { | |||
| 4766 | // A config with relay information. | |||
| 4767 | string config = "{ " + genIfaceConfig() + "," | |||
| 4768 | "\"rebind-timer\": 2000, " | |||
| 4769 | "\"renew-timer\": 1000, " | |||
| 4770 | "\"subnet4\": [ { " | |||
| 4771 | " \"id\": 1," | |||
| 4772 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 4773 | " \"renew-timer\": 1, " | |||
| 4774 | " \"rebind-timer\": 2, " | |||
| 4775 | " \"valid-lifetime\": 4," | |||
| 4776 | " \"relay\": { " | |||
| 4777 | " \"ip-addresses\": [ \"192.0.3.123\", \"192.0.3.124\" ]" | |||
| 4778 | " }," | |||
| 4779 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 4780 | "\"valid-lifetime\": 4000 }"; | |||
| 4781 | ||||
| 4782 | ConstElementPtr json; | |||
| 4783 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_4783 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4783 ; } } else gtest_label_testnothrow_4783 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4783, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 4784 | extractConfig(config); | |||
| 4785 | ||||
| 4786 | ConstElementPtr status; | |||
| 4787 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4787; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4787; } } else gtest_label_testnothrow_4787 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4787, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4788 | ||||
| 4789 | // returned value should be 0 (configuration success) | |||
| 4790 | checkResult(status, 0); | |||
| 4791 | ||||
| 4792 | SubnetSelector selector; | |||
| 4793 | selector.giaddr_ = IOAddress("192.0.2.200"); | |||
| 4794 | ||||
| 4795 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 4796 | getCfgSubnets4()->selectSubnet(selector); | |||
| 4797 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4797, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4798 | ||||
| 4799 | EXPECT_TRUE(subnet->hasRelays())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->hasRelays( ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4799, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->hasRelays()", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 4800 | EXPECT_TRUE(subnet->hasRelayAddress(IOAddress("192.0.3.123")))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->hasRelayAddress (IOAddress("192.0.3.123")))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4800, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->hasRelayAddress(IOAddress(\"192.0.3.123\"))", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 4801 | EXPECT_TRUE(subnet->hasRelayAddress(IOAddress("192.0.3.124")))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->hasRelayAddress (IOAddress("192.0.3.124")))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4801, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->hasRelayAddress(IOAddress(\"192.0.3.124\"))", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 4802 | } | |||
| 4803 | ||||
| 4804 | // Goal of this test is to verify that multiple subnets can be configured | |||
| 4805 | // with defined client classes. | |||
| 4806 | TEST_F(Dhcp4ParserTest, classifySubnets)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("classifySubnets") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_classifySubnets_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_classifySubnets_Test() = default; ~ Dhcp4ParserTest_classifySubnets_Test() override = default; Dhcp4ParserTest_classifySubnets_Test (const Dhcp4ParserTest_classifySubnets_Test &) = delete; Dhcp4ParserTest_classifySubnets_Test & operator=( const Dhcp4ParserTest_classifySubnets_Test &) = delete; Dhcp4ParserTest_classifySubnets_Test (Dhcp4ParserTest_classifySubnets_Test &&) noexcept = delete; Dhcp4ParserTest_classifySubnets_Test & operator=( Dhcp4ParserTest_classifySubnets_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_classifySubnets_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "classifySubnets", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 4806 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4806), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4806), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_classifySubnets_Test >); void Dhcp4ParserTest_classifySubnets_Test::TestBody() { | |||
| 4807 | ConstElementPtr x; | |||
| 4808 | string config = "{ " + genIfaceConfig() + "," | |||
| 4809 | "\"rebind-timer\": 2000, " | |||
| 4810 | "\"renew-timer\": 1000, " | |||
| 4811 | "\"subnet4\": [ { " | |||
| 4812 | " \"id\": 1," | |||
| 4813 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 4814 | " \"subnet\": \"192.0.2.0/24\", " | |||
| 4815 | " \"client-class\": \"alpha\" " | |||
| 4816 | " }," | |||
| 4817 | " {" | |||
| 4818 | " \"id\": 2," | |||
| 4819 | " \"pools\": [ { \"pool\": \"192.0.3.101 - 192.0.3.150\" } ]," | |||
| 4820 | " \"subnet\": \"192.0.3.0/24\", " | |||
| 4821 | " \"client-class\": \"beta\" " | |||
| 4822 | " }," | |||
| 4823 | " {" | |||
| 4824 | " \"id\": 3," | |||
| 4825 | " \"pools\": [ { \"pool\": \"192.0.4.101 - 192.0.4.150\" } ]," | |||
| 4826 | " \"subnet\": \"192.0.4.0/24\", " | |||
| 4827 | " \"client-classes\": [ \"gamma\" ] " | |||
| 4828 | " }," | |||
| 4829 | " {" | |||
| 4830 | " \"id\": 4," | |||
| 4831 | " \"pools\": [ { \"pool\": \"192.0.5.101 - 192.0.5.150\" } ]," | |||
| 4832 | " \"subnet\": \"192.0.5.0/24\" " | |||
| 4833 | " } ]," | |||
| 4834 | "\"valid-lifetime\": 4000 }"; | |||
| 4835 | ||||
| 4836 | ConstElementPtr json; | |||
| 4837 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_4837 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4837 ; } } else gtest_label_testnothrow_4837 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4837, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 4838 | extractConfig(config); | |||
| 4839 | ||||
| 4840 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4840; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4840; } } else gtest_label_testnothrow_4840 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4840, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4841 | checkResult(x, 0); | |||
| 4842 | ||||
| 4843 | const Subnet4Collection* subnets = | |||
| 4844 | CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->getAll(); | |||
| 4845 | ASSERT_TRUE(subnets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnets)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4845, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnets", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 4846 | ASSERT_EQ(4, subnets->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("4", "subnets->size()" , 4, subnets->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4846, gtest_ar.failure_message()) = ::testing::Message(); // We expect 4 subnets | |||
| 4847 | ||||
| 4848 | // Let's check if client belonging to alpha class is supported in subnet[0] | |||
| 4849 | // and not supported in any other subnet (except subnet[3], which allows | |||
| 4850 | // everyone). | |||
| 4851 | ClientClasses classes; | |||
| 4852 | classes.insert("alpha"); | |||
| 4853 | auto subnet0 = subnets->begin(); | |||
| 4854 | auto subnet1 = std::next(subnet0); | |||
| 4855 | auto subnet2 = std::next(subnet1); | |||
| 4856 | auto subnet3 = std::next(subnet2); | |||
| 4857 | EXPECT_TRUE ((*subnet0)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult((*subnet0)->clientSupported (classes))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4857, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet0)->clientSupported(classes)", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4858 | EXPECT_FALSE((*subnet1)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!((*subnet1)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4858, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet1)->clientSupported(classes)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4859 | EXPECT_FALSE((*subnet2)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!((*subnet2)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4859, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet2)->clientSupported(classes)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4860 | EXPECT_TRUE ((*subnet3)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult((*subnet3)->clientSupported (classes))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4860, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet3)->clientSupported(classes)", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4861 | ||||
| 4862 | // Let's check if client belonging to beta class is supported in subnet[1] | |||
| 4863 | // and not supported in any other subnet (except subnet[3], which allows | |||
| 4864 | // everyone). | |||
| 4865 | classes.clear(); | |||
| 4866 | classes.insert("beta"); | |||
| 4867 | EXPECT_FALSE((*subnet0)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!((*subnet0)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4867, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet0)->clientSupported(classes)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4868 | EXPECT_TRUE ((*subnet1)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult((*subnet1)->clientSupported (classes))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4868, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet1)->clientSupported(classes)", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4869 | EXPECT_FALSE((*subnet2)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!((*subnet2)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4869, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet2)->clientSupported(classes)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4870 | EXPECT_TRUE ((*subnet3)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult((*subnet3)->clientSupported (classes))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4870, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet3)->clientSupported(classes)", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4871 | ||||
| 4872 | // Let's check if client belonging to gamma class is supported in subnet[2] | |||
| 4873 | // and not supported in any other subnet (except subnet[3], which allows | |||
| 4874 | // everyone). | |||
| 4875 | classes.clear(); | |||
| 4876 | classes.insert("gamma"); | |||
| 4877 | EXPECT_FALSE((*subnet0)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!((*subnet0)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4877, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet0)->clientSupported(classes)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4878 | EXPECT_FALSE((*subnet1)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!((*subnet1)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4878, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet1)->clientSupported(classes)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4879 | EXPECT_TRUE ((*subnet2)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult((*subnet2)->clientSupported (classes))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4879, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet2)->clientSupported(classes)", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4880 | EXPECT_TRUE ((*subnet3)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult((*subnet3)->clientSupported (classes))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4880, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet3)->clientSupported(classes)", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4881 | ||||
| 4882 | // Let's check if client belonging to some other class (not mentioned in | |||
| 4883 | // the config) is supported only in subnet[3], which allows everyone. | |||
| 4884 | classes.clear(); | |||
| 4885 | classes.insert("delta"); | |||
| 4886 | EXPECT_FALSE((*subnet0)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!((*subnet0)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4886, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet0)->clientSupported(classes)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4887 | EXPECT_FALSE((*subnet1)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!((*subnet1)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4887, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet1)->clientSupported(classes)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4888 | EXPECT_FALSE((*subnet2)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!((*subnet2)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4888, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet2)->clientSupported(classes)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4889 | EXPECT_TRUE ((*subnet3)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult((*subnet3)->clientSupported (classes))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4889, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet3)->clientSupported(classes)", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4890 | ||||
| 4891 | // Finally, let's check class-less client. He should be allowed only in | |||
| 4892 | // the last subnet, which does not have any class restrictions. | |||
| 4893 | classes.clear(); | |||
| 4894 | EXPECT_FALSE((*subnet0)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!((*subnet0)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4894, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet0)->clientSupported(classes)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4895 | EXPECT_FALSE((*subnet1)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!((*subnet1)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4895, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet1)->clientSupported(classes)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4896 | EXPECT_FALSE((*subnet2)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!((*subnet2)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4896, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet2)->clientSupported(classes)", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4897 | EXPECT_TRUE ((*subnet3)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult((*subnet3)->clientSupported (classes))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4897, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "(*subnet3)->clientSupported(classes)", "false", "true") .c_str()) = ::testing::Message(); | |||
| 4898 | } | |||
| 4899 | ||||
| 4900 | // Goal of this test is to verify that multiple pools can be configured | |||
| 4901 | // with defined client classes. | |||
| 4902 | TEST_F(Dhcp4ParserTest, classifyPools)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("classifyPools") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_classifyPools_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_classifyPools_Test() = default; ~Dhcp4ParserTest_classifyPools_Test () override = default; Dhcp4ParserTest_classifyPools_Test (const Dhcp4ParserTest_classifyPools_Test &) = delete; Dhcp4ParserTest_classifyPools_Test & operator=( const Dhcp4ParserTest_classifyPools_Test & ) = delete; Dhcp4ParserTest_classifyPools_Test (Dhcp4ParserTest_classifyPools_Test &&) noexcept = delete; Dhcp4ParserTest_classifyPools_Test & operator=( Dhcp4ParserTest_classifyPools_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_classifyPools_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "classifyPools", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 4902 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4902), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4902), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_classifyPools_Test >); void Dhcp4ParserTest_classifyPools_Test::TestBody() { | |||
| 4903 | ConstElementPtr x; | |||
| 4904 | string config = "{ " + genIfaceConfig() + "," | |||
| 4905 | "\"rebind-timer\": 2000, " | |||
| 4906 | "\"renew-timer\": 1000, " | |||
| 4907 | "\"subnet4\": [ { " | |||
| 4908 | " \"id\": 1," | |||
| 4909 | " \"pools\": [ { " | |||
| 4910 | " \"pool\": \"192.0.2.1 - 192.0.2.100\", " | |||
| 4911 | " \"client-classes\": [ \"alpha\" ]" | |||
| 4912 | " }," | |||
| 4913 | " {" | |||
| 4914 | " \"pool\": \"192.0.3.101 - 192.0.3.150\", " | |||
| 4915 | " \"client-classes\": [ \"beta\" ] " | |||
| 4916 | " }," | |||
| 4917 | " {" | |||
| 4918 | " \"pool\": \"192.0.4.101 - 192.0.4.150\", " | |||
| 4919 | " \"client-classes\": [ \"gamma\" ] " | |||
| 4920 | " }," | |||
| 4921 | " {" | |||
| 4922 | " \"pool\": \"192.0.5.101 - 192.0.5.150\" " | |||
| 4923 | " } ]," | |||
| 4924 | " \"subnet\": \"192.0.0.0/16\" " | |||
| 4925 | " } ]," | |||
| 4926 | "\"valid-lifetime\": 4000 }"; | |||
| 4927 | ||||
| 4928 | ConstElementPtr json; | |||
| 4929 | ASSERT_NO_THROW(json = parseDHCP4(config, true))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(config, 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_4929 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4929 ; } } else gtest_label_testnothrow_4929 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4929, ("Expected: " "json = parseDHCP4(config, true)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 4930 | extractConfig(config); | |||
| 4931 | ||||
| 4932 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_4932; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_4932; } } else gtest_label_testnothrow_4932 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4932, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 4933 | checkResult(x, 0); | |||
| 4934 | ||||
| 4935 | const Subnet4Collection* subnets = | |||
| 4936 | CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->getAll(); | |||
| 4937 | ASSERT_TRUE(subnets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnets)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4937, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnets", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 4938 | ASSERT_EQ(1, subnets->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "subnets->size()" , 1, subnets->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4938, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 4939 | const PoolCollection& pools = (*subnets->begin())->getPools(Lease::TYPE_V4); | |||
| 4940 | ASSERT_EQ(4, pools.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("4", "pools.size()" , 4, pools.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4940, gtest_ar.failure_message()) = ::testing::Message(); // We expect 4 pools | |||
| 4941 | ||||
| 4942 | // Let's check if client belonging to alpha class is supported in pool[0] | |||
| 4943 | // and not supported in any other pool (except pool[3], which allows | |||
| 4944 | // everyone). | |||
| 4945 | ClientClasses classes; | |||
| 4946 | classes.insert("alpha"); | |||
| 4947 | EXPECT_TRUE(pools.at(0)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pools.at(0)->clientSupported (classes))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4947, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(0)->clientSupported(classes)", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 4948 | EXPECT_FALSE(pools.at(1)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pools.at(1)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4948, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(1)->clientSupported(classes)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4949 | EXPECT_FALSE(pools.at(2)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pools.at(2)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4949, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(2)->clientSupported(classes)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4950 | EXPECT_TRUE(pools.at(3)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pools.at(3)->clientSupported (classes))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4950, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(3)->clientSupported(classes)", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 4951 | ||||
| 4952 | // Let's check if client belonging to beta class is supported in pool[1] | |||
| 4953 | // and not supported in any other pool (except pool[3], which allows | |||
| 4954 | // everyone). | |||
| 4955 | classes.clear(); | |||
| 4956 | classes.insert("beta"); | |||
| 4957 | EXPECT_FALSE(pools.at(0)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pools.at(0)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4957, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(0)->clientSupported(classes)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4958 | EXPECT_TRUE(pools.at(1)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pools.at(1)->clientSupported (classes))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4958, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(1)->clientSupported(classes)", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 4959 | EXPECT_FALSE(pools.at(2)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pools.at(2)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4959, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(2)->clientSupported(classes)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4960 | EXPECT_TRUE(pools.at(3)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pools.at(3)->clientSupported (classes))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4960, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(3)->clientSupported(classes)", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 4961 | ||||
| 4962 | // Let's check if client belonging to gamma class is supported in pool[2] | |||
| 4963 | // and not supported in any other pool (except pool[3], which allows | |||
| 4964 | // everyone). | |||
| 4965 | classes.clear(); | |||
| 4966 | classes.insert("gamma"); | |||
| 4967 | EXPECT_FALSE(pools.at(0)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pools.at(0)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4967, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(0)->clientSupported(classes)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4968 | EXPECT_FALSE(pools.at(1)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pools.at(1)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4968, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(1)->clientSupported(classes)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4969 | EXPECT_TRUE(pools.at(2)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pools.at(2)->clientSupported (classes))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4969, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(2)->clientSupported(classes)", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 4970 | EXPECT_TRUE(pools.at(3)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pools.at(3)->clientSupported (classes))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4970, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(3)->clientSupported(classes)", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 4971 | ||||
| 4972 | // Let's check if client belonging to some other class (not mentioned in | |||
| 4973 | // the config) is supported only in pool[3], which allows everyone. | |||
| 4974 | classes.clear(); | |||
| 4975 | classes.insert("delta"); | |||
| 4976 | EXPECT_FALSE(pools.at(0)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pools.at(0)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4976, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(0)->clientSupported(classes)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4977 | EXPECT_FALSE(pools.at(1)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pools.at(1)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4977, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(1)->clientSupported(classes)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4978 | EXPECT_FALSE(pools.at(2)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pools.at(2)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4978, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(2)->clientSupported(classes)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4979 | EXPECT_TRUE(pools.at(3)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pools.at(3)->clientSupported (classes))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4979, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(3)->clientSupported(classes)", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 4980 | ||||
| 4981 | // Finally, let's check class-less client. He should be allowed only in | |||
| 4982 | // the last pool, which does not have any class restrictions. | |||
| 4983 | classes.clear(); | |||
| 4984 | EXPECT_FALSE(pools.at(0)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pools.at(0)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4984, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(0)->clientSupported(classes)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4985 | EXPECT_FALSE(pools.at(1)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pools.at(1)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4985, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(1)->clientSupported(classes)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4986 | EXPECT_FALSE(pools.at(2)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pools.at(2)->clientSupported (classes)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4986, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(2)->clientSupported(classes)", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 4987 | EXPECT_TRUE(pools.at(3)->clientSupported(classes))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pools.at(3)->clientSupported (classes))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4987, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pools.at(3)->clientSupported(classes)", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 4988 | } | |||
| 4989 | ||||
| 4990 | // This test verifies that valid d2CliengConfig works correctly. | |||
| 4991 | TEST_F(Dhcp4ParserTest, d2ClientConfigValid)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("d2ClientConfigValid") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_d2ClientConfigValid_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_d2ClientConfigValid_Test() = default ; ~Dhcp4ParserTest_d2ClientConfigValid_Test() override = default ; Dhcp4ParserTest_d2ClientConfigValid_Test (const Dhcp4ParserTest_d2ClientConfigValid_Test &) = delete; Dhcp4ParserTest_d2ClientConfigValid_Test & operator=( const Dhcp4ParserTest_d2ClientConfigValid_Test & ) = delete; Dhcp4ParserTest_d2ClientConfigValid_Test (Dhcp4ParserTest_d2ClientConfigValid_Test &&) noexcept = delete; Dhcp4ParserTest_d2ClientConfigValid_Test & operator=( Dhcp4ParserTest_d2ClientConfigValid_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_d2ClientConfigValid_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "d2ClientConfigValid", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4991), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4991), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4991), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_d2ClientConfigValid_Test >); void Dhcp4ParserTest_d2ClientConfigValid_Test::TestBody () { | |||
| 4992 | // Verify that the D2 configuration can be fetched and is set to disabled. | |||
| 4993 | D2ClientConfigPtr d2_client_config = CfgMgr::instance().getD2ClientConfig(); | |||
| 4994 | EXPECT_FALSE(d2_client_config->getEnableUpdates())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(d2_client_config-> getEnableUpdates()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4994, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "d2_client_config->getEnableUpdates()", "true", "false") .c_str()) = ::testing::Message(); | |||
| 4995 | ||||
| 4996 | // Verify that the convenience method agrees. | |||
| 4997 | ASSERT_FALSE(CfgMgr::instance().ddnsEnabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(CfgMgr::instance(). ddnsEnabled()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 4997, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().ddnsEnabled()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 4998 | ||||
| 4999 | string config_str = "{ " + genIfaceConfig() + "," | |||
| 5000 | "\"rebind-timer\": 2000, " | |||
| 5001 | "\"renew-timer\": 1000, " | |||
| 5002 | "\"subnet4\": [ { " | |||
| 5003 | " \"id\": 1," | |||
| 5004 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 5005 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 5006 | " \"dhcp-ddns\" : {" | |||
| 5007 | " \"enable-updates\" : true, " | |||
| 5008 | " \"server-ip\" : \"192.168.2.1\", " | |||
| 5009 | " \"server-port\" : 777, " | |||
| 5010 | " \"sender-ip\" : \"192.168.2.2\", " | |||
| 5011 | " \"sender-port\" : 778, " | |||
| 5012 | " \"max-queue-size\" : 2048, " | |||
| 5013 | " \"ncr-protocol\" : \"UDP\", " | |||
| 5014 | " \"ncr-format\" : \"JSON\"}, " | |||
| 5015 | "\"valid-lifetime\": 4000 }"; | |||
| 5016 | ||||
| 5017 | // Convert the JSON string to configuration elements. | |||
| 5018 | ConstElementPtr config; | |||
| 5019 | ASSERT_NO_THROW(config = parseDHCP4(config_str, true))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { config = parseDHCP4(config_str, 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_5019; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5019; } } else gtest_label_testnothrow_5019 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5019, ("Expected: " "config = parseDHCP4(config_str, true)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5020 | extractConfig(config_str); | |||
| 5021 | ||||
| 5022 | // Pass the configuration in for parsing. | |||
| 5023 | ConstElementPtr status; | |||
| 5024 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, 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_5024; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5024; } } else gtest_label_testnothrow_5024 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5024, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5025 | ||||
| 5026 | // check if returned status is OK | |||
| 5027 | checkResult(status, 0); | |||
| 5028 | ||||
| 5029 | // Verify that DHCP-DDNS updating is enabled. | |||
| 5030 | EXPECT_TRUE(CfgMgr::instance().ddnsEnabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(CfgMgr::instance().ddnsEnabled ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5030, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().ddnsEnabled()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 5031 | ||||
| 5032 | // Verify that the D2 configuration can be retrieved. | |||
| 5033 | d2_client_config = CfgMgr::instance().getD2ClientConfig(); | |||
| 5034 | ASSERT_TRUE(d2_client_config)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(d2_client_config)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5034, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "d2_client_config", "false", "true") .c_str()) = ::testing:: Message(); | |||
| 5035 | ||||
| 5036 | // Verify that the configuration values are correct. | |||
| 5037 | EXPECT_TRUE(d2_client_config->getEnableUpdates())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(d2_client_config-> getEnableUpdates())) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5037, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "d2_client_config->getEnableUpdates()", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5038 | EXPECT_EQ("192.168.2.1", d2_client_config->getServerIp().toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.168.2.1\"" , "d2_client_config->getServerIp().toText()", "192.168.2.1" , d2_client_config->getServerIp().toText()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5038 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5039 | EXPECT_EQ(777, d2_client_config->getServerPort())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("777", "d2_client_config->getServerPort()" , 777, d2_client_config->getServerPort()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5039 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5040 | EXPECT_EQ("192.168.2.2", d2_client_config->getSenderIp().toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.168.2.2\"" , "d2_client_config->getSenderIp().toText()", "192.168.2.2" , d2_client_config->getSenderIp().toText()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5040 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5041 | EXPECT_EQ(778, d2_client_config->getSenderPort())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("778", "d2_client_config->getSenderPort()" , 778, d2_client_config->getSenderPort()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5041 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5042 | EXPECT_EQ(2048, d2_client_config->getMaxQueueSize())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2048", "d2_client_config->getMaxQueueSize()" , 2048, d2_client_config->getMaxQueueSize()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5042 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5043 | EXPECT_EQ(dhcp_ddns::NCR_UDP, d2_client_config->getNcrProtocol())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("dhcp_ddns::NCR_UDP" , "d2_client_config->getNcrProtocol()", dhcp_ddns::NCR_UDP , d2_client_config->getNcrProtocol()))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5043 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5044 | EXPECT_EQ(dhcp_ddns::FMT_JSON, d2_client_config->getNcrFormat())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("dhcp_ddns::FMT_JSON" , "d2_client_config->getNcrFormat()", dhcp_ddns::FMT_JSON, d2_client_config->getNcrFormat()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5044, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5045 | ||||
| 5046 | // ddns-send-updates should be global default | |||
| 5047 | checkGlobal("ddns-send-updates", true); | |||
| 5048 | checkGlobal("ddns-conflict-resolution-mode", "check-with-dhcid"); | |||
| 5049 | ||||
| 5050 | // The following, deprecated dhcp-ddns parameters, | |||
| 5051 | // should all have global default values. | |||
| 5052 | checkGlobal("ddns-override-no-update", false); | |||
| 5053 | checkGlobal("ddns-override-client-update", false); | |||
| 5054 | checkGlobal("ddns-replace-client-name", "never"); | |||
| 5055 | checkGlobal("ddns-generated-prefix", "myhost"); | |||
| 5056 | checkGlobal("ddns-qualifying-suffix", ""); | |||
| 5057 | } | |||
| 5058 | ||||
| 5059 | // This test checks the ability of the server to handle a configuration | |||
| 5060 | // containing an invalid dhcp-ddns (D2ClientConfig) entry. | |||
| 5061 | TEST_F(Dhcp4ParserTest, invalidD2ClientConfig)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("invalidD2ClientConfig") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_invalidD2ClientConfig_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_invalidD2ClientConfig_Test() = default ; ~Dhcp4ParserTest_invalidD2ClientConfig_Test() override = default ; Dhcp4ParserTest_invalidD2ClientConfig_Test (const Dhcp4ParserTest_invalidD2ClientConfig_Test &) = delete; Dhcp4ParserTest_invalidD2ClientConfig_Test & operator=( const Dhcp4ParserTest_invalidD2ClientConfig_Test & ) = delete; Dhcp4ParserTest_invalidD2ClientConfig_Test (Dhcp4ParserTest_invalidD2ClientConfig_Test &&) noexcept = delete; Dhcp4ParserTest_invalidD2ClientConfig_Test & operator=( Dhcp4ParserTest_invalidD2ClientConfig_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_invalidD2ClientConfig_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "invalidD2ClientConfig", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5061), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5061), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5061), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_invalidD2ClientConfig_Test >); void Dhcp4ParserTest_invalidD2ClientConfig_Test::TestBody () { | |||
| 5062 | // Configuration string with an invalid D2 client config, | |||
| 5063 | // "server-ip" is invalid. | |||
| 5064 | string config_str = "{ " + genIfaceConfig() + "," | |||
| 5065 | "\"rebind-timer\": 2000, " | |||
| 5066 | "\"renew-timer\": 1000, " | |||
| 5067 | "\"ddns-override-no-update\" : true, " | |||
| 5068 | "\"ddns-override-client-update\" : true, " | |||
| 5069 | "\"ddns-replace-client-name\" : \"when-present\", " | |||
| 5070 | "\"ddns-generated-prefix\" : \"test.prefix\", " | |||
| 5071 | "\"ddns-qualifying-suffix\" : \"test.suffix.\", " | |||
| 5072 | "\"subnet4\": [ { " | |||
| 5073 | " \"id\": 1," | |||
| 5074 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 5075 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 5076 | " \"dhcp-ddns\" : {" | |||
| 5077 | " \"enable-updates\" : true, " | |||
| 5078 | " \"server-ip\" : \"bogus-value\", " | |||
| 5079 | " \"server-port\" : 5301, " | |||
| 5080 | " \"ncr-protocol\" : \"UDP\", " | |||
| 5081 | " \"ncr-format\" : \"JSON\"}," | |||
| 5082 | "\"valid-lifetime\": 4000 }"; | |||
| 5083 | ||||
| 5084 | // Convert the JSON string to configuration elements. | |||
| 5085 | ConstElementPtr config; | |||
| 5086 | ASSERT_NO_THROW(config = parseDHCP4(config_str))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { config = parseDHCP4(config_str); } else static_assert(true, "" ); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5086 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5086 ; } } else gtest_label_testnothrow_5086 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5086, ("Expected: " "config = parseDHCP4(config_str)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5087 | ||||
| 5088 | // Configuration should not throw, but should fail. | |||
| 5089 | ConstElementPtr status; | |||
| 5090 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, 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_5090; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5090; } } else gtest_label_testnothrow_5090 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5090, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5091 | ||||
| 5092 | // check if returned status is failed. | |||
| 5093 | checkResult(status, 1); | |||
| 5094 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5094, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 5095 | ||||
| 5096 | // Verify that the D2 configuration can be fetched and is set to disabled. | |||
| 5097 | D2ClientConfigPtr d2_client_config = CfgMgr::instance().getD2ClientConfig(); | |||
| 5098 | EXPECT_FALSE(d2_client_config->getEnableUpdates())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(d2_client_config-> getEnableUpdates()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5098, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "d2_client_config->getEnableUpdates()", "true", "false") .c_str()) = ::testing::Message(); | |||
| 5099 | ||||
| 5100 | // Verify that the convenience method agrees. | |||
| 5101 | ASSERT_FALSE(CfgMgr::instance().ddnsEnabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(CfgMgr::instance(). ddnsEnabled()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5101, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().ddnsEnabled()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 5102 | } | |||
| 5103 | // This test verifies that the host reservations can be specified for | |||
| 5104 | // respective IPv4 subnets. | |||
| 5105 | TEST_F(Dhcp4ParserTest, reservations)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("reservations") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_reservations_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_reservations_Test() = default; ~Dhcp4ParserTest_reservations_Test () override = default; Dhcp4ParserTest_reservations_Test (const Dhcp4ParserTest_reservations_Test &) = delete; Dhcp4ParserTest_reservations_Test & operator=( const Dhcp4ParserTest_reservations_Test & ) = delete; Dhcp4ParserTest_reservations_Test (Dhcp4ParserTest_reservations_Test &&) noexcept = delete; Dhcp4ParserTest_reservations_Test & operator=( Dhcp4ParserTest_reservations_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_reservations_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "reservations", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5105 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5105), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5105), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_reservations_Test >); void Dhcp4ParserTest_reservations_Test::TestBody() { | |||
| 5106 | ConstElementPtr x; | |||
| 5107 | string config = "{ " + genIfaceConfig() + "," | |||
| 5108 | "\"rebind-timer\": 2000, " | |||
| 5109 | "\"renew-timer\": 1000, " | |||
| 5110 | "\"subnet4\": [ " | |||
| 5111 | " { " | |||
| 5112 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 5113 | " \"subnet\": \"192.0.2.0/24\", " | |||
| 5114 | " \"id\": 123," | |||
| 5115 | " \"reservations\": [" | |||
| 5116 | " ]" | |||
| 5117 | " }," | |||
| 5118 | " {" | |||
| 5119 | " \"reservations\": [" | |||
| 5120 | " {" | |||
| 5121 | " \"duid\": \"01:02:03:04:05:06:07:08:09:0A\"," | |||
| 5122 | " \"ip-address\": \"192.0.3.112\"," | |||
| 5123 | " \"hostname\": \"\"," | |||
| 5124 | " \"option-data\": [" | |||
| 5125 | " {" | |||
| 5126 | " \"name\": \"name-servers\"," | |||
| 5127 | " \"data\": \"192.0.3.15\"" | |||
| 5128 | " }," | |||
| 5129 | " {" | |||
| 5130 | " \"name\": \"default-ip-ttl\"," | |||
| 5131 | " \"data\": \"32\"" | |||
| 5132 | " }" | |||
| 5133 | " ]" | |||
| 5134 | " }," | |||
| 5135 | " {" | |||
| 5136 | " \"hw-address\": \"01:02:03:04:05:06\"," | |||
| 5137 | " \"ip-address\": \"192.0.3.120\"," | |||
| 5138 | " \"hostname\": \"\"," | |||
| 5139 | " \"option-data\": [" | |||
| 5140 | " {" | |||
| 5141 | " \"name\": \"name-servers\"," | |||
| 5142 | " \"data\": \"192.0.3.95\"" | |||
| 5143 | " }," | |||
| 5144 | " {" | |||
| 5145 | " \"name\": \"default-ip-ttl\"," | |||
| 5146 | " \"data\": \"11\"" | |||
| 5147 | " }" | |||
| 5148 | " ]" | |||
| 5149 | " }" | |||
| 5150 | " ]," | |||
| 5151 | " \"pools\": [ { \"pool\": \"192.0.3.101 - 192.0.3.150\" } ]," | |||
| 5152 | " \"subnet\": \"192.0.3.0/24\", " | |||
| 5153 | " \"id\": 234" | |||
| 5154 | " }," | |||
| 5155 | " {" | |||
| 5156 | " \"pools\": [ { \"pool\": \"192.0.4.101 - 192.0.4.150\" } ]," | |||
| 5157 | " \"subnet\": \"192.0.4.0/24\"," | |||
| 5158 | " \"id\": 542," | |||
| 5159 | " \"reservations\": [" | |||
| 5160 | " {" | |||
| 5161 | " \"duid\": \"0A:09:08:07:06:05:04:03:02:01\"," | |||
| 5162 | " \"ip-address\": \"192.0.4.101\"," | |||
| 5163 | " \"hostname\": \"\"," | |||
| 5164 | " \"option-data\": [" | |||
| 5165 | " {" | |||
| 5166 | " \"name\": \"name-servers\"," | |||
| 5167 | " \"data\": \"192.0.4.11\"" | |||
| 5168 | " }," | |||
| 5169 | " {" | |||
| 5170 | " \"name\": \"default-ip-ttl\"," | |||
| 5171 | " \"data\": \"95\"" | |||
| 5172 | " }" | |||
| 5173 | " ]" | |||
| 5174 | " }," | |||
| 5175 | " {" | |||
| 5176 | " \"circuit-id\": \"060504030201\"," | |||
| 5177 | " \"ip-address\": \"192.0.4.102\"," | |||
| 5178 | " \"hostname\": \"\"" | |||
| 5179 | " }," | |||
| 5180 | " {" | |||
| 5181 | " \"client-id\": \"05:01:02:03:04:05:06\"," | |||
| 5182 | " \"ip-address\": \"192.0.4.103\"," | |||
| 5183 | " \"hostname\": \"\"" | |||
| 5184 | " }" | |||
| 5185 | " ]" | |||
| 5186 | " } " | |||
| 5187 | "], " | |||
| 5188 | "\"valid-lifetime\": 4000 }"; | |||
| 5189 | ||||
| 5190 | ConstElementPtr json; | |||
| 5191 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_5191 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5191 ; } } else gtest_label_testnothrow_5191 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5191, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5192 | extractConfig(config); | |||
| 5193 | ||||
| 5194 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5194; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5194; } } else gtest_label_testnothrow_5194 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5194, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5195 | checkResult(x, 0); | |||
| 5196 | ||||
| 5197 | // Make sure all subnets have been successfully configured. There is no | |||
| 5198 | // need to sanity check the subnet properties because it should have | |||
| 5199 | // been already tested by other tests. | |||
| 5200 | const Subnet4Collection* subnets = | |||
| 5201 | CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->getAll(); | |||
| 5202 | ASSERT_TRUE(subnets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnets)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5202, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnets", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 5203 | ASSERT_EQ(3, subnets->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("3", "subnets->size()" , 3, subnets->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5203, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5204 | ||||
| 5205 | // Hosts configuration must be available. | |||
| 5206 | CfgHostsPtr hosts_cfg = CfgMgr::instance().getStagingCfg()->getCfgHosts(); | |||
| 5207 | ASSERT_TRUE(hosts_cfg)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(hosts_cfg)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5207, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg", "false", "true") .c_str()) = ::testing::Message (); | |||
| 5208 | ||||
| 5209 | // Let's create an object holding hardware address of the host having | |||
| 5210 | // a reservation in the subnet having id of 234. For simplicity the | |||
| 5211 | // address is a collection of numbers from 1 to 6. | |||
| 5212 | std::vector<uint8_t> hwaddr; | |||
| 5213 | for (unsigned int i = 1; i < 7; ++i) { | |||
| 5214 | hwaddr.push_back(static_cast<uint8_t>(i)); | |||
| 5215 | } | |||
| 5216 | // Retrieve the reservation and sanity check the address reserved. | |||
| 5217 | ConstHostPtr host = hosts_cfg->get4(234, Host::IDENT_HWADDR, | |||
| 5218 | &hwaddr[0], hwaddr.size()); | |||
| 5219 | ASSERT_TRUE(host)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(host)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5219 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "host", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5220 | EXPECT_EQ("192.0.3.120", host->getIPv4Reservation().toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.3.120\"" , "host->getIPv4Reservation().toText()", "192.0.3.120", host ->getIPv4Reservation().toText()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5220, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5221 | // This reservation should be solely assigned to the subnet 234, | |||
| 5222 | // and not to other two. | |||
| 5223 | EXPECT_FALSE(hosts_cfg->get4(123, Host::IDENT_HWADDR,switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 123, Host::IDENT_HWADDR, &hwaddr[0], hwaddr.size())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5224, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(123, Host::IDENT_HWADDR, &hwaddr[0], hwaddr.size())" , "true", "false") .c_str()) = ::testing::Message() | |||
| 5224 | &hwaddr[0], hwaddr.size()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 123, Host::IDENT_HWADDR, &hwaddr[0], hwaddr.size())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5224, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(123, Host::IDENT_HWADDR, &hwaddr[0], hwaddr.size())" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 5225 | EXPECT_FALSE(hosts_cfg->get4(542, Host::IDENT_HWADDR,switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 542, Host::IDENT_HWADDR, &hwaddr[0], hwaddr.size())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5226, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(542, Host::IDENT_HWADDR, &hwaddr[0], hwaddr.size())" , "true", "false") .c_str()) = ::testing::Message() | |||
| 5226 | &hwaddr[0], hwaddr.size()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 542, Host::IDENT_HWADDR, &hwaddr[0], hwaddr.size())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5226, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(542, Host::IDENT_HWADDR, &hwaddr[0], hwaddr.size())" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 5227 | // Check that options are assigned correctly. | |||
| 5228 | Option4AddrLstPtr opt_dns = | |||
| 5229 | retrieveOption<Option4AddrLstPtr>(*host, DHO_NAME_SERVERS); | |||
| 5230 | ASSERT_TRUE(opt_dns)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(opt_dns)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5230, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "opt_dns", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 5231 | Option4AddrLst::AddressContainer dns_addrs = opt_dns->getAddresses(); | |||
| 5232 | ASSERT_EQ(1, dns_addrs.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "dns_addrs.size()" , 1, dns_addrs.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5232, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5233 | EXPECT_EQ("192.0.3.95", dns_addrs[0].toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.3.95\"" , "dns_addrs[0].toText()", "192.0.3.95", dns_addrs[0].toText( )))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5233, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5234 | OptionUint8Ptr opt_ttl = | |||
| 5235 | retrieveOption<OptionUint8Ptr>(*host, DHO_DEFAULT_IP_TTL); | |||
| 5236 | ASSERT_TRUE(opt_ttl)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(opt_ttl)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5236, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "opt_ttl", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 5237 | EXPECT_EQ(11, static_cast<int>(opt_ttl->getValue()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("11", "static_cast<int>(opt_ttl->getValue())" , 11, static_cast<int>(opt_ttl->getValue())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5237, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5238 | ||||
| 5239 | // Do the same test for the DUID based reservation. | |||
| 5240 | std::vector<uint8_t> duid; | |||
| 5241 | for (unsigned int i = 1; i < 0xb; ++i) { | |||
| 5242 | duid.push_back(static_cast<uint8_t>(i)); | |||
| 5243 | } | |||
| 5244 | host = hosts_cfg->get4(234, Host::IDENT_DUID, &duid[0], duid.size()); | |||
| 5245 | ASSERT_TRUE(host)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(host)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5245 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "host", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5246 | EXPECT_EQ("192.0.3.112", host->getIPv4Reservation().toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.3.112\"" , "host->getIPv4Reservation().toText()", "192.0.3.112", host ->getIPv4Reservation().toText()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5246, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5247 | EXPECT_FALSE(hosts_cfg->get4(123, Host::IDENT_DUID, &duid[0], duid.size()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 123, Host::IDENT_DUID, &duid[0], duid.size())))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5247 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(123, Host::IDENT_DUID, &duid[0], duid.size())" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 5248 | EXPECT_FALSE(hosts_cfg->get4(542, Host::IDENT_DUID, &duid[0], duid.size()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 542, Host::IDENT_DUID, &duid[0], duid.size())))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5248 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(542, Host::IDENT_DUID, &duid[0], duid.size())" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 5249 | // Check that options are assigned correctly. | |||
| 5250 | opt_dns = retrieveOption<Option4AddrLstPtr>(*host, DHO_NAME_SERVERS); | |||
| 5251 | ASSERT_TRUE(opt_dns)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(opt_dns)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5251, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "opt_dns", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 5252 | dns_addrs = opt_dns->getAddresses(); | |||
| 5253 | ASSERT_EQ(1, dns_addrs.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "dns_addrs.size()" , 1, dns_addrs.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5253, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5254 | EXPECT_EQ("192.0.3.15", dns_addrs[0].toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.3.15\"" , "dns_addrs[0].toText()", "192.0.3.15", dns_addrs[0].toText( )))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5254, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5255 | opt_ttl = retrieveOption<OptionUint8Ptr>(*host, DHO_DEFAULT_IP_TTL); | |||
| 5256 | ASSERT_TRUE(opt_ttl)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(opt_ttl)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5256, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "opt_ttl", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 5257 | EXPECT_EQ(32, static_cast<int>(opt_ttl->getValue()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("32", "static_cast<int>(opt_ttl->getValue())" , 32, static_cast<int>(opt_ttl->getValue())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5257, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5258 | ||||
| 5259 | // The circuit-id used for one of the reservations in the subnet 542 | |||
| 5260 | // consists of numbers from 6 to 1. So, let's just reverse the order | |||
| 5261 | // of the address from the previous test. | |||
| 5262 | std::vector<uint8_t> circuit_id(hwaddr.rbegin(), hwaddr.rend()); | |||
| 5263 | host = hosts_cfg->get4(542, Host::IDENT_CIRCUIT_ID, &circuit_id[0], | |||
| 5264 | circuit_id.size()); | |||
| 5265 | EXPECT_TRUE(host)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(host)) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5265 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "host", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5266 | EXPECT_EQ("192.0.4.102", host->getIPv4Reservation().toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.4.102\"" , "host->getIPv4Reservation().toText()", "192.0.4.102", host ->getIPv4Reservation().toText()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5266, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5267 | ||||
| 5268 | // This reservation must not belong to other subnets. | |||
| 5269 | EXPECT_FALSE(hosts_cfg->get4(123, Host::IDENT_CIRCUIT_ID,switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 123, Host::IDENT_CIRCUIT_ID, &circuit_id[0], circuit_id.size ())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5270, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(123, Host::IDENT_CIRCUIT_ID, &circuit_id[0], circuit_id.size())" , "true", "false") .c_str()) = ::testing::Message() | |||
| 5270 | &circuit_id[0], circuit_id.size()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 123, Host::IDENT_CIRCUIT_ID, &circuit_id[0], circuit_id.size ())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5270, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(123, Host::IDENT_CIRCUIT_ID, &circuit_id[0], circuit_id.size())" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 5271 | EXPECT_FALSE(hosts_cfg->get4(234, Host::IDENT_CIRCUIT_ID,switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 234, Host::IDENT_CIRCUIT_ID, &circuit_id[0], circuit_id.size ())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5272, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(234, Host::IDENT_CIRCUIT_ID, &circuit_id[0], circuit_id.size())" , "true", "false") .c_str()) = ::testing::Message() | |||
| 5272 | &circuit_id[0], circuit_id.size()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 234, Host::IDENT_CIRCUIT_ID, &circuit_id[0], circuit_id.size ())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5272, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(234, Host::IDENT_CIRCUIT_ID, &circuit_id[0], circuit_id.size())" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 5273 | ||||
| 5274 | // Repeat the test for the DUID based reservation in this subnet. | |||
| 5275 | std::vector<uint8_t> duid_r(duid.rbegin(), duid.rend()); | |||
| 5276 | host = hosts_cfg->get4(542, Host::IDENT_DUID, &duid_r[0], duid_r.size()); | |||
| 5277 | ASSERT_TRUE(host)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(host)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5277 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "host", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5278 | EXPECT_EQ("192.0.4.101", host->getIPv4Reservation().toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.4.101\"" , "host->getIPv4Reservation().toText()", "192.0.4.101", host ->getIPv4Reservation().toText()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5278, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5279 | ||||
| 5280 | EXPECT_FALSE(hosts_cfg->get4(123, Host::IDENT_DUID,switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 123, Host::IDENT_DUID, &duid_r[0], duid_r.size())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5281, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(123, Host::IDENT_DUID, &duid_r[0], duid_r.size())" , "true", "false") .c_str()) = ::testing::Message() | |||
| 5281 | &duid_r[0], duid_r.size()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 123, Host::IDENT_DUID, &duid_r[0], duid_r.size())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5281, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(123, Host::IDENT_DUID, &duid_r[0], duid_r.size())" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 5282 | EXPECT_FALSE(hosts_cfg->get4(234, Host::IDENT_DUID,switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 234, Host::IDENT_DUID, &duid_r[0], duid_r.size())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5283, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(234, Host::IDENT_DUID, &duid_r[0], duid_r.size())" , "true", "false") .c_str()) = ::testing::Message() | |||
| 5283 | &duid_r[0], duid_r.size()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 234, Host::IDENT_DUID, &duid_r[0], duid_r.size())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5283, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(234, Host::IDENT_DUID, &duid_r[0], duid_r.size())" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 5284 | // Check that options are assigned correctly. | |||
| 5285 | opt_dns = retrieveOption<Option4AddrLstPtr>(*host, DHO_NAME_SERVERS); | |||
| 5286 | ASSERT_TRUE(opt_dns)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(opt_dns)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5286, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "opt_dns", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 5287 | dns_addrs = opt_dns->getAddresses(); | |||
| 5288 | ASSERT_EQ(1, dns_addrs.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "dns_addrs.size()" , 1, dns_addrs.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5288, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5289 | EXPECT_EQ("192.0.4.11", dns_addrs[0].toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.4.11\"" , "dns_addrs[0].toText()", "192.0.4.11", dns_addrs[0].toText( )))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5289, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5290 | opt_ttl = retrieveOption<OptionUint8Ptr>(*host, DHO_DEFAULT_IP_TTL); | |||
| 5291 | ASSERT_TRUE(opt_ttl)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(opt_ttl)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5291, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "opt_ttl", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 5292 | EXPECT_EQ(95, static_cast<int>(opt_ttl->getValue()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("95", "static_cast<int>(opt_ttl->getValue())" , 95, static_cast<int>(opt_ttl->getValue())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5292, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5293 | ||||
| 5294 | // Check that we can find reservation using client identifier. | |||
| 5295 | ClientIdPtr client_id = ClientId::fromText("05:01:02:03:04:05:06"); | |||
| 5296 | host = hosts_cfg->get4(542, Host::IDENT_CLIENT_ID, &client_id->getClientId()[0], | |||
| 5297 | client_id->getClientId().size()); | |||
| 5298 | ASSERT_TRUE(host)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(host)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5298 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "host", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5299 | EXPECT_EQ("192.0.4.103", host->getIPv4Reservation().toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.4.103\"" , "host->getIPv4Reservation().toText()", "192.0.4.103", host ->getIPv4Reservation().toText()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5299, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5300 | ||||
| 5301 | // But this reservation should not be returned for other subnet. | |||
| 5302 | host = hosts_cfg->get4(234, Host::IDENT_CLIENT_ID, &client_id->getClientId()[0], | |||
| 5303 | client_id->getClientId().size()); | |||
| 5304 | EXPECT_FALSE(host)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(host))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5304 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "host", "true", "false") .c_str()) = ::testing::Message(); | |||
| 5305 | } | |||
| 5306 | ||||
| 5307 | // This test checks that it is possible to configure option data for a | |||
| 5308 | // host using a user defined option format. | |||
| 5309 | TEST_F(Dhcp4ParserTest, reservationWithOptionDefinition)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("reservationWithOptionDefinition") > 1, "test_name must not be empty"); class Dhcp4ParserTest_reservationWithOptionDefinition_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_reservationWithOptionDefinition_Test () = default; ~Dhcp4ParserTest_reservationWithOptionDefinition_Test () override = default; Dhcp4ParserTest_reservationWithOptionDefinition_Test (const Dhcp4ParserTest_reservationWithOptionDefinition_Test & ) = delete; Dhcp4ParserTest_reservationWithOptionDefinition_Test & operator=( const Dhcp4ParserTest_reservationWithOptionDefinition_Test &) = delete; Dhcp4ParserTest_reservationWithOptionDefinition_Test (Dhcp4ParserTest_reservationWithOptionDefinition_Test && ) noexcept = delete; Dhcp4ParserTest_reservationWithOptionDefinition_Test & operator=( Dhcp4ParserTest_reservationWithOptionDefinition_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_reservationWithOptionDefinition_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "reservationWithOptionDefinition", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5309), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5309), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5309), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_reservationWithOptionDefinition_Test >); void Dhcp4ParserTest_reservationWithOptionDefinition_Test ::TestBody() { | |||
| 5310 | ConstElementPtr x; | |||
| 5311 | // The following configuration contains host declaration in which | |||
| 5312 | // a non-standard option is used. This option has option definition | |||
| 5313 | // specified in the configuration. | |||
| 5314 | string config = "{ " + genIfaceConfig() + "," | |||
| 5315 | "\"rebind-timer\": 2000, " | |||
| 5316 | "\"renew-timer\": 1000, " | |||
| 5317 | "\"option-def\": [ {" | |||
| 5318 | " \"name\": \"foo\"," | |||
| 5319 | " \"code\": 100," | |||
| 5320 | " \"type\": \"uint32\"," | |||
| 5321 | " \"space\": \"isc\"" | |||
| 5322 | "} ]," | |||
| 5323 | "\"subnet4\": [ " | |||
| 5324 | " {" | |||
| 5325 | " \"reservations\": [" | |||
| 5326 | " {" | |||
| 5327 | " \"duid\": \"01:02:03:04:05:06:07:08:09:0A\"," | |||
| 5328 | " \"ip-address\": \"192.0.3.112\"," | |||
| 5329 | " \"option-data\": [" | |||
| 5330 | " {" | |||
| 5331 | " \"name\": \"foo\"," | |||
| 5332 | " \"data\": \"123\"," | |||
| 5333 | " \"space\": \"isc\"" | |||
| 5334 | " }" | |||
| 5335 | " ]" | |||
| 5336 | " }" | |||
| 5337 | " ]," | |||
| 5338 | " \"pools\": [ { \"pool\": \"192.0.3.101 - 192.0.3.150\" } ]," | |||
| 5339 | " \"subnet\": \"192.0.3.0/24\", " | |||
| 5340 | " \"id\": 234" | |||
| 5341 | " }" | |||
| 5342 | "]," | |||
| 5343 | "\"valid-lifetime\": 4000 }"; | |||
| 5344 | ||||
| 5345 | ConstElementPtr json; | |||
| 5346 | ASSERT_NO_THROW(json = parseDHCP4(config, true))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(config, 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_5346 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5346 ; } } else gtest_label_testnothrow_5346 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5346, ("Expected: " "json = parseDHCP4(config, true)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5347 | extractConfig(config); | |||
| 5348 | ||||
| 5349 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5349; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5349; } } else gtest_label_testnothrow_5349 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5349, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5350 | checkResult(x, 0); | |||
| 5351 | ||||
| 5352 | // Hosts configuration must be available. | |||
| 5353 | CfgHostsPtr hosts_cfg = CfgMgr::instance().getStagingCfg()->getCfgHosts(); | |||
| 5354 | ASSERT_TRUE(hosts_cfg)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(hosts_cfg)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5354, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg", "false", "true") .c_str()) = ::testing::Message (); | |||
| 5355 | ||||
| 5356 | // Let's create an object holding DUID of the host. For simplicity the | |||
| 5357 | // address is a collection of numbers from 1 to A. | |||
| 5358 | std::vector<uint8_t> duid; | |||
| 5359 | for (unsigned int i = 1; i < 0xB; ++i) { | |||
| 5360 | duid.push_back(static_cast<uint8_t>(i)); | |||
| 5361 | } | |||
| 5362 | // Retrieve the reservation and sanity check the address reserved. | |||
| 5363 | ConstHostPtr host = hosts_cfg->get4(234, Host::IDENT_DUID, | |||
| 5364 | &duid[0], duid.size()); | |||
| 5365 | ASSERT_TRUE(host)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(host)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5365 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "host", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5366 | EXPECT_EQ("192.0.3.112", host->getIPv4Reservation().toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.3.112\"" , "host->getIPv4Reservation().toText()", "192.0.3.112", host ->getIPv4Reservation().toText()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5366, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5367 | ||||
| 5368 | // Check if the option has been parsed. | |||
| 5369 | OptionUint32Ptr opt_foo = retrieveOption<OptionUint32Ptr>(*host, "isc", | |||
| 5370 | 100); | |||
| 5371 | ASSERT_TRUE(opt_foo)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(opt_foo)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5371, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "opt_foo", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 5372 | EXPECT_EQ(100, opt_foo->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("100", "opt_foo->getType()" , 100, opt_foo->getType()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5372, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5373 | EXPECT_EQ(123, opt_foo->getValue())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("123", "opt_foo->getValue()" , 123, opt_foo->getValue()))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5373, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5374 | } | |||
| 5375 | ||||
| 5376 | // This test verifies that the bogus host reservation would trigger a | |||
| 5377 | // server configuration error. | |||
| 5378 | TEST_F(Dhcp4ParserTest, reservationBogus)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("reservationBogus") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_reservationBogus_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_reservationBogus_Test() = default; ~Dhcp4ParserTest_reservationBogus_Test() override = default; Dhcp4ParserTest_reservationBogus_Test (const Dhcp4ParserTest_reservationBogus_Test &) = delete; Dhcp4ParserTest_reservationBogus_Test & operator=( const Dhcp4ParserTest_reservationBogus_Test & ) = delete; Dhcp4ParserTest_reservationBogus_Test (Dhcp4ParserTest_reservationBogus_Test &&) noexcept = delete; Dhcp4ParserTest_reservationBogus_Test & operator=( Dhcp4ParserTest_reservationBogus_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_reservationBogus_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "reservationBogus", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5378), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5378), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5378), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_reservationBogus_Test >); void Dhcp4ParserTest_reservationBogus_Test::TestBody() { | |||
| 5379 | // Case 1: misspelled hw-address parameter. | |||
| 5380 | ConstElementPtr x; | |||
| 5381 | string config = "{ " + genIfaceConfig() + "," | |||
| 5382 | "\"rebind-timer\": 2000, " | |||
| 5383 | "\"renew-timer\": 1000, " | |||
| 5384 | "\"subnet4\": [ " | |||
| 5385 | " { " | |||
| 5386 | " \"pools\": [ { \"pool\": \"192.0.4.101 - 192.0.4.150\" } ]," | |||
| 5387 | " \"subnet\": \"192.0.4.0/24\"," | |||
| 5388 | " \"id\": 542," | |||
| 5389 | " \"reservations\": [" | |||
| 5390 | " {" | |||
| 5391 | " \"hw-addre\": \"06:05:04:03:02:01\"," | |||
| 5392 | " \"ip-address\": \"192.0.4.102\"," | |||
| 5393 | " \"hostname\": \"\"" | |||
| 5394 | " }" | |||
| 5395 | " ]" | |||
| 5396 | " } " | |||
| 5397 | "], " | |||
| 5398 | "\"valid-lifetime\": 4000 }"; | |||
| 5399 | ||||
| 5400 | ConstElementPtr json; | |||
| 5401 | ASSERT_NO_THROW(json = parseJSON(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseJSON(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_5401 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5401 ; } } else gtest_label_testnothrow_5401 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5401, ("Expected: " "json = parseJSON(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5402 | ||||
| 5403 | CfgMgr::instance().clear(); | |||
| 5404 | ||||
| 5405 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5405; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5405; } } else gtest_label_testnothrow_5405 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5405, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5406 | checkResult(x, 1); | |||
| 5407 | ||||
| 5408 | EXPECT_THROW(parseDHCP4(config), Dhcp4ParseError)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { parseDHCP4(config); } else static_assert(true, ""); } catch (Dhcp4ParseError const& ) { gtest_caught_expected = true; } catch (typename std::conditional < std::is_same<typename std::remove_cv<typename std:: remove_reference< Dhcp4ParseError>::type>::type, std ::exception>::value, const ::testing::internal::NeverThrown &, const std::exception&>::type e) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\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_5408; } catch (... ) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_5408; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws nothing."; goto gtest_label_testthrow_5408 ; } } else gtest_label_testthrow_5408 : ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5408, gtest_msg.value.c_str()) = ::testing::Message(); | |||
| 5409 | ||||
| 5410 | // Case 2: DUID and HW Address both specified. | |||
| 5411 | config = "{ " + genIfaceConfig() + "," | |||
| 5412 | "\"rebind-timer\": 2000, " | |||
| 5413 | "\"renew-timer\": 1000, " | |||
| 5414 | "\"subnet4\": [ " | |||
| 5415 | " { " | |||
| 5416 | " \"pools\": [ { \"pool\": \"192.0.4.101 - 192.0.4.150\" } ]," | |||
| 5417 | " \"subnet\": \"192.0.4.0/24\"," | |||
| 5418 | " \"id\": 542," | |||
| 5419 | " \"reservations\": [" | |||
| 5420 | " {" | |||
| 5421 | " \"duid\": \"01:02:03:04:05:06\"," | |||
| 5422 | " \"hw-address\": \"06:05:04:03:02:01\"," | |||
| 5423 | " \"ip-address\": \"192.0.4.102\"," | |||
| 5424 | " \"hostname\": \"\"" | |||
| 5425 | " }" | |||
| 5426 | " ]" | |||
| 5427 | " } ]," | |||
| 5428 | "\"valid-lifetime\": 4000 }"; | |||
| 5429 | ||||
| 5430 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_5430 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5430 ; } } else gtest_label_testnothrow_5430 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5430, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5431 | ||||
| 5432 | // Remove existing configuration, if any. | |||
| 5433 | CfgMgr::instance().clear(); | |||
| 5434 | ||||
| 5435 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5435; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5435; } } else gtest_label_testnothrow_5435 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5435, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5436 | checkResult(x, 1); | |||
| 5437 | ||||
| 5438 | // Case 3: Broken specification of option data. | |||
| 5439 | config = "{ " + genIfaceConfig() + "," | |||
| 5440 | "\"rebind-timer\": 2000, " | |||
| 5441 | "\"renew-timer\": 1000, " | |||
| 5442 | "\"subnet4\": [ " | |||
| 5443 | " { " | |||
| 5444 | " \"pools\": [ { \"pool\": \"192.0.4.101 - 192.0.4.150\" } ]," | |||
| 5445 | " \"subnet\": \"192.0.4.0/24\"," | |||
| 5446 | " \"id\": 542," | |||
| 5447 | " \"reservations\": [" | |||
| 5448 | " {" | |||
| 5449 | " \"hw-address\": \"06:05:04:03:02:01\"," | |||
| 5450 | " \"option-data\": [" | |||
| 5451 | " {" | |||
| 5452 | " \"name\": \"name-servers\"," | |||
| 5453 | " \"data\": \"bogus-ip-address\"" | |||
| 5454 | " }" | |||
| 5455 | " ]" | |||
| 5456 | " }" | |||
| 5457 | " ]" | |||
| 5458 | " } " | |||
| 5459 | "], " | |||
| 5460 | "\"valid-lifetime\": 4000 }"; | |||
| 5461 | ||||
| 5462 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_5462 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5462 ; } } else gtest_label_testnothrow_5462 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5462, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5463 | ||||
| 5464 | // Remove existing configuration, if any. | |||
| 5465 | CfgMgr::instance().clear(); | |||
| 5466 | ||||
| 5467 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5467; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5467; } } else gtest_label_testnothrow_5467 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5467, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5468 | checkResult(x, 1); | |||
| 5469 | } | |||
| 5470 | ||||
| 5471 | /// The goal of this test is to verify that Host Reservation flags can be | |||
| 5472 | /// specified on a per-subnet basis. | |||
| 5473 | TEST_F(Dhcp4ParserTest, hostReservationPerSubnet)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("hostReservationPerSubnet") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_hostReservationPerSubnet_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_hostReservationPerSubnet_Test () = default; ~Dhcp4ParserTest_hostReservationPerSubnet_Test( ) override = default; Dhcp4ParserTest_hostReservationPerSubnet_Test (const Dhcp4ParserTest_hostReservationPerSubnet_Test &) = delete; Dhcp4ParserTest_hostReservationPerSubnet_Test & operator =( const Dhcp4ParserTest_hostReservationPerSubnet_Test &) = delete; Dhcp4ParserTest_hostReservationPerSubnet_Test (Dhcp4ParserTest_hostReservationPerSubnet_Test &&) noexcept = delete; Dhcp4ParserTest_hostReservationPerSubnet_Test & operator=( Dhcp4ParserTest_hostReservationPerSubnet_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_hostReservationPerSubnet_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "hostReservationPerSubnet", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5473), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5473), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5473), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_hostReservationPerSubnet_Test >); void Dhcp4ParserTest_hostReservationPerSubnet_Test::TestBody () { | |||
| 5474 | ||||
| 5475 | /// - Configuration: | |||
| 5476 | /// - only addresses (no prefixes) | |||
| 5477 | /// - 7 subnets with: | |||
| 5478 | /// - 192.0.1.0/24 (all reservations enabled) | |||
| 5479 | /// - 192.0.2.0/24 (out-of-pool reservations) | |||
| 5480 | /// - 192.0.3.0/24 (reservations disabled) | |||
| 5481 | /// - 192.0.4.0/24 (global reservations) | |||
| 5482 | /// - 192.0.5.0/24 (reservations not specified) | |||
| 5483 | /// - 192.0.6.0/24 (global + all enabled) | |||
| 5484 | /// - 192.0.7.0/24 (global + out-of-pool enabled) | |||
| 5485 | const char* hr_config = | |||
| 5486 | "{" | |||
| 5487 | "\"rebind-timer\": 2000, " | |||
| 5488 | "\"renew-timer\": 1000, " | |||
| 5489 | "\"subnet4\": [ { " | |||
| 5490 | " \"id\": 1," | |||
| 5491 | " \"pools\": [ { \"pool\": \"192.0.1.0/24\" } ]," | |||
| 5492 | " \"subnet\": \"192.0.1.0/24\", " | |||
| 5493 | " \"reservations-global\": false," | |||
| 5494 | " \"reservations-in-subnet\": true," | |||
| 5495 | " \"reservations-out-of-pool\": false" | |||
| 5496 | " }," | |||
| 5497 | " {" | |||
| 5498 | " \"id\": 2," | |||
| 5499 | " \"pools\": [ { \"pool\": \"192.0.2.0/24\" } ]," | |||
| 5500 | " \"subnet\": \"192.0.2.0/24\", " | |||
| 5501 | " \"reservations-global\": false," | |||
| 5502 | " \"reservations-in-subnet\": true," | |||
| 5503 | " \"reservations-out-of-pool\": true" | |||
| 5504 | " }," | |||
| 5505 | " {" | |||
| 5506 | " \"id\": 3," | |||
| 5507 | " \"pools\": [ { \"pool\": \"192.0.3.0/24\" } ]," | |||
| 5508 | " \"subnet\": \"192.0.3.0/24\", " | |||
| 5509 | " \"reservations-global\": false," | |||
| 5510 | " \"reservations-in-subnet\": false" | |||
| 5511 | " }," | |||
| 5512 | " {" | |||
| 5513 | " \"id\": 4," | |||
| 5514 | " \"pools\": [ { \"pool\": \"192.0.4.0/24\" } ]," | |||
| 5515 | " \"subnet\": \"192.0.4.0/24\", " | |||
| 5516 | " \"reservations-global\": true," | |||
| 5517 | " \"reservations-in-subnet\": false" | |||
| 5518 | " }," | |||
| 5519 | " {" | |||
| 5520 | " \"id\": 5," | |||
| 5521 | " \"pools\": [ { \"pool\": \"192.0.5.0/24\" } ]," | |||
| 5522 | " \"subnet\": \"192.0.5.0/24\"" | |||
| 5523 | " }," | |||
| 5524 | " {" | |||
| 5525 | " \"id\": 6," | |||
| 5526 | " \"pools\": [ { \"pool\": \"192.0.6.0/24\" } ]," | |||
| 5527 | " \"subnet\": \"192.0.6.0/24\", " | |||
| 5528 | " \"reservations-global\": true," | |||
| 5529 | " \"reservations-in-subnet\": true," | |||
| 5530 | " \"reservations-out-of-pool\": false" | |||
| 5531 | " }," | |||
| 5532 | " {" | |||
| 5533 | " \"id\": 7," | |||
| 5534 | " \"pools\": [ { \"pool\": \"192.0.7.0/24\" } ]," | |||
| 5535 | " \"subnet\": \"192.0.7.0/24\", " | |||
| 5536 | " \"reservations-global\": true," | |||
| 5537 | " \"reservations-in-subnet\": true," | |||
| 5538 | " \"reservations-out-of-pool\": true" | |||
| 5539 | " } ]," | |||
| 5540 | "\"valid-lifetime\": 4000 }"; | |||
| 5541 | ||||
| 5542 | ConstElementPtr json; | |||
| 5543 | ASSERT_NO_THROW(json = parseDHCP4(hr_config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(hr_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_5543 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5543 ; } } else gtest_label_testnothrow_5543 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5543, ("Expected: " "json = parseDHCP4(hr_config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5544 | extractConfig(hr_config); | |||
| 5545 | ||||
| 5546 | ConstElementPtr status; | |||
| 5547 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5547; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5547; } } else gtest_label_testnothrow_5547 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5547, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5548 | ||||
| 5549 | // returned value should be 0 (success) | |||
| 5550 | checkResult(status, 0); | |||
| 5551 | CfgMgr::instance().commit(); | |||
| 5552 | ||||
| 5553 | // Let's get all subnets and check that there are 7 of them. | |||
| 5554 | ConstCfgSubnets4Ptr subnets = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4(); | |||
| 5555 | ASSERT_TRUE(subnets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnets)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5555, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnets", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 5556 | const Subnet4Collection* subnet_col = subnets->getAll(); | |||
| 5557 | ASSERT_EQ(7, subnet_col->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("7", "subnet_col->size()" , 7, subnet_col->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5557, gtest_ar.failure_message()) = ::testing::Message(); // We expect 7 subnets | |||
| 5558 | ||||
| 5559 | // Let's check if the parsed subnets have correct HR modes. | |||
| 5560 | ||||
| 5561 | // Subnet 1 | |||
| 5562 | ConstSubnet4Ptr subnet; | |||
| 5563 | subnet = subnets->selectSubnet(IOAddress("192.0.1.1")); | |||
| 5564 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5564, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5565 | EXPECT_FALSE(subnet->getReservationsGlobal())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getReservationsGlobal ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5565, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsGlobal()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 5566 | EXPECT_TRUE(subnet->getReservationsInSubnet())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->getReservationsInSubnet ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5566, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsInSubnet()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 5567 | EXPECT_FALSE(subnet->getReservationsOutOfPool())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getReservationsOutOfPool ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5567, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsOutOfPool()", "true", "false") . c_str()) = ::testing::Message(); | |||
| 5568 | ||||
| 5569 | // Subnet 2 | |||
| 5570 | subnet = subnets->selectSubnet(IOAddress("192.0.2.1")); | |||
| 5571 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5571, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5572 | EXPECT_FALSE(subnet->getReservationsGlobal())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getReservationsGlobal ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5572, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsGlobal()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 5573 | EXPECT_TRUE(subnet->getReservationsInSubnet())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->getReservationsInSubnet ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5573, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsInSubnet()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 5574 | EXPECT_TRUE(subnet->getReservationsOutOfPool())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->getReservationsOutOfPool ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5574, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsOutOfPool()", "false", "true") . c_str()) = ::testing::Message(); | |||
| 5575 | ||||
| 5576 | // Subnet 3 | |||
| 5577 | subnet = subnets->selectSubnet(IOAddress("192.0.3.1")); | |||
| 5578 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5578, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5579 | EXPECT_FALSE(subnet->getReservationsGlobal())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getReservationsGlobal ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5579, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsGlobal()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 5580 | EXPECT_FALSE(subnet->getReservationsInSubnet())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getReservationsInSubnet ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5580, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsInSubnet()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 5581 | EXPECT_FALSE(subnet->getReservationsOutOfPool())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getReservationsOutOfPool ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5581, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsOutOfPool()", "true", "false") . c_str()) = ::testing::Message(); | |||
| 5582 | ||||
| 5583 | // Subnet 4 | |||
| 5584 | subnet = subnets->selectSubnet(IOAddress("192.0.4.1")); | |||
| 5585 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5585, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5586 | EXPECT_TRUE(subnet->getReservationsGlobal())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->getReservationsGlobal ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5586, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsGlobal()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 5587 | EXPECT_FALSE(subnet->getReservationsInSubnet())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getReservationsInSubnet ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5587, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsInSubnet()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 5588 | EXPECT_FALSE(subnet->getReservationsOutOfPool())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getReservationsOutOfPool ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5588, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsOutOfPool()", "true", "false") . c_str()) = ::testing::Message(); | |||
| 5589 | ||||
| 5590 | // Subnet 5 | |||
| 5591 | subnet = subnets->selectSubnet(IOAddress("192.0.5.1")); | |||
| 5592 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5592, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5593 | EXPECT_FALSE(subnet->getReservationsGlobal())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getReservationsGlobal ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5593, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsGlobal()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 5594 | EXPECT_TRUE(subnet->getReservationsInSubnet())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->getReservationsInSubnet ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5594, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsInSubnet()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 5595 | EXPECT_FALSE(subnet->getReservationsOutOfPool())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getReservationsOutOfPool ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5595, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsOutOfPool()", "true", "false") . c_str()) = ::testing::Message(); | |||
| 5596 | ||||
| 5597 | // Subnet 6 | |||
| 5598 | subnet = subnets->selectSubnet(IOAddress("192.0.6.1")); | |||
| 5599 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5599, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5600 | EXPECT_TRUE(subnet->getReservationsGlobal())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->getReservationsGlobal ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5600, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsGlobal()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 5601 | EXPECT_TRUE(subnet->getReservationsInSubnet())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->getReservationsInSubnet ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5601, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsInSubnet()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 5602 | EXPECT_FALSE(subnet->getReservationsOutOfPool())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getReservationsOutOfPool ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5602, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsOutOfPool()", "true", "false") . c_str()) = ::testing::Message(); | |||
| 5603 | ||||
| 5604 | // Subnet 7 | |||
| 5605 | subnet = subnets->selectSubnet(IOAddress("192.0.7.1")); | |||
| 5606 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5606, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5607 | EXPECT_TRUE(subnet->getReservationsGlobal())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->getReservationsGlobal ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5607, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsGlobal()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 5608 | EXPECT_TRUE(subnet->getReservationsInSubnet())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->getReservationsInSubnet ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5608, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsInSubnet()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 5609 | EXPECT_TRUE(subnet->getReservationsOutOfPool())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->getReservationsOutOfPool ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5609, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsOutOfPool()", "false", "true") . c_str()) = ::testing::Message(); | |||
| 5610 | } | |||
| 5611 | ||||
| 5612 | /// The goal of this test is to verify that Host Reservation flags can be | |||
| 5613 | /// specified globally. | |||
| 5614 | TEST_F(Dhcp4ParserTest, hostReservationGlobal)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("hostReservationGlobal") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_hostReservationGlobal_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_hostReservationGlobal_Test() = default ; ~Dhcp4ParserTest_hostReservationGlobal_Test() override = default ; Dhcp4ParserTest_hostReservationGlobal_Test (const Dhcp4ParserTest_hostReservationGlobal_Test &) = delete; Dhcp4ParserTest_hostReservationGlobal_Test & operator=( const Dhcp4ParserTest_hostReservationGlobal_Test & ) = delete; Dhcp4ParserTest_hostReservationGlobal_Test (Dhcp4ParserTest_hostReservationGlobal_Test &&) noexcept = delete; Dhcp4ParserTest_hostReservationGlobal_Test & operator=( Dhcp4ParserTest_hostReservationGlobal_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_hostReservationGlobal_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "hostReservationGlobal", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5614), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5614), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5614), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_hostReservationGlobal_Test >); void Dhcp4ParserTest_hostReservationGlobal_Test::TestBody () { | |||
| 5615 | ||||
| 5616 | /// - Configuration: | |||
| 5617 | /// - only addresses (no prefixes) | |||
| 5618 | /// - 2 subnets with : | |||
| 5619 | /// - 192.0.2.0/24 (all reservations enabled) | |||
| 5620 | /// - 192.0.3.0/24 (reservations not specified) | |||
| 5621 | const char* hr_config = | |||
| 5622 | "{" | |||
| 5623 | "\"rebind-timer\": 2000, " | |||
| 5624 | "\"renew-timer\": 1000, " | |||
| 5625 | "\"reservations-global\": false," | |||
| 5626 | "\"reservations-in-subnet\": true," | |||
| 5627 | "\"reservations-out-of-pool\": true," | |||
| 5628 | "\"subnet4\": [ { " | |||
| 5629 | " \"id\": 1," | |||
| 5630 | " \"pools\": [ { \"pool\": \"192.0.2.0/24\" } ]," | |||
| 5631 | " \"subnet\": \"192.0.2.0/24\", " | |||
| 5632 | " \"reservations-global\": false," | |||
| 5633 | " \"reservations-in-subnet\": true," | |||
| 5634 | " \"reservations-out-of-pool\": false" | |||
| 5635 | " }," | |||
| 5636 | " {" | |||
| 5637 | " \"id\": 2," | |||
| 5638 | " \"pools\": [ { \"pool\": \"192.0.3.0/24\" } ]," | |||
| 5639 | " \"subnet\": \"192.0.3.0/24\"" | |||
| 5640 | " } ]," | |||
| 5641 | "\"valid-lifetime\": 4000 }"; | |||
| 5642 | ||||
| 5643 | ConstElementPtr json; | |||
| 5644 | ASSERT_NO_THROW(json = parseDHCP4(hr_config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(hr_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_5644 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5644 ; } } else gtest_label_testnothrow_5644 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5644, ("Expected: " "json = parseDHCP4(hr_config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5645 | extractConfig(hr_config); | |||
| 5646 | ||||
| 5647 | ConstElementPtr status; | |||
| 5648 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5648; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5648; } } else gtest_label_testnothrow_5648 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5648, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5649 | ||||
| 5650 | // returned value should be 0 (success) | |||
| 5651 | checkResult(status, 0); | |||
| 5652 | CfgMgr::instance().commit(); | |||
| 5653 | ||||
| 5654 | // Let's get all subnets and check that there are 4 of them. | |||
| 5655 | ConstCfgSubnets4Ptr subnets = CfgMgr::instance().getCurrentCfg()->getCfgSubnets4(); | |||
| 5656 | ASSERT_TRUE(subnets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnets)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5656, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnets", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 5657 | const Subnet4Collection* subnet_col = subnets->getAll(); | |||
| 5658 | ASSERT_EQ(2, subnet_col->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "subnet_col->size()" , 2, subnet_col->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5658, gtest_ar.failure_message()) = ::testing::Message(); // We expect 2 subnets | |||
| 5659 | ||||
| 5660 | // Let's check if the parsed subnets have correct HR modes. | |||
| 5661 | ||||
| 5662 | // Subnet 1 | |||
| 5663 | ConstSubnet4Ptr subnet; | |||
| 5664 | subnet = subnets->selectSubnet(IOAddress("192.0.2.1")); | |||
| 5665 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5665, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5666 | EXPECT_FALSE(subnet->getReservationsGlobal())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getReservationsGlobal ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5666, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsGlobal()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 5667 | EXPECT_TRUE(subnet->getReservationsInSubnet())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->getReservationsInSubnet ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5667, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsInSubnet()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 5668 | EXPECT_FALSE(subnet->getReservationsOutOfPool())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getReservationsOutOfPool ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5668, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsOutOfPool()", "true", "false") . c_str()) = ::testing::Message(); | |||
| 5669 | ||||
| 5670 | // Subnet 2 | |||
| 5671 | subnet = subnets->selectSubnet(IOAddress("192.0.3.1")); | |||
| 5672 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5672, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5673 | EXPECT_FALSE(subnet->getReservationsGlobal())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getReservationsGlobal ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5673, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsGlobal()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 5674 | EXPECT_TRUE(subnet->getReservationsInSubnet())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->getReservationsInSubnet ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5674, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsInSubnet()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 5675 | EXPECT_TRUE(subnet->getReservationsOutOfPool())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet->getReservationsOutOfPool ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5675, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getReservationsOutOfPool()", "false", "true") . c_str()) = ::testing::Message(); | |||
| 5676 | } | |||
| 5677 | ||||
| 5678 | /// Check that the decline-probation-period has a default value when not | |||
| 5679 | /// specified. | |||
| 5680 | TEST_F(Dhcp4ParserTest, declineTimerDefault)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("declineTimerDefault") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_declineTimerDefault_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_declineTimerDefault_Test() = default ; ~Dhcp4ParserTest_declineTimerDefault_Test() override = default ; Dhcp4ParserTest_declineTimerDefault_Test (const Dhcp4ParserTest_declineTimerDefault_Test &) = delete; Dhcp4ParserTest_declineTimerDefault_Test & operator=( const Dhcp4ParserTest_declineTimerDefault_Test & ) = delete; Dhcp4ParserTest_declineTimerDefault_Test (Dhcp4ParserTest_declineTimerDefault_Test &&) noexcept = delete; Dhcp4ParserTest_declineTimerDefault_Test & operator=( Dhcp4ParserTest_declineTimerDefault_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_declineTimerDefault_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "declineTimerDefault", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5680), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5680), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5680), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_declineTimerDefault_Test >); void Dhcp4ParserTest_declineTimerDefault_Test::TestBody () { | |||
| 5681 | ||||
| 5682 | string config = "{ " + genIfaceConfig() + "," | |||
| 5683 | "\"subnet4\": [ ] " | |||
| 5684 | "}"; | |||
| 5685 | ||||
| 5686 | ConstElementPtr json; | |||
| 5687 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_5687 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5687 ; } } else gtest_label_testnothrow_5687 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5687, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5688 | extractConfig(config); | |||
| 5689 | ||||
| 5690 | ConstElementPtr status; | |||
| 5691 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5691; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5691; } } else gtest_label_testnothrow_5691 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5691, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5692 | ||||
| 5693 | // returned value should be 0 (success) | |||
| 5694 | checkResult(status, 0); | |||
| 5695 | ||||
| 5696 | // The value of decline-probation-period must be equal to the | |||
| 5697 | // default value (86400). The default value is defined in GLOBAL4_DEFAULTS in | |||
| 5698 | // simple_parser4.cc. | |||
| 5699 | EXPECT_EQ(86400, CfgMgr::instance().getStagingCfg()->getDeclinePeriod())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("86400", "CfgMgr::instance().getStagingCfg()->getDeclinePeriod()" , 86400, CfgMgr::instance().getStagingCfg()->getDeclinePeriod ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5699, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5700 | } | |||
| 5701 | ||||
| 5702 | /// Check that the dhcp4o6-port default value has a default value if not | |||
| 5703 | /// specified explicitly. | |||
| 5704 | TEST_F(Dhcp4ParserTest, dhcp4o6portDefault)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("dhcp4o6portDefault") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_dhcp4o6portDefault_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_dhcp4o6portDefault_Test() = default ; ~Dhcp4ParserTest_dhcp4o6portDefault_Test() override = default ; Dhcp4ParserTest_dhcp4o6portDefault_Test (const Dhcp4ParserTest_dhcp4o6portDefault_Test &) = delete; Dhcp4ParserTest_dhcp4o6portDefault_Test & operator=( const Dhcp4ParserTest_dhcp4o6portDefault_Test & ) = delete; Dhcp4ParserTest_dhcp4o6portDefault_Test (Dhcp4ParserTest_dhcp4o6portDefault_Test &&) noexcept = delete; Dhcp4ParserTest_dhcp4o6portDefault_Test & operator=( Dhcp4ParserTest_dhcp4o6portDefault_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_dhcp4o6portDefault_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "dhcp4o6portDefault", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5704), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5704), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5704), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_dhcp4o6portDefault_Test >); void Dhcp4ParserTest_dhcp4o6portDefault_Test::TestBody () { | |||
| 5705 | ||||
| 5706 | string config_txt = "{ " + genIfaceConfig() + "," | |||
| 5707 | "\"subnet4\": [ ] " | |||
| 5708 | "}"; | |||
| 5709 | ConstElementPtr config; | |||
| 5710 | ASSERT_NO_THROW(config = parseDHCP4(config_txt))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { config = parseDHCP4(config_txt); } else static_assert(true, "" ); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5710 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5710 ; } } else gtest_label_testnothrow_5710 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5710, ("Expected: " "config = parseDHCP4(config_txt)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5711 | extractConfig(config_txt); | |||
| 5712 | ||||
| 5713 | ConstElementPtr status; | |||
| 5714 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, 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_5714; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5714; } } else gtest_label_testnothrow_5714 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5714, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5715 | ||||
| 5716 | // returned value should be 0 (success) | |||
| 5717 | checkResult(status, 0); | |||
| 5718 | ||||
| 5719 | // The value of decline-probation-period must be equal to the | |||
| 5720 | // default value (0). The default value is defined in GLOBAL4_DEFAULTS in | |||
| 5721 | // simple_parser4.cc. | |||
| 5722 | EXPECT_EQ(0, CfgMgr::instance().getStagingCfg()->getDhcp4o6Port())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "CfgMgr::instance().getStagingCfg()->getDhcp4o6Port()" , 0, CfgMgr::instance().getStagingCfg()->getDhcp4o6Port()) )) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5722, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5723 | } | |||
| 5724 | ||||
| 5725 | /// Check that the decline-probation-period value can be set properly. | |||
| 5726 | TEST_F(Dhcp4ParserTest, declineTimer)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("declineTimer") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_declineTimer_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_declineTimer_Test() = default; ~Dhcp4ParserTest_declineTimer_Test () override = default; Dhcp4ParserTest_declineTimer_Test (const Dhcp4ParserTest_declineTimer_Test &) = delete; Dhcp4ParserTest_declineTimer_Test & operator=( const Dhcp4ParserTest_declineTimer_Test & ) = delete; Dhcp4ParserTest_declineTimer_Test (Dhcp4ParserTest_declineTimer_Test &&) noexcept = delete; Dhcp4ParserTest_declineTimer_Test & operator=( Dhcp4ParserTest_declineTimer_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_declineTimer_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "declineTimer", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5726 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5726), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5726), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_declineTimer_Test >); void Dhcp4ParserTest_declineTimer_Test::TestBody() { | |||
| 5727 | string config = "{ " + genIfaceConfig() + "," | |||
| 5728 | "\"decline-probation-period\": 12345," | |||
| 5729 | "\"subnet4\": [ ]" | |||
| 5730 | "}"; | |||
| 5731 | ||||
| 5732 | ConstElementPtr json; | |||
| 5733 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_5733 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5733 ; } } else gtest_label_testnothrow_5733 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5733, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5734 | extractConfig(config); | |||
| 5735 | ||||
| 5736 | ConstElementPtr status; | |||
| 5737 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5737; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5737; } } else gtest_label_testnothrow_5737 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5737, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5738 | ||||
| 5739 | // returned value should be 0 (success) | |||
| 5740 | checkResult(status, 0); | |||
| 5741 | ||||
| 5742 | // The value of decline-probation-period must be equal to the | |||
| 5743 | // value specified. | |||
| 5744 | EXPECT_EQ(12345,switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("12345", "CfgMgr::instance().getStagingCfg()->getDeclinePeriod()" , 12345, CfgMgr::instance().getStagingCfg()->getDeclinePeriod ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5745, gtest_ar.failure_message()) = ::testing::Message() | |||
| 5745 | CfgMgr::instance().getStagingCfg()->getDeclinePeriod())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("12345", "CfgMgr::instance().getStagingCfg()->getDeclinePeriod()" , 12345, CfgMgr::instance().getStagingCfg()->getDeclinePeriod ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5745, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5746 | } | |||
| 5747 | ||||
| 5748 | /// Check that an incorrect decline-probation-period value will be caught. | |||
| 5749 | TEST_F(Dhcp4ParserTest, declineTimerError)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("declineTimerError") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_declineTimerError_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_declineTimerError_Test() = default ; ~Dhcp4ParserTest_declineTimerError_Test() override = default ; Dhcp4ParserTest_declineTimerError_Test (const Dhcp4ParserTest_declineTimerError_Test &) = delete; Dhcp4ParserTest_declineTimerError_Test & operator=( const Dhcp4ParserTest_declineTimerError_Test & ) = delete; Dhcp4ParserTest_declineTimerError_Test (Dhcp4ParserTest_declineTimerError_Test &&) noexcept = delete; Dhcp4ParserTest_declineTimerError_Test & operator=( Dhcp4ParserTest_declineTimerError_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_declineTimerError_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "declineTimerError", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5749), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5749), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5749), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_declineTimerError_Test >); void Dhcp4ParserTest_declineTimerError_Test::TestBody( ) { | |||
| 5750 | string config = "{ " + genIfaceConfig() + "," | |||
| 5751 | "\"decline-probation-period\": \"soon\"," | |||
| 5752 | "\"subnet4\": [ ]" | |||
| 5753 | "}"; | |||
| 5754 | ||||
| 5755 | ConstElementPtr json; | |||
| 5756 | ASSERT_NO_THROW(json = parseJSON(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseJSON(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_5756 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5756 ; } } else gtest_label_testnothrow_5756 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5756, ("Expected: " "json = parseJSON(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5757 | ||||
| 5758 | ConstElementPtr status; | |||
| 5759 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5759; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5759; } } else gtest_label_testnothrow_5759 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5759, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5760 | ||||
| 5761 | // returned value should be 1 (error) | |||
| 5762 | checkResult(status, 1); | |||
| 5763 | ||||
| 5764 | // Check that the error contains error position. | |||
| 5765 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5765, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 5766 | ||||
| 5767 | // Check that the Dhcp4 parser catches the type error | |||
| 5768 | EXPECT_THROW(parseDHCP4(config), Dhcp4ParseError)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { parseDHCP4(config); } else static_assert(true, ""); } catch (Dhcp4ParseError const& ) { gtest_caught_expected = true; } catch (typename std::conditional < std::is_same<typename std::remove_cv<typename std:: remove_reference< Dhcp4ParseError>::type>::type, std ::exception>::value, const ::testing::internal::NeverThrown &, const std::exception&>::type e) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\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_5768; } catch (... ) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_5768; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws nothing."; goto gtest_label_testthrow_5768 ; } } else gtest_label_testthrow_5768 : ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5768, gtest_msg.value.c_str()) = ::testing::Message(); | |||
| 5769 | } | |||
| 5770 | ||||
| 5771 | // Check that configuration for the expired leases processing may be | |||
| 5772 | // specified. | |||
| 5773 | TEST_F(Dhcp4ParserTest, expiredLeasesProcessing)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("expiredLeasesProcessing") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_expiredLeasesProcessing_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_expiredLeasesProcessing_Test () = default; ~Dhcp4ParserTest_expiredLeasesProcessing_Test() override = default; Dhcp4ParserTest_expiredLeasesProcessing_Test (const Dhcp4ParserTest_expiredLeasesProcessing_Test &) = delete; Dhcp4ParserTest_expiredLeasesProcessing_Test & operator =( const Dhcp4ParserTest_expiredLeasesProcessing_Test &) = delete; Dhcp4ParserTest_expiredLeasesProcessing_Test (Dhcp4ParserTest_expiredLeasesProcessing_Test &&) noexcept = delete; Dhcp4ParserTest_expiredLeasesProcessing_Test & operator=( Dhcp4ParserTest_expiredLeasesProcessing_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_expiredLeasesProcessing_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "expiredLeasesProcessing", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5773), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5773), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5773), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_expiredLeasesProcessing_Test >); void Dhcp4ParserTest_expiredLeasesProcessing_Test::TestBody () { | |||
| 5774 | // Create basic configuration with the expiration specific parameters. | |||
| 5775 | string config = "{ " + genIfaceConfig() + "," | |||
| 5776 | "\"expired-leases-processing\": " | |||
| 5777 | "{" | |||
| 5778 | " \"reclaim-timer-wait-time\": 20," | |||
| 5779 | " \"flush-reclaimed-timer-wait-time\": 35," | |||
| 5780 | " \"hold-reclaimed-time\": 1800," | |||
| 5781 | " \"max-reclaim-leases\": 50," | |||
| 5782 | " \"max-reclaim-time\": 100," | |||
| 5783 | " \"unwarned-reclaim-cycles\": 10" | |||
| 5784 | "}," | |||
| 5785 | "\"subnet4\": [ ]" | |||
| 5786 | "}"; | |||
| 5787 | ||||
| 5788 | ConstElementPtr json; | |||
| 5789 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_5789 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5789 ; } } else gtest_label_testnothrow_5789 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5789, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5790 | extractConfig(config); | |||
| 5791 | ||||
| 5792 | ConstElementPtr status; | |||
| 5793 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5793; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5793; } } else gtest_label_testnothrow_5793 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5793, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5794 | ||||
| 5795 | // Returned value should be 0 (success) | |||
| 5796 | checkResult(status, 0); | |||
| 5797 | ||||
| 5798 | // The value of decline-probation-period must be equal to the | |||
| 5799 | // value specified. | |||
| 5800 | CfgExpirationPtr cfg = CfgMgr::instance().getStagingCfg()->getCfgExpiration(); | |||
| 5801 | ASSERT_TRUE(cfg)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(cfg)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5801 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "cfg", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5802 | ||||
| 5803 | // Verify that parameters are correct. | |||
| 5804 | EXPECT_EQ(20, cfg->getReclaimTimerWaitTime())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("20", "cfg->getReclaimTimerWaitTime()" , 20, cfg->getReclaimTimerWaitTime()))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5804 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5805 | EXPECT_EQ(35, cfg->getFlushReclaimedTimerWaitTime())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("35", "cfg->getFlushReclaimedTimerWaitTime()" , 35, cfg->getFlushReclaimedTimerWaitTime()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5805 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5806 | EXPECT_EQ(1800, cfg->getHoldReclaimedTime())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1800", "cfg->getHoldReclaimedTime()" , 1800, cfg->getHoldReclaimedTime()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5806, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5807 | EXPECT_EQ(50, cfg->getMaxReclaimLeases())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("50", "cfg->getMaxReclaimLeases()" , 50, cfg->getMaxReclaimLeases()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5807, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5808 | EXPECT_EQ(100, cfg->getMaxReclaimTime())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("100", "cfg->getMaxReclaimTime()" , 100, cfg->getMaxReclaimTime()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5808, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5809 | EXPECT_EQ(10, cfg->getUnwarnedReclaimCycles())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("10", "cfg->getUnwarnedReclaimCycles()" , 10, cfg->getUnwarnedReclaimCycles()))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5809 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5810 | } | |||
| 5811 | ||||
| 5812 | // Check that invalid configuration for the expired leases processing is | |||
| 5813 | // causing an error. | |||
| 5814 | TEST_F(Dhcp4ParserTest, expiredLeasesProcessingError)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("expiredLeasesProcessingError") > 1 , "test_name must not be empty"); class Dhcp4ParserTest_expiredLeasesProcessingError_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_expiredLeasesProcessingError_Test () = default; ~Dhcp4ParserTest_expiredLeasesProcessingError_Test () override = default; Dhcp4ParserTest_expiredLeasesProcessingError_Test (const Dhcp4ParserTest_expiredLeasesProcessingError_Test & ) = delete; Dhcp4ParserTest_expiredLeasesProcessingError_Test & operator=( const Dhcp4ParserTest_expiredLeasesProcessingError_Test &) = delete; Dhcp4ParserTest_expiredLeasesProcessingError_Test (Dhcp4ParserTest_expiredLeasesProcessingError_Test && ) noexcept = delete; Dhcp4ParserTest_expiredLeasesProcessingError_Test & operator=( Dhcp4ParserTest_expiredLeasesProcessingError_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_expiredLeasesProcessingError_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "expiredLeasesProcessingError", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5814), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5814), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5814), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_expiredLeasesProcessingError_Test >); void Dhcp4ParserTest_expiredLeasesProcessingError_Test ::TestBody() { | |||
| 5815 | // Create basic configuration with the expiration specific parameters. | |||
| 5816 | // One of the parameters holds invalid value. | |||
| 5817 | string config = "{ " + genIfaceConfig() + "," | |||
| 5818 | "\"expired-leases-processing\": " | |||
| 5819 | "{" | |||
| 5820 | " \"reclaim-timer-wait-time\": -5," | |||
| 5821 | " \"flush-reclaimed-timer-wait-time\": 35," | |||
| 5822 | " \"hold-reclaimed-time\": 1800," | |||
| 5823 | " \"max-reclaim-leases\": 50," | |||
| 5824 | " \"max-reclaim-time\": 100," | |||
| 5825 | " \"unwarned-reclaim-cycles\": 10" | |||
| 5826 | "}," | |||
| 5827 | "\"subnet4\": [ ]" | |||
| 5828 | "}"; | |||
| 5829 | ||||
| 5830 | ConstElementPtr json; | |||
| 5831 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_5831 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5831 ; } } else gtest_label_testnothrow_5831 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5831, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5832 | ||||
| 5833 | ConstElementPtr status; | |||
| 5834 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5834; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5834; } } else gtest_label_testnothrow_5834 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5834, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5835 | ||||
| 5836 | // Returned value should be 0 (error) | |||
| 5837 | checkResult(status, 1); | |||
| 5838 | ||||
| 5839 | // Check that the error contains error position. | |||
| 5840 | EXPECT_TRUE(errorContainsPosition(status, "<string>"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(errorContainsPosition (status, "<string>"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5840, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "errorContainsPosition(status, \"<string>\")", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 5841 | } | |||
| 5842 | ||||
| 5843 | // Checks if the DHCPv4 is able to parse the configuration without 4o6 parameters | |||
| 5844 | // and does not set 4o6 fields at all. | |||
| 5845 | TEST_F(Dhcp4ParserTest, 4o6default)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("4o6default") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_4o6default_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_4o6default_Test() = default; ~Dhcp4ParserTest_4o6default_Test () override = default; Dhcp4ParserTest_4o6default_Test (const Dhcp4ParserTest_4o6default_Test &) = delete; Dhcp4ParserTest_4o6default_Test & operator=( const Dhcp4ParserTest_4o6default_Test & ) = delete; Dhcp4ParserTest_4o6default_Test (Dhcp4ParserTest_4o6default_Test &&) noexcept = delete; Dhcp4ParserTest_4o6default_Test & operator=( Dhcp4ParserTest_4o6default_Test &&) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_4o6default_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "4o6default", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5845 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5845), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5845), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_4o6default_Test >); void Dhcp4ParserTest_4o6default_Test::TestBody() { | |||
| 5846 | ||||
| 5847 | ConstElementPtr status; | |||
| 5848 | ||||
| 5849 | // Just a plain v4 config (no 4o6 parameters) | |||
| 5850 | string config = "{ " + genIfaceConfig() + "," | |||
| 5851 | "\"rebind-timer\": 2000, " | |||
| 5852 | "\"renew-timer\": 1000, " | |||
| 5853 | "\"subnet4\": [ { " | |||
| 5854 | " \"id\": 1," | |||
| 5855 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 5856 | " \"subnet\": \"192.0.2.0/24\" } ]," | |||
| 5857 | "\"valid-lifetime\": 4000 }"; | |||
| 5858 | ||||
| 5859 | ConstElementPtr json; | |||
| 5860 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_5860 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5860 ; } } else gtest_label_testnothrow_5860 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5860, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5861 | extractConfig(config); | |||
| 5862 | ||||
| 5863 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5863; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5863; } } else gtest_label_testnothrow_5863 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5863, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5864 | ||||
| 5865 | // check if returned status is OK | |||
| 5866 | checkResult(status, 0); | |||
| 5867 | ||||
| 5868 | // Now check if the configuration was indeed handled and we have | |||
| 5869 | // expected pool configured. | |||
| 5870 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 5871 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200")); | |||
| 5872 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5872, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5873 | ||||
| 5874 | const Cfg4o6& dhcp4o6 = subnet->get4o6(); | |||
| 5875 | EXPECT_FALSE(dhcp4o6.enabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(dhcp4o6.enabled())) ) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5875, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dhcp4o6.enabled()", "true", "false") .c_str()) = ::testing ::Message(); | |||
| 5876 | } | |||
| 5877 | ||||
| 5878 | // Checks if the DHCPv4 is able to parse the configuration with 4o6 subnet | |||
| 5879 | // defined. | |||
| 5880 | TEST_F(Dhcp4ParserTest, 4o6subnet)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("4o6subnet") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_4o6subnet_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_4o6subnet_Test() = default; ~Dhcp4ParserTest_4o6subnet_Test () override = default; Dhcp4ParserTest_4o6subnet_Test (const Dhcp4ParserTest_4o6subnet_Test &) = delete; Dhcp4ParserTest_4o6subnet_Test & operator =( const Dhcp4ParserTest_4o6subnet_Test &) = delete; Dhcp4ParserTest_4o6subnet_Test (Dhcp4ParserTest_4o6subnet_Test &&) noexcept = delete ; Dhcp4ParserTest_4o6subnet_Test & operator=( Dhcp4ParserTest_4o6subnet_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_4o6subnet_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "4o6subnet", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5880 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5880), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5880), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_4o6subnet_Test >); void Dhcp4ParserTest_4o6subnet_Test::TestBody() { | |||
| 5881 | ||||
| 5882 | ConstElementPtr status; | |||
| 5883 | ||||
| 5884 | // Just a plain v4 config (no 4o6 parameters) | |||
| 5885 | string config = "{ " + genIfaceConfig() + "," | |||
| 5886 | "\"rebind-timer\": 2000, " | |||
| 5887 | "\"renew-timer\": 1000, " | |||
| 5888 | "\"subnet4\": [ { " | |||
| 5889 | " \"id\": 1," | |||
| 5890 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 5891 | " \"subnet\": \"192.0.2.0/24\"," | |||
| 5892 | " \"4o6-subnet\": \"2001:db8::123/45\" } ]," | |||
| 5893 | "\"valid-lifetime\": 4000 }"; | |||
| 5894 | ||||
| 5895 | ConstElementPtr json; | |||
| 5896 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_5896 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5896 ; } } else gtest_label_testnothrow_5896 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5896, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5897 | extractConfig(config); | |||
| 5898 | ||||
| 5899 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5899; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5899; } } else gtest_label_testnothrow_5899 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5899, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5900 | ||||
| 5901 | // check if returned status is OK | |||
| 5902 | checkResult(status, 0); | |||
| 5903 | ||||
| 5904 | // Now check if the configuration was indeed handled and we have | |||
| 5905 | // expected pool configured. | |||
| 5906 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 5907 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200")); | |||
| 5908 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5908, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 5909 | ||||
| 5910 | const Cfg4o6& dhcp4o6 = subnet->get4o6(); | |||
| 5911 | EXPECT_TRUE(dhcp4o6.enabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dhcp4o6.enabled())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5911, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dhcp4o6.enabled()", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 5912 | EXPECT_EQ(IOAddress("2001:db8::123"), dhcp4o6.getSubnet4o6().get().first)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("IOAddress(\"2001:db8::123\")" , "dhcp4o6.getSubnet4o6().get().first", IOAddress("2001:db8::123" ), dhcp4o6.getSubnet4o6().get().first))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5912, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5913 | EXPECT_EQ(45, dhcp4o6.getSubnet4o6().get().second)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("45", "dhcp4o6.getSubnet4o6().get().second" , 45, dhcp4o6.getSubnet4o6().get().second))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5913 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 5914 | } | |||
| 5915 | ||||
| 5916 | // Checks if the DHCPv4 is able to parse the configuration with 4o6 subnet | |||
| 5917 | // defined. | |||
| 5918 | TEST_F(Dhcp4ParserTest, 4o6subnetBogus)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("4o6subnetBogus") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_4o6subnetBogus_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_4o6subnetBogus_Test() = default; ~ Dhcp4ParserTest_4o6subnetBogus_Test() override = default; Dhcp4ParserTest_4o6subnetBogus_Test (const Dhcp4ParserTest_4o6subnetBogus_Test &) = delete; Dhcp4ParserTest_4o6subnetBogus_Test & operator=( const Dhcp4ParserTest_4o6subnetBogus_Test & ) = delete; Dhcp4ParserTest_4o6subnetBogus_Test (Dhcp4ParserTest_4o6subnetBogus_Test &&) noexcept = delete; Dhcp4ParserTest_4o6subnetBogus_Test & operator=( Dhcp4ParserTest_4o6subnetBogus_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_4o6subnetBogus_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "4o6subnetBogus", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5918 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5918), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5918), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_4o6subnetBogus_Test >); void Dhcp4ParserTest_4o6subnetBogus_Test::TestBody() { | |||
| 5919 | ||||
| 5920 | ConstElementPtr status; | |||
| 5921 | ||||
| 5922 | // Just a plain v4 config (no 4o6 parameters) | |||
| 5923 | string config[] = { | |||
| 5924 | // Bogus configuration 1: missing / in subnet | |||
| 5925 | "{ " + genIfaceConfig() + "," | |||
| 5926 | "\"rebind-timer\": 2000, " | |||
| 5927 | "\"renew-timer\": 1000, " | |||
| 5928 | "\"subnet4\": [ { " | |||
| 5929 | " \"id\": 1," | |||
| 5930 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 5931 | " \"subnet\": \"192.0.2.0/24\"," | |||
| 5932 | " \"4o6-subnet\": \"2001:db8::123\" } ]," | |||
| 5933 | "\"valid-lifetime\": 4000 }", | |||
| 5934 | ||||
| 5935 | // Bogus configuration 2: incorrect address | |||
| 5936 | "{ " + genIfaceConfig() + "," | |||
| 5937 | "\"rebind-timer\": 2000, " | |||
| 5938 | "\"renew-timer\": 1000, " | |||
| 5939 | "\"subnet4\": [ { " | |||
| 5940 | " \"id\": 1," | |||
| 5941 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 5942 | " \"subnet\": \"192.0.2.0/24\"," | |||
| 5943 | " \"4o6-subnet\": \"2001:db8:bogus/45\" } ]," | |||
| 5944 | "\"valid-lifetime\": 4000 }", | |||
| 5945 | ||||
| 5946 | // Bogus configuration 3: incorrect prefix length | |||
| 5947 | "{ " + genIfaceConfig() + "," | |||
| 5948 | "\"rebind-timer\": 2000, " | |||
| 5949 | "\"renew-timer\": 1000, " | |||
| 5950 | "\"subnet4\": [ { " | |||
| 5951 | " \"id\": 1," | |||
| 5952 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 5953 | " \"subnet\": \"192.0.2.0/24\"," | |||
| 5954 | " \"4o6-subnet\": \"2001:db8::123/200\" } ]," | |||
| 5955 | "\"valid-lifetime\": 4000 }" | |||
| 5956 | }; | |||
| 5957 | ||||
| 5958 | ConstElementPtr json1; | |||
| 5959 | ASSERT_NO_THROW(json1 = parseDHCP4(config[0]))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json1 = parseDHCP4(config[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_5959 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5959 ; } } else gtest_label_testnothrow_5959 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5959, ("Expected: " "json1 = parseDHCP4(config[0])" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5960 | ConstElementPtr json2; | |||
| 5961 | ASSERT_NO_THROW(json2 = parseDHCP4(config[0]))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json2 = parseDHCP4(config[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_5961 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5961 ; } } else gtest_label_testnothrow_5961 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5961, ("Expected: " "json2 = parseDHCP4(config[0])" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5962 | ConstElementPtr json3; | |||
| 5963 | ASSERT_NO_THROW(json3 = parseDHCP4(config[0]))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json3 = parseDHCP4(config[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_5963 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5963 ; } } else gtest_label_testnothrow_5963 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5963, ("Expected: " "json3 = parseDHCP4(config[0])" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5964 | ||||
| 5965 | // Check that the first config is rejected. | |||
| 5966 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json1))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json1); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5966; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5966; } } else gtest_label_testnothrow_5966 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5966, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json1)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5967 | checkResult(status, 1); | |||
| 5968 | ||||
| 5969 | // Check that the second config is rejected. | |||
| 5970 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json2))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json2); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5970; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5970; } } else gtest_label_testnothrow_5970 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5970, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json2)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5971 | checkResult(status, 1); | |||
| 5972 | ||||
| 5973 | // Check that the third config is rejected. | |||
| 5974 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json3))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json3); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5974; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5974; } } else gtest_label_testnothrow_5974 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5974, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json3)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 5975 | checkResult(status, 1); | |||
| 5976 | } | |||
| 5977 | ||||
| 5978 | // Checks if the DHCPv4 is able to parse the configuration with 4o6 network | |||
| 5979 | // interface defined. | |||
| 5980 | TEST_F(Dhcp4ParserTest, 4o6iface)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("4o6iface") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_4o6iface_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_4o6iface_Test() = default; ~Dhcp4ParserTest_4o6iface_Test () override = default; Dhcp4ParserTest_4o6iface_Test (const Dhcp4ParserTest_4o6iface_Test &) = delete; Dhcp4ParserTest_4o6iface_Test & operator =( const Dhcp4ParserTest_4o6iface_Test &) = delete; Dhcp4ParserTest_4o6iface_Test (Dhcp4ParserTest_4o6iface_Test &&) noexcept = delete ; Dhcp4ParserTest_4o6iface_Test & operator=( Dhcp4ParserTest_4o6iface_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_4o6iface_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "4o6iface", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 5980 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5980), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5980), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_4o6iface_Test >); void Dhcp4ParserTest_4o6iface_Test::TestBody() { | |||
| 5981 | ||||
| 5982 | ConstElementPtr status; | |||
| 5983 | ||||
| 5984 | // Just a plain v4 config (no 4o6 parameters) | |||
| 5985 | string config = "{ " + genIfaceConfig() + "," | |||
| 5986 | "\"rebind-timer\": 2000, " | |||
| 5987 | "\"renew-timer\": 1000, " | |||
| 5988 | "\"subnet4\": [ { " | |||
| 5989 | " \"id\": 1," | |||
| 5990 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 5991 | " \"subnet\": \"192.0.2.0/24\"," | |||
| 5992 | " \"4o6-interface\": \"ethX\" } ]," | |||
| 5993 | "\"valid-lifetime\": 4000 }"; | |||
| 5994 | ||||
| 5995 | ConstElementPtr json; | |||
| 5996 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_5996 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5996 ; } } else gtest_label_testnothrow_5996 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5996, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 5997 | extractConfig(config); | |||
| 5998 | ||||
| 5999 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_5999; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_5999; } } else gtest_label_testnothrow_5999 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 5999, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 6000 | ||||
| 6001 | // check if returned status is OK | |||
| 6002 | checkResult(status, 0); | |||
| 6003 | ||||
| 6004 | // Now check if the configuration was indeed handled and we have | |||
| 6005 | // expected pool configured. | |||
| 6006 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 6007 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200")); | |||
| 6008 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6008, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6009 | ||||
| 6010 | const Cfg4o6& dhcp4o6 = subnet->get4o6(); | |||
| 6011 | EXPECT_TRUE(dhcp4o6.enabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dhcp4o6.enabled())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6011, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dhcp4o6.enabled()", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 6012 | EXPECT_EQ("ethX", dhcp4o6.getIface4o6().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"ethX\"" , "dhcp4o6.getIface4o6().get()", "ethX", dhcp4o6.getIface4o6( ).get()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6012, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6013 | } | |||
| 6014 | ||||
| 6015 | // Checks if the DHCPv4 is able to parse the configuration with both 4o6 network | |||
| 6016 | // interface and v6 subnet defined. | |||
| 6017 | TEST_F(Dhcp4ParserTest, 4o6subnetIface)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("4o6subnetIface") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_4o6subnetIface_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_4o6subnetIface_Test() = default; ~ Dhcp4ParserTest_4o6subnetIface_Test() override = default; Dhcp4ParserTest_4o6subnetIface_Test (const Dhcp4ParserTest_4o6subnetIface_Test &) = delete; Dhcp4ParserTest_4o6subnetIface_Test & operator=( const Dhcp4ParserTest_4o6subnetIface_Test & ) = delete; Dhcp4ParserTest_4o6subnetIface_Test (Dhcp4ParserTest_4o6subnetIface_Test &&) noexcept = delete; Dhcp4ParserTest_4o6subnetIface_Test & operator=( Dhcp4ParserTest_4o6subnetIface_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_4o6subnetIface_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "4o6subnetIface", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6017 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6017), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6017), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_4o6subnetIface_Test >); void Dhcp4ParserTest_4o6subnetIface_Test::TestBody() { | |||
| 6018 | ||||
| 6019 | ConstElementPtr status; | |||
| 6020 | ||||
| 6021 | // Just a plain v4 config (no 4o6 parameters) | |||
| 6022 | string config = "{ " + genIfaceConfig() + "," | |||
| 6023 | "\"rebind-timer\": 2000, " | |||
| 6024 | "\"renew-timer\": 1000, " | |||
| 6025 | "\"subnet4\": [ { " | |||
| 6026 | " \"id\": 1," | |||
| 6027 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 6028 | " \"subnet\": \"192.0.2.0/24\"," | |||
| 6029 | " \"4o6-subnet\": \"2001:db8::543/21\"," | |||
| 6030 | " \"4o6-interface\": \"ethX\" } ]," | |||
| 6031 | "\"valid-lifetime\": 4000 }"; | |||
| 6032 | ||||
| 6033 | ConstElementPtr json; | |||
| 6034 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_6034 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_6034 ; } } else gtest_label_testnothrow_6034 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6034, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 6035 | extractConfig(config); | |||
| 6036 | ||||
| 6037 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_6037; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_6037; } } else gtest_label_testnothrow_6037 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6037, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 6038 | ||||
| 6039 | // check if returned status is OK | |||
| 6040 | checkResult(status, 0); | |||
| 6041 | ||||
| 6042 | // Now check if the configuration was indeed handled and we have | |||
| 6043 | // expected subnet configured... | |||
| 6044 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 6045 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200")); | |||
| 6046 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6046, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6047 | ||||
| 6048 | // ... and that subnet has 4o6 network interface specified. | |||
| 6049 | const Cfg4o6& dhcp4o6 = subnet->get4o6(); | |||
| 6050 | EXPECT_TRUE(dhcp4o6.enabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dhcp4o6.enabled())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6050, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dhcp4o6.enabled()", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 6051 | EXPECT_EQ(IOAddress("2001:db8::543"), dhcp4o6.getSubnet4o6().get().first)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("IOAddress(\"2001:db8::543\")" , "dhcp4o6.getSubnet4o6().get().first", IOAddress("2001:db8::543" ), dhcp4o6.getSubnet4o6().get().first))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6051, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6052 | EXPECT_EQ(21, dhcp4o6.getSubnet4o6().get().second)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("21", "dhcp4o6.getSubnet4o6().get().second" , 21, dhcp4o6.getSubnet4o6().get().second))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6052 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6053 | EXPECT_EQ("ethX", dhcp4o6.getIface4o6().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"ethX\"" , "dhcp4o6.getIface4o6().get()", "ethX", dhcp4o6.getIface4o6( ).get()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6053, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6054 | } | |||
| 6055 | ||||
| 6056 | // Checks if the DHCPv4 is able to parse the configuration with 4o6 network | |||
| 6057 | // interface-id. | |||
| 6058 | TEST_F(Dhcp4ParserTest, 4o6subnetInterfaceId)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("4o6subnetInterfaceId") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_4o6subnetInterfaceId_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_4o6subnetInterfaceId_Test() = default ; ~Dhcp4ParserTest_4o6subnetInterfaceId_Test() override = default ; Dhcp4ParserTest_4o6subnetInterfaceId_Test (const Dhcp4ParserTest_4o6subnetInterfaceId_Test &) = delete; Dhcp4ParserTest_4o6subnetInterfaceId_Test & operator=( const Dhcp4ParserTest_4o6subnetInterfaceId_Test & ) = delete; Dhcp4ParserTest_4o6subnetInterfaceId_Test (Dhcp4ParserTest_4o6subnetInterfaceId_Test &&) noexcept = delete; Dhcp4ParserTest_4o6subnetInterfaceId_Test & operator=( Dhcp4ParserTest_4o6subnetInterfaceId_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_4o6subnetInterfaceId_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "4o6subnetInterfaceId", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6058), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6058), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6058), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_4o6subnetInterfaceId_Test >); void Dhcp4ParserTest_4o6subnetInterfaceId_Test::TestBody () { | |||
| 6059 | ||||
| 6060 | ConstElementPtr status; | |||
| 6061 | ||||
| 6062 | // Just a plain v4 config (no 4o6 parameters) | |||
| 6063 | string config = "{ " + genIfaceConfig() + "," | |||
| 6064 | "\"rebind-timer\": 2000, " | |||
| 6065 | "\"renew-timer\": 1000, " | |||
| 6066 | "\"subnet4\": [ { " | |||
| 6067 | " \"id\": 1," | |||
| 6068 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 6069 | " \"subnet\": \"192.0.2.0/24\"," | |||
| 6070 | " \"4o6-interface-id\": \"vlan123\" } ]," | |||
| 6071 | "\"valid-lifetime\": 4000 }"; | |||
| 6072 | ||||
| 6073 | ConstElementPtr json; | |||
| 6074 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_6074 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_6074 ; } } else gtest_label_testnothrow_6074 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6074, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 6075 | extractConfig(config); | |||
| 6076 | ||||
| 6077 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_6077; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_6077; } } else gtest_label_testnothrow_6077 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6077, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 6078 | ||||
| 6079 | // check if returned status is OK | |||
| 6080 | checkResult(status, 0); | |||
| 6081 | ||||
| 6082 | // Now check if the configuration was indeed handled and we have | |||
| 6083 | // expected 4o6-interface-id configured. | |||
| 6084 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 6085 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.200")); | |||
| 6086 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6086, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6087 | ||||
| 6088 | const Cfg4o6& dhcp4o6 = subnet->get4o6(); | |||
| 6089 | EXPECT_TRUE(dhcp4o6.enabled())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dhcp4o6.enabled())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6089, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dhcp4o6.enabled()", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 6090 | OptionPtr ifaceid = dhcp4o6.getInterfaceId(); | |||
| 6091 | ASSERT_TRUE(ifaceid)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ifaceid)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6091, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ifaceid", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 6092 | ||||
| 6093 | vector<uint8_t> data = ifaceid->getData(); | |||
| 6094 | EXPECT_EQ(7, data.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("7", "data.size()" , 7, data.size()))) ; else ::testing::internal::AssertHelper( ::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6094, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6095 | const char *exp = "vlan123"; | |||
| 6096 | EXPECT_EQ(0, memcmp(&data[0], exp, data.size()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "memcmp(&data[0], exp, data.size())" , 0, memcmp(&data[0], exp, data.size())))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6096 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6097 | } | |||
| 6098 | ||||
| 6099 | // Verifies that simple list of valid classes parses and | |||
| 6100 | // is staged for commit. | |||
| 6101 | TEST_F(Dhcp4ParserTest, validClientClassDictionary)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("validClientClassDictionary") > 1, "test_name must not be empty"); class Dhcp4ParserTest_validClientClassDictionary_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_validClientClassDictionary_Test () = default; ~Dhcp4ParserTest_validClientClassDictionary_Test () override = default; Dhcp4ParserTest_validClientClassDictionary_Test (const Dhcp4ParserTest_validClientClassDictionary_Test & ) = delete; Dhcp4ParserTest_validClientClassDictionary_Test & operator=( const Dhcp4ParserTest_validClientClassDictionary_Test &) = delete; Dhcp4ParserTest_validClientClassDictionary_Test (Dhcp4ParserTest_validClientClassDictionary_Test &&) noexcept = delete; Dhcp4ParserTest_validClientClassDictionary_Test & operator=( Dhcp4ParserTest_validClientClassDictionary_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_validClientClassDictionary_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "validClientClassDictionary", nullptr, nullptr, ::testing:: internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6101), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6101), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6101), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_validClientClassDictionary_Test >); void Dhcp4ParserTest_validClientClassDictionary_Test:: TestBody() { | |||
| 6102 | string config = "{ " + genIfaceConfig() + "," | |||
| 6103 | "\"valid-lifetime\": 4000, \n" | |||
| 6104 | "\"rebind-timer\": 2000, \n" | |||
| 6105 | "\"renew-timer\": 1000, \n" | |||
| 6106 | "\"client-classes\" : [ \n" | |||
| 6107 | " { \n" | |||
| 6108 | " \"name\": \"one\" \n" | |||
| 6109 | " }, \n" | |||
| 6110 | " { \n" | |||
| 6111 | " \"name\": \"two\" \n" | |||
| 6112 | " }, \n" | |||
| 6113 | " { \n" | |||
| 6114 | " \"name\": \"three\" \n" | |||
| 6115 | " } \n" | |||
| 6116 | "], \n" | |||
| 6117 | "\"subnet4\": [ { \n" | |||
| 6118 | " \"id\": 1, \n" | |||
| 6119 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ], \n" | |||
| 6120 | " \"subnet\": \"192.0.2.0/24\" \n" | |||
| 6121 | " } ] \n" | |||
| 6122 | "} \n"; | |||
| 6123 | ||||
| 6124 | ConstElementPtr json; | |||
| 6125 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_6125 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_6125 ; } } else gtest_label_testnothrow_6125 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6125, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 6126 | extractConfig(config); | |||
| 6127 | ||||
| 6128 | ConstElementPtr status; | |||
| 6129 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_6129; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_6129; } } else gtest_label_testnothrow_6129 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6129, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 6130 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6130, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6131 | checkResult(status, 0); | |||
| 6132 | ||||
| 6133 | // We check staging config because CfgMgr::commit hasn't been executed. | |||
| 6134 | ClientClassDictionaryPtr dictionary; | |||
| 6135 | dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); | |||
| 6136 | ASSERT_TRUE(dictionary)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dictionary)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6136, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dictionary", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6137 | EXPECT_EQ(3, dictionary->getClasses()->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("3", "dictionary->getClasses()->size()" , 3, dictionary->getClasses()->size()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6137 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6138 | ||||
| 6139 | // Execute the commit | |||
| 6140 | ASSERT_NO_THROW(CfgMgr::instance().commit())switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { CfgMgr::instance().commit(); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_6140 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_6140 ; } } else gtest_label_testnothrow_6140 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6140, ("Expected: " "CfgMgr::instance().commit()" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 6141 | ||||
| 6142 | // Verify that after commit, the current config has the correct dictionary | |||
| 6143 | dictionary = CfgMgr::instance().getCurrentCfg()->getClientClassDictionary(); | |||
| 6144 | ASSERT_TRUE(dictionary)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dictionary)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6144, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dictionary", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6145 | EXPECT_EQ(3, dictionary->getClasses()->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("3", "dictionary->getClasses()->size()" , 3, dictionary->getClasses()->size()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6145 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6146 | } | |||
| 6147 | ||||
| 6148 | // Verifies that a class list containing an invalid | |||
| 6149 | // class definition causes a configuration error. | |||
| 6150 | TEST_F(Dhcp4ParserTest, invalidClientClassDictionary)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("invalidClientClassDictionary") > 1 , "test_name must not be empty"); class Dhcp4ParserTest_invalidClientClassDictionary_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_invalidClientClassDictionary_Test () = default; ~Dhcp4ParserTest_invalidClientClassDictionary_Test () override = default; Dhcp4ParserTest_invalidClientClassDictionary_Test (const Dhcp4ParserTest_invalidClientClassDictionary_Test & ) = delete; Dhcp4ParserTest_invalidClientClassDictionary_Test & operator=( const Dhcp4ParserTest_invalidClientClassDictionary_Test &) = delete; Dhcp4ParserTest_invalidClientClassDictionary_Test (Dhcp4ParserTest_invalidClientClassDictionary_Test && ) noexcept = delete; Dhcp4ParserTest_invalidClientClassDictionary_Test & operator=( Dhcp4ParserTest_invalidClientClassDictionary_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_invalidClientClassDictionary_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "invalidClientClassDictionary", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6150), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6150), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6150), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_invalidClientClassDictionary_Test >); void Dhcp4ParserTest_invalidClientClassDictionary_Test ::TestBody() { | |||
| 6151 | string config = "{ " + genIfaceConfig() + "," | |||
| 6152 | "\"valid-lifetime\": 4000, \n" | |||
| 6153 | "\"rebind-timer\": 2000, \n" | |||
| 6154 | "\"renew-timer\": 1000, \n" | |||
| 6155 | "\"client-classes\" : [ \n" | |||
| 6156 | " { \n" | |||
| 6157 | " \"name\": \"one\", \n" | |||
| 6158 | " \"bogus\": \"bad\" \n" | |||
| 6159 | " } \n" | |||
| 6160 | "], \n" | |||
| 6161 | "\"subnet4\": [ { \n" | |||
| 6162 | " \"id\": 1, \n" | |||
| 6163 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ], \n" | |||
| 6164 | " \"subnet\": \"192.0.2.0/24\" \n" | |||
| 6165 | " } ] \n" | |||
| 6166 | "} \n"; | |||
| 6167 | ||||
| 6168 | EXPECT_THROW(parseDHCP4(config), Dhcp4ParseError)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { parseDHCP4(config); } else static_assert(true, ""); } catch (Dhcp4ParseError const& ) { gtest_caught_expected = true; } catch (typename std::conditional < std::is_same<typename std::remove_cv<typename std:: remove_reference< Dhcp4ParseError>::type>::type, std ::exception>::value, const ::testing::internal::NeverThrown &, const std::exception&>::type e) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\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_6168; } catch (... ) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_6168; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "parseDHCP4(config)" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws nothing."; goto gtest_label_testthrow_6168 ; } } else gtest_label_testthrow_6168 : ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6168, gtest_msg.value.c_str()) = ::testing::Message(); | |||
| 6169 | } | |||
| 6170 | ||||
| 6171 | // Verifies that simple list of valid classes parses and | |||
| 6172 | // is staged for commit. | |||
| 6173 | TEST_F(Dhcp4ParserTest, clientClassValidLifetime)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("clientClassValidLifetime") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_clientClassValidLifetime_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_clientClassValidLifetime_Test () = default; ~Dhcp4ParserTest_clientClassValidLifetime_Test( ) override = default; Dhcp4ParserTest_clientClassValidLifetime_Test (const Dhcp4ParserTest_clientClassValidLifetime_Test &) = delete; Dhcp4ParserTest_clientClassValidLifetime_Test & operator =( const Dhcp4ParserTest_clientClassValidLifetime_Test &) = delete; Dhcp4ParserTest_clientClassValidLifetime_Test (Dhcp4ParserTest_clientClassValidLifetime_Test &&) noexcept = delete; Dhcp4ParserTest_clientClassValidLifetime_Test & operator=( Dhcp4ParserTest_clientClassValidLifetime_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_clientClassValidLifetime_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "clientClassValidLifetime", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6173), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6173), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6173), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_clientClassValidLifetime_Test >); void Dhcp4ParserTest_clientClassValidLifetime_Test::TestBody () { | |||
| 6174 | string config = "{ " + genIfaceConfig() + "," | |||
| 6175 | "\"client-classes\" : [ \n" | |||
| 6176 | " { \n" | |||
| 6177 | " \"name\": \"one\", \n" | |||
| 6178 | " \"min-valid-lifetime\": 1000, \n" | |||
| 6179 | " \"valid-lifetime\": 2000, \n" | |||
| 6180 | " \"max-valid-lifetime\": 3000 \n" | |||
| 6181 | " }, \n" | |||
| 6182 | " { \n" | |||
| 6183 | " \"name\": \"two\" \n" | |||
| 6184 | " } \n" | |||
| 6185 | "], \n" | |||
| 6186 | "\"subnet4\": [ { \n" | |||
| 6187 | " \"id\": 1, \n" | |||
| 6188 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ], \n" | |||
| 6189 | " \"subnet\": \"192.0.2.0/24\" \n" | |||
| 6190 | " } ] \n" | |||
| 6191 | "} \n"; | |||
| 6192 | ||||
| 6193 | ConstElementPtr json; | |||
| 6194 | ASSERT_NO_THROW_LOG(json = parseDHCP4(config)){ try { json = parseDHCP4(config); } catch (const std::exception & ex) { return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6194, "Failed") = ::testing::Message() << "json = parseDHCP4(config)" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6194 , "Failed") = ::testing::Message() << "json = parseDHCP4(config)" << " threw non-std::exception"; } }; | |||
| 6195 | extractConfig(config); | |||
| 6196 | ||||
| 6197 | ConstElementPtr status; | |||
| 6198 | ASSERT_NO_THROW_LOG(status = Dhcpv4SrvTest::configure(*srv_, json)){ try { status = Dhcpv4SrvTest::configure(*srv_, json); } catch (const std::exception& ex) { return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6198, "Failed") = ::testing::Message() << "status = Dhcpv4SrvTest::configure(*srv_, json)" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6198 , "Failed") = ::testing::Message() << "status = Dhcpv4SrvTest::configure(*srv_, json)" << " threw non-std::exception"; } }; | |||
| 6199 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6199, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6200 | checkResult(status, 0); | |||
| 6201 | ||||
| 6202 | // We check staging config because CfgMgr::commit hasn't been executed. | |||
| 6203 | ClientClassDictionaryPtr dictionary; | |||
| 6204 | dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); | |||
| 6205 | ASSERT_TRUE(dictionary)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dictionary)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6205, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dictionary", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6206 | EXPECT_EQ(2, dictionary->getClasses()->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "dictionary->getClasses()->size()" , 2, dictionary->getClasses()->size()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6206 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6207 | ||||
| 6208 | // Execute the commit | |||
| 6209 | ASSERT_NO_THROW(CfgMgr::instance().commit())switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { CfgMgr::instance().commit(); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_6209 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_6209 ; } } else gtest_label_testnothrow_6209 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6209, ("Expected: " "CfgMgr::instance().commit()" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 6210 | ||||
| 6211 | // Verify that after commit, the current config has the correct dictionary | |||
| 6212 | dictionary = CfgMgr::instance().getCurrentCfg()->getClientClassDictionary(); | |||
| 6213 | ASSERT_TRUE(dictionary)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dictionary)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6213, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dictionary", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6214 | EXPECT_EQ(2, dictionary->getClasses()->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "dictionary->getClasses()->size()" , 2, dictionary->getClasses()->size()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6214 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6215 | ||||
| 6216 | ClientClassDefPtr class_def = dictionary->findClass("one"); | |||
| 6217 | ASSERT_TRUE(class_def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(class_def)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6217, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "class_def", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6218 | EXPECT_EQ(class_def->getValid().getMin(), 1000)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("class_def->getValid().getMin()" , "1000", class_def->getValid().getMin(), 1000))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6218 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6219 | EXPECT_EQ(class_def->getValid().get(), 2000)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("class_def->getValid().get()" , "2000", class_def->getValid().get(), 2000))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6219 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6220 | EXPECT_EQ(class_def->getValid().getMax(), 3000)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("class_def->getValid().getMax()" , "3000", class_def->getValid().getMax(), 3000))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6220 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6221 | ||||
| 6222 | class_def = dictionary->findClass("two"); | |||
| 6223 | ASSERT_TRUE(class_def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(class_def)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6223, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "class_def", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6224 | EXPECT_TRUE(class_def->getValid().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(class_def->getValid ().unspecified())) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6224, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "class_def->getValid().unspecified()", "false", "true") . c_str()) = ::testing::Message(); | |||
| 6225 | } | |||
| 6226 | ||||
| 6227 | // Verifies that simple list of valid template classes parses and | |||
| 6228 | // is staged for commit. | |||
| 6229 | TEST_F(Dhcp4ParserTest, templateClientClassValidLifetime)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("templateClientClassValidLifetime") > 1, "test_name must not be empty"); class Dhcp4ParserTest_templateClientClassValidLifetime_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_templateClientClassValidLifetime_Test () = default; ~Dhcp4ParserTest_templateClientClassValidLifetime_Test () override = default; Dhcp4ParserTest_templateClientClassValidLifetime_Test (const Dhcp4ParserTest_templateClientClassValidLifetime_Test &) = delete; Dhcp4ParserTest_templateClientClassValidLifetime_Test & operator=( const Dhcp4ParserTest_templateClientClassValidLifetime_Test &) = delete; Dhcp4ParserTest_templateClientClassValidLifetime_Test (Dhcp4ParserTest_templateClientClassValidLifetime_Test && ) noexcept = delete; Dhcp4ParserTest_templateClientClassValidLifetime_Test & operator=( Dhcp4ParserTest_templateClientClassValidLifetime_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_templateClientClassValidLifetime_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "templateClientClassValidLifetime", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6229), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6229), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6229), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_templateClientClassValidLifetime_Test >); void Dhcp4ParserTest_templateClientClassValidLifetime_Test ::TestBody() { | |||
| 6230 | string config = "{ " + genIfaceConfig() + "," | |||
| 6231 | "\"client-classes\" : [ \n" | |||
| 6232 | " { \n" | |||
| 6233 | " \"name\": \"one\", \n" | |||
| 6234 | " \"min-valid-lifetime\": 1000, \n" | |||
| 6235 | " \"valid-lifetime\": 2000, \n" | |||
| 6236 | " \"max-valid-lifetime\": 3000, \n" | |||
| 6237 | " \"template-test\": \"''\" \n" | |||
| 6238 | " }, \n" | |||
| 6239 | " { \n" | |||
| 6240 | " \"name\": \"two\", \n" | |||
| 6241 | " \"template-test\": \"''\" \n" | |||
| 6242 | " } \n" | |||
| 6243 | "], \n" | |||
| 6244 | "\"subnet4\": [ { \n" | |||
| 6245 | " \"id\": 1, \n" | |||
| 6246 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ], \n" | |||
| 6247 | " \"subnet\": \"192.0.2.0/24\" \n" | |||
| 6248 | " } ] \n" | |||
| 6249 | "} \n"; | |||
| 6250 | ||||
| 6251 | ConstElementPtr json; | |||
| 6252 | ASSERT_NO_THROW_LOG(json = parseDHCP4(config)){ try { json = parseDHCP4(config); } catch (const std::exception & ex) { return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6252, "Failed") = ::testing::Message() << "json = parseDHCP4(config)" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6252 , "Failed") = ::testing::Message() << "json = parseDHCP4(config)" << " threw non-std::exception"; } }; | |||
| 6253 | extractConfig(config); | |||
| 6254 | ||||
| 6255 | ConstElementPtr status; | |||
| 6256 | ASSERT_NO_THROW_LOG(status = Dhcpv4SrvTest::configure(*srv_, json)){ try { status = Dhcpv4SrvTest::configure(*srv_, json); } catch (const std::exception& ex) { return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6256, "Failed") = ::testing::Message() << "status = Dhcpv4SrvTest::configure(*srv_, json)" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6256 , "Failed") = ::testing::Message() << "status = Dhcpv4SrvTest::configure(*srv_, json)" << " threw non-std::exception"; } }; | |||
| 6257 | ASSERT_TRUE(status)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(status)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6257, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "status", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6258 | checkResult(status, 0); | |||
| 6259 | ||||
| 6260 | // We check staging config because CfgMgr::commit hasn't been executed. | |||
| 6261 | ClientClassDictionaryPtr dictionary; | |||
| 6262 | dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); | |||
| 6263 | ASSERT_TRUE(dictionary)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dictionary)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6263, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dictionary", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6264 | EXPECT_EQ(2, dictionary->getClasses()->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "dictionary->getClasses()->size()" , 2, dictionary->getClasses()->size()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6264 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6265 | ||||
| 6266 | // Execute the commit | |||
| 6267 | ASSERT_NO_THROW(CfgMgr::instance().commit())switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { CfgMgr::instance().commit(); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_6267 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_6267 ; } } else gtest_label_testnothrow_6267 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6267, ("Expected: " "CfgMgr::instance().commit()" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 6268 | ||||
| 6269 | // Verify that after commit, the current config has the correct dictionary | |||
| 6270 | dictionary = CfgMgr::instance().getCurrentCfg()->getClientClassDictionary(); | |||
| 6271 | ASSERT_TRUE(dictionary)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dictionary)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6271, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dictionary", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6272 | EXPECT_EQ(2, dictionary->getClasses()->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "dictionary->getClasses()->size()" , 2, dictionary->getClasses()->size()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6272 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6273 | ||||
| 6274 | ClientClassDefPtr class_def = dictionary->findClass("one"); | |||
| 6275 | ASSERT_TRUE(class_def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(class_def)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6275, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "class_def", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6276 | ASSERT_TRUE(dynamic_cast<TemplateClientClassDef*>(class_def.get()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dynamic_cast<TemplateClientClassDef *>(class_def.get()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6276, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dynamic_cast<TemplateClientClassDef*>(class_def.get())" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 6277 | EXPECT_EQ(class_def->getValid().getMin(), 1000)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("class_def->getValid().getMin()" , "1000", class_def->getValid().getMin(), 1000))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6277 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6278 | EXPECT_EQ(class_def->getValid().get(), 2000)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("class_def->getValid().get()" , "2000", class_def->getValid().get(), 2000))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6278 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6279 | EXPECT_EQ(class_def->getValid().getMax(), 3000)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("class_def->getValid().getMax()" , "3000", class_def->getValid().getMax(), 3000))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6279 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6280 | ||||
| 6281 | class_def = dictionary->findClass("two"); | |||
| 6282 | ASSERT_TRUE(class_def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(class_def)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6282, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "class_def", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6283 | ASSERT_TRUE(dynamic_cast<TemplateClientClassDef*>(class_def.get()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dynamic_cast<TemplateClientClassDef *>(class_def.get()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6283, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dynamic_cast<TemplateClientClassDef*>(class_def.get())" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 6284 | EXPECT_TRUE(class_def->getValid().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(class_def->getValid ().unspecified())) ; else ::testing::internal::AssertHelper(:: testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6284, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "class_def->getValid().unspecified()", "false", "true") . c_str()) = ::testing::Message(); | |||
| 6285 | } | |||
| 6286 | ||||
| 6287 | // Test verifies that regular configuration does not provide any user context | |||
| 6288 | // in the address pool. | |||
| 6289 | TEST_F(Dhcp4ParserTest, poolUserContextMissing)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("poolUserContextMissing") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_poolUserContextMissing_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_poolUserContextMissing_Test () = default; ~Dhcp4ParserTest_poolUserContextMissing_Test() override = default; Dhcp4ParserTest_poolUserContextMissing_Test (const Dhcp4ParserTest_poolUserContextMissing_Test &) = delete; Dhcp4ParserTest_poolUserContextMissing_Test & operator=( const Dhcp4ParserTest_poolUserContextMissing_Test &) = delete ; Dhcp4ParserTest_poolUserContextMissing_Test (Dhcp4ParserTest_poolUserContextMissing_Test &&) noexcept = delete; Dhcp4ParserTest_poolUserContextMissing_Test & operator=( Dhcp4ParserTest_poolUserContextMissing_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_poolUserContextMissing_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "poolUserContextMissing", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6289), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6289), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6289), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_poolUserContextMissing_Test >); void Dhcp4ParserTest_poolUserContextMissing_Test::TestBody () { | |||
| 6290 | extractConfig(PARSER_CONFIGS[0]); | |||
| 6291 | PoolPtr pool; | |||
| 6292 | getPool(string(PARSER_CONFIGS[0]), 0, 0, pool); | |||
| 6293 | ASSERT_TRUE(pool)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6293 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6294 | EXPECT_FALSE(pool->getContext())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pool->getContext ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6294, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getContext()", "true", "false") .c_str()) = ::testing ::Message(); | |||
| 6295 | } | |||
| 6296 | ||||
| 6297 | // Test verifies that it's possible to specify empty user context in the | |||
| 6298 | // address pool. | |||
| 6299 | TEST_F(Dhcp4ParserTest, poolUserContextEmpty)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("poolUserContextEmpty") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_poolUserContextEmpty_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_poolUserContextEmpty_Test() = default ; ~Dhcp4ParserTest_poolUserContextEmpty_Test() override = default ; Dhcp4ParserTest_poolUserContextEmpty_Test (const Dhcp4ParserTest_poolUserContextEmpty_Test &) = delete; Dhcp4ParserTest_poolUserContextEmpty_Test & operator=( const Dhcp4ParserTest_poolUserContextEmpty_Test & ) = delete; Dhcp4ParserTest_poolUserContextEmpty_Test (Dhcp4ParserTest_poolUserContextEmpty_Test &&) noexcept = delete; Dhcp4ParserTest_poolUserContextEmpty_Test & operator=( Dhcp4ParserTest_poolUserContextEmpty_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_poolUserContextEmpty_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "poolUserContextEmpty", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6299), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6299), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6299), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_poolUserContextEmpty_Test >); void Dhcp4ParserTest_poolUserContextEmpty_Test::TestBody () { | |||
| 6300 | extractConfig(PARSER_CONFIGS[1]); | |||
| 6301 | PoolPtr pool; | |||
| 6302 | getPool(string(PARSER_CONFIGS[1]), 0, 0, pool); | |||
| 6303 | ASSERT_TRUE(pool)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6303 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6304 | ConstElementPtr ctx = pool->getContext(); | |||
| 6305 | ASSERT_TRUE(ctx)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6305 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6306 | ||||
| 6307 | // The context should be of type map and not contain any parameters. | |||
| 6308 | EXPECT_EQ(Element::map, ctx->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("Element::map" , "ctx->getType()", Element::map, ctx->getType()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6308, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6309 | EXPECT_EQ(0, ctx->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "ctx->size()" , 0, ctx->size()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6309, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6310 | } | |||
| 6311 | ||||
| 6312 | // Test verifies that it's possible to specify parameters in the user context | |||
| 6313 | // in the address pool. | |||
| 6314 | TEST_F(Dhcp4ParserTest, poolUserContextData)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("poolUserContextData") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_poolUserContextData_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_poolUserContextData_Test() = default ; ~Dhcp4ParserTest_poolUserContextData_Test() override = default ; Dhcp4ParserTest_poolUserContextData_Test (const Dhcp4ParserTest_poolUserContextData_Test &) = delete; Dhcp4ParserTest_poolUserContextData_Test & operator=( const Dhcp4ParserTest_poolUserContextData_Test & ) = delete; Dhcp4ParserTest_poolUserContextData_Test (Dhcp4ParserTest_poolUserContextData_Test &&) noexcept = delete; Dhcp4ParserTest_poolUserContextData_Test & operator=( Dhcp4ParserTest_poolUserContextData_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_poolUserContextData_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "poolUserContextData", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6314), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6314), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6314), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_poolUserContextData_Test >); void Dhcp4ParserTest_poolUserContextData_Test::TestBody () { | |||
| 6315 | extractConfig(PARSER_CONFIGS[2]); | |||
| 6316 | PoolPtr pool; | |||
| 6317 | getPool(string(PARSER_CONFIGS[2]), 0, 0, pool); | |||
| 6318 | ASSERT_TRUE(pool)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6318 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6319 | ConstElementPtr ctx = pool->getContext(); | |||
| 6320 | ASSERT_TRUE(ctx)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6320 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6321 | ||||
| 6322 | // The context should be of type map and contain 4 parameters. | |||
| 6323 | EXPECT_EQ(Element::map, ctx->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("Element::map" , "ctx->getType()", Element::map, ctx->getType()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6323, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6324 | EXPECT_EQ(3, ctx->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("3", "ctx->size()" , 3, ctx->size()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6324, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6325 | ConstElementPtr int_param = ctx->get("integer-param"); | |||
| 6326 | ConstElementPtr str_param = ctx->get("string-param"); | |||
| 6327 | ConstElementPtr bool_param = ctx->get("bool-param"); | |||
| 6328 | ||||
| 6329 | ASSERT_TRUE(int_param)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(int_param)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6329, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "int_param", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6330 | ASSERT_EQ(Element::integer, int_param->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("Element::integer" , "int_param->getType()", Element::integer, int_param-> getType()))) ; else return ::testing::internal::AssertHelper( ::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6330, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6331 | int64_t int_value; | |||
| 6332 | EXPECT_NO_THROW(int_param->getValue(int_value))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { int_param->getValue(int_value); } else static_assert(true , ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_6332 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_6332 ; } } else gtest_label_testnothrow_6332 : ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6332, ("Expected: " "int_param->getValue(int_value)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 6333 | EXPECT_EQ(42L, int_value)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("42L", "int_value" , 42L, int_value))) ; else ::testing::internal::AssertHelper( ::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6333, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6334 | ||||
| 6335 | ASSERT_TRUE(str_param)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(str_param)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6335, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "str_param", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6336 | ASSERT_EQ(Element::string, str_param->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("Element::string" , "str_param->getType()", Element::string, str_param->getType ()))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6336, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6337 | EXPECT_EQ("Sagittarius", str_param->stringValue())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"Sagittarius\"" , "str_param->stringValue()", "Sagittarius", str_param-> stringValue()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6337, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6338 | ||||
| 6339 | ASSERT_TRUE(bool_param)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(bool_param)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6339, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "bool_param", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6340 | bool bool_value; | |||
| 6341 | ASSERT_EQ(Element::boolean, bool_param->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("Element::boolean" , "bool_param->getType()", Element::boolean, bool_param-> getType()))) ; else return ::testing::internal::AssertHelper( ::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6341, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6342 | EXPECT_NO_THROW(bool_param->getValue(bool_value))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { bool_param->getValue(bool_value); } else static_assert(true , ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_6342 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_6342 ; } } else gtest_label_testnothrow_6342 : ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6342, ("Expected: " "bool_param->getValue(bool_value)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 6343 | EXPECT_TRUE(bool_value)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(bool_value)) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6343 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "bool_value", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6344 | } | |||
| 6345 | ||||
| 6346 | // Test verifies that it's possible to specify parameters in the user context | |||
| 6347 | // in the min-max address pool. | |||
| 6348 | TEST_F(Dhcp4ParserTest, poolMinMaxUserContext)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("poolMinMaxUserContext") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_poolMinMaxUserContext_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_poolMinMaxUserContext_Test() = default ; ~Dhcp4ParserTest_poolMinMaxUserContext_Test() override = default ; Dhcp4ParserTest_poolMinMaxUserContext_Test (const Dhcp4ParserTest_poolMinMaxUserContext_Test &) = delete; Dhcp4ParserTest_poolMinMaxUserContext_Test & operator=( const Dhcp4ParserTest_poolMinMaxUserContext_Test & ) = delete; Dhcp4ParserTest_poolMinMaxUserContext_Test (Dhcp4ParserTest_poolMinMaxUserContext_Test &&) noexcept = delete; Dhcp4ParserTest_poolMinMaxUserContext_Test & operator=( Dhcp4ParserTest_poolMinMaxUserContext_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_poolMinMaxUserContext_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "poolMinMaxUserContext", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6348), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6348), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6348), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_poolMinMaxUserContext_Test >); void Dhcp4ParserTest_poolMinMaxUserContext_Test::TestBody () { | |||
| 6349 | extractConfig(PARSER_CONFIGS[3]); | |||
| 6350 | PoolPtr pool; | |||
| 6351 | getPool(string(PARSER_CONFIGS[3]), 0, 0, pool); | |||
| 6352 | ASSERT_TRUE(pool)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6352 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool", "false", "true") .c_str()) = ::testing::Message(); | |||
| ||||
| 6353 | ConstElementPtr ctx = pool->getContext(); | |||
| 6354 | ASSERT_TRUE(ctx)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6354 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6355 | ||||
| 6356 | // The context should be of type map and contain 4 parameters. | |||
| 6357 | EXPECT_EQ(Element::map, ctx->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("Element::map" , "ctx->getType()", Element::map, ctx->getType()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6357, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6358 | EXPECT_EQ(3, ctx->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("3", "ctx->size()" , 3, ctx->size()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6358, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6359 | ConstElementPtr int_param = ctx->get("integer-param"); | |||
| 6360 | ConstElementPtr str_param = ctx->get("string-param"); | |||
| 6361 | ConstElementPtr bool_param = ctx->get("bool-param"); | |||
| 6362 | ||||
| 6363 | ASSERT_TRUE(int_param)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(int_param)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6363, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "int_param", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6364 | ASSERT_EQ(Element::integer, int_param->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("Element::integer" , "int_param->getType()", Element::integer, int_param-> getType()))) ; else return ::testing::internal::AssertHelper( ::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6364, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6365 | int64_t int_value; | |||
| 6366 | EXPECT_NO_THROW(int_param->getValue(int_value))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { int_param->getValue(int_value); } else static_assert(true , ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_6366 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_6366 ; } } else gtest_label_testnothrow_6366 : ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6366, ("Expected: " "int_param->getValue(int_value)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 6367 | EXPECT_EQ(42L, int_value)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("42L", "int_value" , 42L, int_value))) ; else ::testing::internal::AssertHelper( ::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6367, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6368 | ||||
| 6369 | ASSERT_TRUE(str_param)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(str_param)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6369, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "str_param", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6370 | ASSERT_EQ(Element::string, str_param->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("Element::string" , "str_param->getType()", Element::string, str_param->getType ()))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6370, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6371 | EXPECT_EQ("Sagittarius", str_param->stringValue())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"Sagittarius\"" , "str_param->stringValue()", "Sagittarius", str_param-> stringValue()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6371, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6372 | ||||
| 6373 | ASSERT_TRUE(bool_param)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(bool_param)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6373, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "bool_param", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6374 | bool bool_value; | |||
| 6375 | ASSERT_EQ(Element::boolean, bool_param->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("Element::boolean" , "bool_param->getType()", Element::boolean, bool_param-> getType()))) ; else return ::testing::internal::AssertHelper( ::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6375, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6376 | EXPECT_NO_THROW(bool_param->getValue(bool_value))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { bool_param->getValue(bool_value); } else static_assert(true , ""); } catch (std::exception const& e) { gtest_msg.value = "it throws "; gtest_msg.value += ::testing::internal::GetTypeName (typeid(e)); gtest_msg.value += " with description \""; gtest_msg .value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_6376 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_6376 ; } } else gtest_label_testnothrow_6376 : ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6376, ("Expected: " "bool_param->getValue(bool_value)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 6377 | EXPECT_TRUE(bool_value)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(bool_value)) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6377 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "bool_value", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6378 | } | |||
| 6379 | ||||
| 6380 | // Test verifies the error message for an incorrect pool range | |||
| 6381 | // is what we expect. | |||
| 6382 | TEST_F(Dhcp4ParserTest, invalidPoolRange)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("invalidPoolRange") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_invalidPoolRange_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_invalidPoolRange_Test() = default; ~Dhcp4ParserTest_invalidPoolRange_Test() override = default; Dhcp4ParserTest_invalidPoolRange_Test (const Dhcp4ParserTest_invalidPoolRange_Test &) = delete; Dhcp4ParserTest_invalidPoolRange_Test & operator=( const Dhcp4ParserTest_invalidPoolRange_Test & ) = delete; Dhcp4ParserTest_invalidPoolRange_Test (Dhcp4ParserTest_invalidPoolRange_Test &&) noexcept = delete; Dhcp4ParserTest_invalidPoolRange_Test & operator=( Dhcp4ParserTest_invalidPoolRange_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_invalidPoolRange_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "invalidPoolRange", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6382), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6382), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6382), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_invalidPoolRange_Test >); void Dhcp4ParserTest_invalidPoolRange_Test::TestBody() { | |||
| 6383 | string config = "{ " + genIfaceConfig() + ", \n" + | |||
| 6384 | "\"valid-lifetime\": 4000, \n" | |||
| 6385 | "\"rebind-timer\": 2000, \n" | |||
| 6386 | "\"renew-timer\": 1000, \n" | |||
| 6387 | "\"subnet4\": [ { \n" | |||
| 6388 | " \"id\": 1, \n" | |||
| 6389 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 19.2.0.200\" } ], \n" | |||
| 6390 | " \"subnet\": \"192.0.2.0/24\" \n" | |||
| 6391 | " } ] \n" | |||
| 6392 | "} \n"; | |||
| 6393 | ||||
| 6394 | string expected = "Failed to create pool defined by: " | |||
| 6395 | "192.0.2.1-19.2.0.200 (<string>:7:26)"; | |||
| 6396 | ||||
| 6397 | configure(config, CONTROL_RESULT_ERROR, expected); | |||
| 6398 | } | |||
| 6399 | ||||
| 6400 | // Test verifies the error message for an outside subnet pool range | |||
| 6401 | // is what we expect. | |||
| 6402 | TEST_F(Dhcp4ParserTest, outsideSubnetPool)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("outsideSubnetPool") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_outsideSubnetPool_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_outsideSubnetPool_Test() = default ; ~Dhcp4ParserTest_outsideSubnetPool_Test() override = default ; Dhcp4ParserTest_outsideSubnetPool_Test (const Dhcp4ParserTest_outsideSubnetPool_Test &) = delete; Dhcp4ParserTest_outsideSubnetPool_Test & operator=( const Dhcp4ParserTest_outsideSubnetPool_Test & ) = delete; Dhcp4ParserTest_outsideSubnetPool_Test (Dhcp4ParserTest_outsideSubnetPool_Test &&) noexcept = delete; Dhcp4ParserTest_outsideSubnetPool_Test & operator=( Dhcp4ParserTest_outsideSubnetPool_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_outsideSubnetPool_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "outsideSubnetPool", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6402), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6402), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6402), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_outsideSubnetPool_Test >); void Dhcp4ParserTest_outsideSubnetPool_Test::TestBody( ) { | |||
| 6403 | string config = "{ " + genIfaceConfig() + ", \n" + | |||
| 6404 | "\"valid-lifetime\": 4000, \n" | |||
| 6405 | "\"rebind-timer\": 2000, \n" | |||
| 6406 | "\"renew-timer\": 1000, \n" | |||
| 6407 | "\"subnet4\": [ { \n" | |||
| 6408 | " \"id\": 1, \n" | |||
| 6409 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ], \n" | |||
| 6410 | " \"subnet\": \"10.0.2.0/24\" \n" | |||
| 6411 | " } ] \n" | |||
| 6412 | "} \n"; | |||
| 6413 | ||||
| 6414 | string expected = "subnet configuration failed: " | |||
| 6415 | "a pool of type V4, with the following address range: " | |||
| 6416 | "192.0.2.1-192.0.2.100 does not match the prefix of a subnet: " | |||
| 6417 | "10.0.2.0/24 to which it is being added (<string>:5:14)"; | |||
| 6418 | ||||
| 6419 | configure(config, CONTROL_RESULT_ERROR, expected); | |||
| 6420 | } | |||
| 6421 | ||||
| 6422 | // Test verifies that empty shared networks are accepted. | |||
| 6423 | TEST_F(Dhcp4ParserTest, sharedNetworksEmpty)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("sharedNetworksEmpty") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_sharedNetworksEmpty_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_sharedNetworksEmpty_Test() = default ; ~Dhcp4ParserTest_sharedNetworksEmpty_Test() override = default ; Dhcp4ParserTest_sharedNetworksEmpty_Test (const Dhcp4ParserTest_sharedNetworksEmpty_Test &) = delete; Dhcp4ParserTest_sharedNetworksEmpty_Test & operator=( const Dhcp4ParserTest_sharedNetworksEmpty_Test & ) = delete; Dhcp4ParserTest_sharedNetworksEmpty_Test (Dhcp4ParserTest_sharedNetworksEmpty_Test &&) noexcept = delete; Dhcp4ParserTest_sharedNetworksEmpty_Test & operator=( Dhcp4ParserTest_sharedNetworksEmpty_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_sharedNetworksEmpty_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "sharedNetworksEmpty", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6423), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6423), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6423), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_sharedNetworksEmpty_Test >); void Dhcp4ParserTest_sharedNetworksEmpty_Test::TestBody () { | |||
| 6424 | string config = "{\n" | |||
| 6425 | "\"valid-lifetime\": 4000, \n" | |||
| 6426 | "\"rebind-timer\": 2000, \n" | |||
| 6427 | "\"renew-timer\": 1000, \n" | |||
| 6428 | "\"subnet4\": [ { \n" | |||
| 6429 | " \"id\": 1, \n" | |||
| 6430 | " \"pools\": [ { \"pool\": \"10.0.2.1 - 10.0.2.100\" } ], \n" | |||
| 6431 | " \"subnet\": \"10.0.2.0/24\" \n" | |||
| 6432 | " } ],\n" | |||
| 6433 | "\"shared-networks\": [ ]\n" | |||
| 6434 | "} \n"; | |||
| 6435 | ||||
| 6436 | configure(config, CONTROL_RESULT_SUCCESS, ""); | |||
| 6437 | } | |||
| 6438 | ||||
| 6439 | // Test verifies that if a shared network is defined, it at least has to have | |||
| 6440 | // a name. | |||
| 6441 | TEST_F(Dhcp4ParserTest, sharedNetworksNoName)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("sharedNetworksNoName") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_sharedNetworksNoName_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_sharedNetworksNoName_Test() = default ; ~Dhcp4ParserTest_sharedNetworksNoName_Test() override = default ; Dhcp4ParserTest_sharedNetworksNoName_Test (const Dhcp4ParserTest_sharedNetworksNoName_Test &) = delete; Dhcp4ParserTest_sharedNetworksNoName_Test & operator=( const Dhcp4ParserTest_sharedNetworksNoName_Test & ) = delete; Dhcp4ParserTest_sharedNetworksNoName_Test (Dhcp4ParserTest_sharedNetworksNoName_Test &&) noexcept = delete; Dhcp4ParserTest_sharedNetworksNoName_Test & operator=( Dhcp4ParserTest_sharedNetworksNoName_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_sharedNetworksNoName_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "sharedNetworksNoName", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6441), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6441), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6441), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_sharedNetworksNoName_Test >); void Dhcp4ParserTest_sharedNetworksNoName_Test::TestBody () { | |||
| 6442 | string config = "{\n" | |||
| 6443 | "\"valid-lifetime\": 4000, \n" | |||
| 6444 | "\"rebind-timer\": 2000, \n" | |||
| 6445 | "\"renew-timer\": 1000, \n" | |||
| 6446 | "\"subnet4\": [ { \n" | |||
| 6447 | " \"id\": 1, \n" | |||
| 6448 | " \"pools\": [ { \"pool\": \"10.0.2.1 - 10.0.2.100\" } ], \n" | |||
| 6449 | " \"subnet\": \"10.0.2.0/24\" \n" | |||
| 6450 | " } ],\n" | |||
| 6451 | "\"shared-networks\": [ { } ]\n" | |||
| 6452 | "} \n"; | |||
| 6453 | ||||
| 6454 | EXPECT_THROW(parseDHCP4(config, true), Dhcp4ParseError)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { parseDHCP4(config, true) ; } else static_assert(true, ""); } catch (Dhcp4ParseError const &) { gtest_caught_expected = true; } catch (typename std:: conditional< std::is_same<typename std::remove_cv<typename std::remove_reference< Dhcp4ParseError>::type>::type , std::exception>::value, const ::testing::internal::NeverThrown &, const std::exception&>::type e) { gtest_msg.value = "Expected: " "parseDHCP4(config, true)" " throws an exception of type " "Dhcp4ParseError" ".\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_6454; } catch (... ) { gtest_msg.value = "Expected: " "parseDHCP4(config, true)" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_6454; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "parseDHCP4(config, true)" " throws an exception of type " "Dhcp4ParseError" ".\n Actual: it throws nothing." ; goto gtest_label_testthrow_6454; } } else gtest_label_testthrow_6454 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6454, gtest_msg.value.c_str()) = ::testing::Message(); | |||
| 6455 | } | |||
| 6456 | ||||
| 6457 | // Test verifies that empty shared networks are accepted. | |||
| 6458 | TEST_F(Dhcp4ParserTest, sharedNetworksEmptyName)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("sharedNetworksEmptyName") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_sharedNetworksEmptyName_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_sharedNetworksEmptyName_Test () = default; ~Dhcp4ParserTest_sharedNetworksEmptyName_Test() override = default; Dhcp4ParserTest_sharedNetworksEmptyName_Test (const Dhcp4ParserTest_sharedNetworksEmptyName_Test &) = delete; Dhcp4ParserTest_sharedNetworksEmptyName_Test & operator =( const Dhcp4ParserTest_sharedNetworksEmptyName_Test &) = delete; Dhcp4ParserTest_sharedNetworksEmptyName_Test (Dhcp4ParserTest_sharedNetworksEmptyName_Test &&) noexcept = delete; Dhcp4ParserTest_sharedNetworksEmptyName_Test & operator=( Dhcp4ParserTest_sharedNetworksEmptyName_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_sharedNetworksEmptyName_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "sharedNetworksEmptyName", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6458), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6458), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6458), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_sharedNetworksEmptyName_Test >); void Dhcp4ParserTest_sharedNetworksEmptyName_Test::TestBody () { | |||
| 6459 | string config = "{\n" | |||
| 6460 | "\"valid-lifetime\": 4000, \n" | |||
| 6461 | "\"rebind-timer\": 2000, \n" | |||
| 6462 | "\"renew-timer\": 1000, \n" | |||
| 6463 | "\"subnet4\": [ { \n" | |||
| 6464 | " \"id\": 1, \n" | |||
| 6465 | " \"pools\": [ { \"pool\": \"10.0.2.1 - 10.0.2.100\" } ], \n" | |||
| 6466 | " \"subnet\": \"10.0.2.0/24\" \n" | |||
| 6467 | " } ],\n" | |||
| 6468 | "\"shared-networks\": [ { \"name\": \"\" } ]\n" | |||
| 6469 | "} \n"; | |||
| 6470 | ||||
| 6471 | configure(config, CONTROL_RESULT_ERROR, | |||
| 6472 | "Shared-network with subnets is missing mandatory 'name' parameter"); | |||
| 6473 | } | |||
| 6474 | ||||
| 6475 | // Test verifies that a degenerated shared-network (no subnets) is | |||
| 6476 | // accepted. | |||
| 6477 | TEST_F(Dhcp4ParserTest, sharedNetworksName)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("sharedNetworksName") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_sharedNetworksName_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_sharedNetworksName_Test() = default ; ~Dhcp4ParserTest_sharedNetworksName_Test() override = default ; Dhcp4ParserTest_sharedNetworksName_Test (const Dhcp4ParserTest_sharedNetworksName_Test &) = delete; Dhcp4ParserTest_sharedNetworksName_Test & operator=( const Dhcp4ParserTest_sharedNetworksName_Test & ) = delete; Dhcp4ParserTest_sharedNetworksName_Test (Dhcp4ParserTest_sharedNetworksName_Test &&) noexcept = delete; Dhcp4ParserTest_sharedNetworksName_Test & operator=( Dhcp4ParserTest_sharedNetworksName_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_sharedNetworksName_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "sharedNetworksName", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6477), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6477), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6477), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_sharedNetworksName_Test >); void Dhcp4ParserTest_sharedNetworksName_Test::TestBody () { | |||
| 6478 | string config = "{\n" | |||
| 6479 | "\"subnet4\": [ { \n" | |||
| 6480 | " \"id\": 1, \n" | |||
| 6481 | " \"pools\": [ { \"pool\": \"10.0.2.1 - 10.0.2.100\" } ], \n" | |||
| 6482 | " \"subnet\": \"10.0.2.0/24\" \n" | |||
| 6483 | " } ],\n" | |||
| 6484 | "\"shared-networks\": [ { \"name\": \"foo\" } ]\n" | |||
| 6485 | "} \n"; | |||
| 6486 | ||||
| 6487 | configure(config, CONTROL_RESULT_SUCCESS, ""); | |||
| 6488 | ||||
| 6489 | // Now verify that the shared network was indeed configured. | |||
| 6490 | CfgSharedNetworks4Ptr cfg_net = CfgMgr::instance().getStagingCfg() | |||
| 6491 | ->getCfgSharedNetworks4(); | |||
| 6492 | ASSERT_TRUE(cfg_net)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(cfg_net)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6492, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "cfg_net", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 6493 | const SharedNetwork4Collection* nets = cfg_net->getAll(); | |||
| 6494 | ASSERT_TRUE(nets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(nets)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6494 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "nets", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6495 | ASSERT_EQ(1, nets->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "nets->size()" , 1, nets->size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6495, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6496 | SharedNetwork4Ptr net = *(nets->begin()); | |||
| 6497 | ASSERT_TRUE(net)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(net)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6497 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "net", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6498 | EXPECT_EQ("foo", net->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"foo\"" , "net->getName()", "foo", net->getName()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6498 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6499 | ||||
| 6500 | // Verify that there are no subnets in this shared-network | |||
| 6501 | const Subnet4SimpleCollection* subs = net->getAllSubnets(); | |||
| 6502 | ASSERT_TRUE(subs)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subs)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6502 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subs", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6503 | EXPECT_EQ(0, subs->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0", "subs->size()" , 0, subs->size()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6503, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6504 | } | |||
| 6505 | ||||
| 6506 | // Test verifies that a degenerated shared-network (just one subnet) is | |||
| 6507 | // accepted. Also tests that, unless explicitly specified, the subnet | |||
| 6508 | // gets default values. | |||
| 6509 | TEST_F(Dhcp4ParserTest, sharedNetworks1subnet)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("sharedNetworks1subnet") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_sharedNetworks1subnet_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_sharedNetworks1subnet_Test() = default ; ~Dhcp4ParserTest_sharedNetworks1subnet_Test() override = default ; Dhcp4ParserTest_sharedNetworks1subnet_Test (const Dhcp4ParserTest_sharedNetworks1subnet_Test &) = delete; Dhcp4ParserTest_sharedNetworks1subnet_Test & operator=( const Dhcp4ParserTest_sharedNetworks1subnet_Test & ) = delete; Dhcp4ParserTest_sharedNetworks1subnet_Test (Dhcp4ParserTest_sharedNetworks1subnet_Test &&) noexcept = delete; Dhcp4ParserTest_sharedNetworks1subnet_Test & operator=( Dhcp4ParserTest_sharedNetworks1subnet_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_sharedNetworks1subnet_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "sharedNetworks1subnet", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6509), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6509), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6509), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_sharedNetworks1subnet_Test >); void Dhcp4ParserTest_sharedNetworks1subnet_Test::TestBody () { | |||
| 6510 | string config = "{\n" | |||
| 6511 | "\"shared-networks\": [ {\n" | |||
| 6512 | " \"name\": \"foo\"\n," | |||
| 6513 | " \"subnet4\": [ { \n" | |||
| 6514 | " \"id\": 1,\n" | |||
| 6515 | " \"subnet\": \"192.0.2.0/24\",\n" | |||
| 6516 | " \"pools\": [ { \"pool\": \"192.0.2.1-192.0.2.10\" } ]\n" | |||
| 6517 | " } ]\n" | |||
| 6518 | " } ]\n" | |||
| 6519 | "} \n"; | |||
| 6520 | ||||
| 6521 | configure(config, CONTROL_RESULT_SUCCESS, ""); | |||
| 6522 | ||||
| 6523 | // Now verify that the shared network was indeed configured. | |||
| 6524 | CfgSharedNetworks4Ptr cfg_net = CfgMgr::instance().getStagingCfg() | |||
| 6525 | ->getCfgSharedNetworks4(); | |||
| 6526 | ASSERT_TRUE(cfg_net)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(cfg_net)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6526, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "cfg_net", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 6527 | ||||
| 6528 | // There should be exactly one shared subnet. | |||
| 6529 | const SharedNetwork4Collection* nets = cfg_net->getAll(); | |||
| 6530 | ASSERT_TRUE(nets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(nets)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6530 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "nets", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6531 | ASSERT_EQ(1, nets->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "nets->size()" , 1, nets->size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6531, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6532 | ||||
| 6533 | SharedNetwork4Ptr net = *(nets->begin()); | |||
| 6534 | ASSERT_TRUE(net)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(net)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6534 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "net", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6535 | EXPECT_EQ("foo", net->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"foo\"" , "net->getName()", "foo", net->getName()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6535 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6536 | ||||
| 6537 | // It should have one subnet. The subnet should have default values. | |||
| 6538 | const Subnet4SimpleCollection* subs = net->getAllSubnets(); | |||
| 6539 | ASSERT_TRUE(subs)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subs)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6539 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subs", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6540 | EXPECT_EQ(1, subs->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "subs->size()" , 1, subs->size()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6540, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6541 | checkSubnet(*subs, "192.0.2.0/24", 0, 0, 7200); | |||
| 6542 | ||||
| 6543 | // Now make sure the subnet was added to global list of subnets. | |||
| 6544 | CfgSubnets4Ptr subnets4 = CfgMgr::instance().getStagingCfg()->getCfgSubnets4(); | |||
| 6545 | ASSERT_TRUE(subnets4)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnets4)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6545, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnets4", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6546 | ||||
| 6547 | const Subnet4Collection* gsubs = subnets4->getAll(); | |||
| 6548 | ASSERT_TRUE(gsubs)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(gsubs)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6548, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "gsubs", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6549 | checkSubnet(*gsubs, "192.0.2.0/24", 0, 0, 7200); | |||
| 6550 | } | |||
| 6551 | ||||
| 6552 | // Test verifies that a proper shared-network (three subnets) is | |||
| 6553 | // accepted. It verifies several things: | |||
| 6554 | // - that more than one subnet can be added to shared subnets | |||
| 6555 | // - that each subnet being part of the shared subnets is also stored in | |||
| 6556 | // global subnets collection | |||
| 6557 | // - that a subnet can inherit global values | |||
| 6558 | // - that subnet can override global parameters | |||
| 6559 | // - that overridden parameters only affect one subnet and not others | |||
| 6560 | TEST_F(Dhcp4ParserTest, sharedNetworks3subnets)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("sharedNetworks3subnets") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_sharedNetworks3subnets_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_sharedNetworks3subnets_Test () = default; ~Dhcp4ParserTest_sharedNetworks3subnets_Test() override = default; Dhcp4ParserTest_sharedNetworks3subnets_Test (const Dhcp4ParserTest_sharedNetworks3subnets_Test &) = delete; Dhcp4ParserTest_sharedNetworks3subnets_Test & operator=( const Dhcp4ParserTest_sharedNetworks3subnets_Test &) = delete ; Dhcp4ParserTest_sharedNetworks3subnets_Test (Dhcp4ParserTest_sharedNetworks3subnets_Test &&) noexcept = delete; Dhcp4ParserTest_sharedNetworks3subnets_Test & operator=( Dhcp4ParserTest_sharedNetworks3subnets_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_sharedNetworks3subnets_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "sharedNetworks3subnets", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6560), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6560), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6560), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_sharedNetworks3subnets_Test >); void Dhcp4ParserTest_sharedNetworks3subnets_Test::TestBody () { | |||
| 6561 | string config = "{\n" | |||
| 6562 | "\"valid-lifetime\": 4000, \n" | |||
| 6563 | "\"min-valid-lifetime\": 3000, \n" | |||
| 6564 | "\"max-valid-lifetime\": 5000, \n" | |||
| 6565 | "\"renew-timer\": 1000, \n" | |||
| 6566 | "\"rebind-timer\": 2000, \n" | |||
| 6567 | "\"shared-networks\": [ {\n" | |||
| 6568 | " \"name\": \"foo\"\n," | |||
| 6569 | " \"subnet4\": [\n" | |||
| 6570 | " { \n" | |||
| 6571 | " \"id\": 1,\n" | |||
| 6572 | " \"subnet\": \"192.0.1.0/24\",\n" | |||
| 6573 | " \"pools\": [ { \"pool\": \"192.0.1.1-192.0.1.10\" } ]\n" | |||
| 6574 | " },\n" | |||
| 6575 | " { \n" | |||
| 6576 | " \"id\": 2,\n" | |||
| 6577 | " \"subnet\": \"192.0.2.0/24\",\n" | |||
| 6578 | " \"pools\": [ { \"pool\": \"192.0.2.1-192.0.2.10\" } ],\n" | |||
| 6579 | " \"renew-timer\": 2,\n" | |||
| 6580 | " \"rebind-timer\": 22,\n" | |||
| 6581 | " \"valid-lifetime\": 222,\n" | |||
| 6582 | " \"min-valid-lifetime\": 111,\n" | |||
| 6583 | " \"max-valid-lifetime\": 333\n" | |||
| 6584 | " },\n" | |||
| 6585 | " { \n" | |||
| 6586 | " \"id\": 3,\n" | |||
| 6587 | " \"subnet\": \"192.0.3.0/24\",\n" | |||
| 6588 | " \"pools\": [ { \"pool\": \"192.0.3.1-192.0.3.10\" } ]\n" | |||
| 6589 | " }\n" | |||
| 6590 | " ]\n" | |||
| 6591 | " } ]\n" | |||
| 6592 | "} \n"; | |||
| 6593 | ||||
| 6594 | configure(config, CONTROL_RESULT_SUCCESS, ""); | |||
| 6595 | ||||
| 6596 | // Now verify that the shared network was indeed configured. | |||
| 6597 | CfgSharedNetworks4Ptr cfg_net = CfgMgr::instance().getStagingCfg() | |||
| 6598 | ->getCfgSharedNetworks4(); | |||
| 6599 | ||||
| 6600 | // There is expected one shared subnet. | |||
| 6601 | ASSERT_TRUE(cfg_net)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(cfg_net)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6601, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "cfg_net", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 6602 | const SharedNetwork4Collection* nets = cfg_net->getAll(); | |||
| 6603 | ASSERT_TRUE(nets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(nets)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6603 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "nets", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6604 | ASSERT_EQ(1, nets->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "nets->size()" , 1, nets->size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6604, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6605 | ||||
| 6606 | SharedNetwork4Ptr net = *(nets->begin()); | |||
| 6607 | ASSERT_TRUE(net)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(net)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6607 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "net", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6608 | ||||
| 6609 | EXPECT_EQ("foo", net->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"foo\"" , "net->getName()", "foo", net->getName()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6609 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6610 | ||||
| 6611 | const Subnet4SimpleCollection* subs = net->getAllSubnets(); | |||
| 6612 | ASSERT_TRUE(subs)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subs)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6612 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subs", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6613 | EXPECT_EQ(3, subs->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("3", "subs->size()" , 3, subs->size()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6613, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6614 | checkSubnet(*subs, "192.0.1.0/24", 1000, 2000, 4000, 3000, 5000); | |||
| 6615 | checkSubnet(*subs, "192.0.2.0/24", 2, 22, 222, 111, 333); | |||
| 6616 | checkSubnet(*subs, "192.0.3.0/24", 1000, 2000, 4000, 3000, 5000); | |||
| 6617 | ||||
| 6618 | // Now make sure the subnet was added to global list of subnets. | |||
| 6619 | CfgSubnets4Ptr subnets4 = CfgMgr::instance().getStagingCfg()->getCfgSubnets4(); | |||
| 6620 | ASSERT_TRUE(subnets4)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnets4)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6620, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnets4", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6621 | ||||
| 6622 | const Subnet4Collection* gsubs = subnets4->getAll(); | |||
| 6623 | ASSERT_TRUE(gsubs)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(gsubs)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6623, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "gsubs", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6624 | checkSubnet(*gsubs, "192.0.1.0/24", 1000, 2000, 4000, 3000, 5000); | |||
| 6625 | checkSubnet(*gsubs, "192.0.2.0/24", 2, 22, 222, 111, 333); | |||
| 6626 | checkSubnet(*gsubs, "192.0.3.0/24", 1000, 2000, 4000, 3000, 5000); | |||
| 6627 | } | |||
| 6628 | ||||
| 6629 | // This test checks if parameters are derived properly: | |||
| 6630 | // - global to shared network | |||
| 6631 | // - shared network to subnet | |||
| 6632 | // Also, it tests that more than one shared network can be defined. | |||
| 6633 | TEST_F(Dhcp4ParserTest, sharedNetworksDerive)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("sharedNetworksDerive") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_sharedNetworksDerive_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_sharedNetworksDerive_Test() = default ; ~Dhcp4ParserTest_sharedNetworksDerive_Test() override = default ; Dhcp4ParserTest_sharedNetworksDerive_Test (const Dhcp4ParserTest_sharedNetworksDerive_Test &) = delete; Dhcp4ParserTest_sharedNetworksDerive_Test & operator=( const Dhcp4ParserTest_sharedNetworksDerive_Test & ) = delete; Dhcp4ParserTest_sharedNetworksDerive_Test (Dhcp4ParserTest_sharedNetworksDerive_Test &&) noexcept = delete; Dhcp4ParserTest_sharedNetworksDerive_Test & operator=( Dhcp4ParserTest_sharedNetworksDerive_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_sharedNetworksDerive_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "sharedNetworksDerive", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6633), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6633), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6633), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_sharedNetworksDerive_Test >); void Dhcp4ParserTest_sharedNetworksDerive_Test::TestBody () { | |||
| 6634 | ||||
| 6635 | // We need to fake the interfaces present, because we want to test | |||
| 6636 | // interface names inheritance. However, there are sanity checks | |||
| 6637 | // on subnet level that would refuse the value if the interface | |||
| 6638 | // is not present. | |||
| 6639 | IfaceMgrTestConfig iface_config(true); | |||
| 6640 | ||||
| 6641 | // This config is structured in a way that the first shared | |||
| 6642 | // subnet have many parameters defined. The first subnet | |||
| 6643 | // should inherit them. The second subnet overrides all | |||
| 6644 | // values and those values should be used, not those from | |||
| 6645 | // shared network scope. | |||
| 6646 | string config = "{\n" | |||
| 6647 | "\"renew-timer\": 1, \n" // global values here | |||
| 6648 | "\"rebind-timer\": 2, \n" | |||
| 6649 | "\"valid-lifetime\": 4, \n" | |||
| 6650 | "\"min-valid-lifetime\": 3, \n" | |||
| 6651 | "\"max-valid-lifetime\": 5, \n" | |||
| 6652 | "\"shared-networks\": [ {\n" | |||
| 6653 | " \"name\": \"foo\"\n," // shared network values here | |||
| 6654 | " \"interface\": \"eth0\",\n" | |||
| 6655 | " \"match-client-id\": false,\n" | |||
| 6656 | " \"authoritative\": true,\n" | |||
| 6657 | " \"next-server\": \"1.2.3.4\",\n" | |||
| 6658 | " \"server-hostname\": \"foo\",\n" | |||
| 6659 | " \"boot-file-name\": \"bar\",\n" | |||
| 6660 | " \"store-extended-info\": true,\n" | |||
| 6661 | " \"relay\": {\n" | |||
| 6662 | " \"ip-addresses\": [ \"5.6.7.8\" ]\n" | |||
| 6663 | " },\n" | |||
| 6664 | " \"reservations-global\": false,\n" | |||
| 6665 | " \"reservations-in-subnet\": false,\n" | |||
| 6666 | " \"renew-timer\": 10,\n" | |||
| 6667 | " \"rebind-timer\": 20,\n" | |||
| 6668 | " \"valid-lifetime\": 40,\n" | |||
| 6669 | " \"min-valid-lifetime\": 30,\n" | |||
| 6670 | " \"max-valid-lifetime\": 50,\n" | |||
| 6671 | " \"subnet4\": [\n" | |||
| 6672 | " { \n" | |||
| 6673 | " \"id\": 1,\n" | |||
| 6674 | " \"subnet\": \"192.0.1.0/24\",\n" | |||
| 6675 | " \"pools\": [ { \"pool\": \"192.0.1.1-192.0.1.10\" } ]\n" | |||
| 6676 | " },\n" | |||
| 6677 | " { \n" | |||
| 6678 | " \"id\": 2,\n" | |||
| 6679 | " \"subnet\": \"192.0.2.0/24\",\n" | |||
| 6680 | " \"pools\": [ { \"pool\": \"192.0.2.1-192.0.2.10\" } ],\n" | |||
| 6681 | " \"renew-timer\": 100,\n" | |||
| 6682 | " \"rebind-timer\": 200,\n" | |||
| 6683 | " \"valid-lifetime\": 400,\n" | |||
| 6684 | " \"min-valid-lifetime\": 300,\n" | |||
| 6685 | " \"max-valid-lifetime\": 500,\n" | |||
| 6686 | " \"match-client-id\": true,\n" | |||
| 6687 | " \"next-server\": \"11.22.33.44\",\n" | |||
| 6688 | " \"server-hostname\": \"some-name.example.org\",\n" | |||
| 6689 | " \"boot-file-name\": \"bootfile.efi\",\n" | |||
| 6690 | " \"relay\": {\n" | |||
| 6691 | " \"ip-addresses\": [ \"55.66.77.88\" ]\n" | |||
| 6692 | " },\n" | |||
| 6693 | " \"reservations-global\": false,\n" | |||
| 6694 | " \"reservations-in-subnet\": true,\n" | |||
| 6695 | " \"reservations-out-of-pool\": true\n" | |||
| 6696 | " }\n" | |||
| 6697 | " ]\n" | |||
| 6698 | " },\n" | |||
| 6699 | "{ // second shared-network starts here\n" | |||
| 6700 | " \"name\": \"bar\",\n" | |||
| 6701 | " \"subnet4\": [\n" | |||
| 6702 | " {\n" | |||
| 6703 | " \"id\": 3,\n" | |||
| 6704 | " \"subnet\": \"192.0.3.0/24\",\n" | |||
| 6705 | " \"pools\": [ { \"pool\": \"192.0.3.1-192.0.3.10\" } ]\n" | |||
| 6706 | " }\n" | |||
| 6707 | " ]\n" | |||
| 6708 | " } ]\n" | |||
| 6709 | "} \n"; | |||
| 6710 | ||||
| 6711 | configure(config, CONTROL_RESULT_SUCCESS, ""); | |||
| 6712 | ||||
| 6713 | // Now verify that the shared network was indeed configured. | |||
| 6714 | CfgSharedNetworks4Ptr cfg_net = CfgMgr::instance().getStagingCfg() | |||
| 6715 | ->getCfgSharedNetworks4(); | |||
| 6716 | ||||
| 6717 | // Two shared networks are expected. | |||
| 6718 | ASSERT_TRUE(cfg_net)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(cfg_net)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6718, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "cfg_net", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 6719 | const SharedNetwork4Collection* nets = cfg_net->getAll(); | |||
| 6720 | ASSERT_TRUE(nets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(nets)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6720 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "nets", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6721 | ASSERT_EQ(2, nets->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "nets->size()" , 2, nets->size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6721, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6722 | ||||
| 6723 | // Let's check the first one. | |||
| 6724 | SharedNetwork4Ptr net = nets->at(0); | |||
| 6725 | ASSERT_TRUE(net)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(net)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6725 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "net", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6726 | ||||
| 6727 | // The first shared network has two subnets. | |||
| 6728 | const Subnet4SimpleCollection* subs = net->getAllSubnets(); | |||
| 6729 | ASSERT_TRUE(subs)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subs)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6729 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subs", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6730 | EXPECT_EQ(2, subs->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "subs->size()" , 2, subs->size()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6730, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6731 | ||||
| 6732 | // For the first subnet, the renew-timer should be 10, because it was | |||
| 6733 | // derived from shared-network level. Other parameters a derived | |||
| 6734 | // from global scope to shared-network level and later again to | |||
| 6735 | // subnet4 level. | |||
| 6736 | Subnet4Ptr s = checkSubnet(*subs, "192.0.1.0/24", 10, 20, 40, 30, 50); | |||
| 6737 | ASSERT_TRUE(s)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(s)) ; else return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6737 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6738 | ||||
| 6739 | // These are values derived from shared network scope: | |||
| 6740 | EXPECT_EQ("eth0", s->getIface().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"eth0\"" , "s->getIface().get()", "eth0", s->getIface().get()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6740, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6741 | EXPECT_FALSE(s->getMatchClientId())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(s->getMatchClientId ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6741, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getMatchClientId()", "true", "false") .c_str()) = :: testing::Message(); | |||
| 6742 | EXPECT_TRUE(s->getAuthoritative())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(s->getAuthoritative ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6742, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getAuthoritative()", "false", "true") .c_str()) = :: testing::Message(); | |||
| 6743 | EXPECT_TRUE(s->getStoreExtendedInfo())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(s->getStoreExtendedInfo ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6743, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getStoreExtendedInfo()", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6744 | EXPECT_EQ(IOAddress("1.2.3.4"), s->getSiaddr())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("IOAddress(\"1.2.3.4\")" , "s->getSiaddr()", IOAddress("1.2.3.4"), s->getSiaddr( )))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6744, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6745 | EXPECT_EQ("foo", s->getSname().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"foo\"" , "s->getSname().get()", "foo", s->getSname().get()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6745, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6746 | EXPECT_EQ("bar", s->getFilename().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"bar\"" , "s->getFilename().get()", "bar", s->getFilename().get ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6746, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6747 | EXPECT_TRUE(s->hasRelayAddress(IOAddress("5.6.7.8")))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(s->hasRelayAddress (IOAddress("5.6.7.8")))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6747, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->hasRelayAddress(IOAddress(\"5.6.7.8\"))", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 6748 | EXPECT_FALSE(s->getReservationsGlobal())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(s->getReservationsGlobal ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6748, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getReservationsGlobal()", "true", "false") .c_str()) = ::testing::Message(); | |||
| 6749 | EXPECT_FALSE(s->getReservationsInSubnet())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(s->getReservationsInSubnet ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6749, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getReservationsInSubnet()", "true", "false") .c_str( )) = ::testing::Message(); | |||
| 6750 | EXPECT_FALSE(s->getReservationsOutOfPool())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(s->getReservationsOutOfPool ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6750, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getReservationsOutOfPool()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 6751 | ||||
| 6752 | // For the second subnet, the renew-timer should be 100, because it | |||
| 6753 | // was specified explicitly. Other parameters a derived | |||
| 6754 | // from global scope to shared-network level and later again to | |||
| 6755 | // subnet4 level. | |||
| 6756 | s = checkSubnet(*subs, "192.0.2.0/24", 100, 200, 400, 300, 500); | |||
| 6757 | ||||
| 6758 | // These are values derived from shared network scope: | |||
| 6759 | EXPECT_EQ("eth0", s->getIface().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"eth0\"" , "s->getIface().get()", "eth0", s->getIface().get()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6759, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6760 | EXPECT_TRUE(s->getMatchClientId())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(s->getMatchClientId ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6760, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getMatchClientId()", "false", "true") .c_str()) = :: testing::Message(); | |||
| 6761 | EXPECT_TRUE(s->getAuthoritative())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(s->getAuthoritative ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6761, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getAuthoritative()", "false", "true") .c_str()) = :: testing::Message(); | |||
| 6762 | EXPECT_TRUE(s->getStoreExtendedInfo())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(s->getStoreExtendedInfo ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6762, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getStoreExtendedInfo()", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6763 | EXPECT_EQ(IOAddress("11.22.33.44"), s->getSiaddr().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("IOAddress(\"11.22.33.44\")" , "s->getSiaddr().get()", IOAddress("11.22.33.44"), s-> getSiaddr().get()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6763, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6764 | EXPECT_EQ("some-name.example.org", s->getSname().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"some-name.example.org\"" , "s->getSname().get()", "some-name.example.org", s->getSname ().get()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6764, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6765 | EXPECT_EQ("bootfile.efi", s->getFilename().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"bootfile.efi\"" , "s->getFilename().get()", "bootfile.efi", s->getFilename ().get()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6765, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6766 | EXPECT_TRUE(s->hasRelayAddress(IOAddress("55.66.77.88")))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(s->hasRelayAddress (IOAddress("55.66.77.88")))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6766, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->hasRelayAddress(IOAddress(\"55.66.77.88\"))", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 6767 | EXPECT_FALSE(s->getReservationsGlobal())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(s->getReservationsGlobal ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6767, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getReservationsGlobal()", "true", "false") .c_str()) = ::testing::Message(); | |||
| 6768 | EXPECT_TRUE(s->getReservationsInSubnet())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(s->getReservationsInSubnet ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6768, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getReservationsInSubnet()", "false", "true") .c_str( )) = ::testing::Message(); | |||
| 6769 | EXPECT_TRUE(s->getReservationsOutOfPool())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(s->getReservationsOutOfPool ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6769, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getReservationsOutOfPool()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 6770 | ||||
| 6771 | // Ok, now check the second shared subnet. | |||
| 6772 | net = nets->at(1); | |||
| 6773 | ASSERT_TRUE(net)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(net)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6773 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "net", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6774 | ||||
| 6775 | subs = net->getAllSubnets(); | |||
| 6776 | ASSERT_TRUE(subs)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subs)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6776 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subs", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6777 | EXPECT_EQ(1, subs->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "subs->size()" , 1, subs->size()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6777, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6778 | ||||
| 6779 | // This subnet should derive its renew-timer from global scope. | |||
| 6780 | // All other parameters should have default values. | |||
| 6781 | s = checkSubnet(*subs, "192.0.3.0/24", 1, 2, 4, 3, 5); | |||
| 6782 | EXPECT_EQ("", s->getIface().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\"", "s->getIface().get()" , "", s->getIface().get()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6782, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6783 | EXPECT_TRUE(s->getMatchClientId())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(s->getMatchClientId ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6783, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getMatchClientId()", "false", "true") .c_str()) = :: testing::Message(); | |||
| 6784 | EXPECT_FALSE(s->getAuthoritative())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(s->getAuthoritative ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6784, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getAuthoritative()", "true", "false") .c_str()) = :: testing::Message(); | |||
| 6785 | EXPECT_FALSE(s->getStoreExtendedInfo())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(s->getStoreExtendedInfo ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6785, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getStoreExtendedInfo()", "true", "false") .c_str()) = ::testing::Message(); | |||
| 6786 | EXPECT_EQ(IOAddress("0.0.0.0"), s->getSiaddr())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("IOAddress(\"0.0.0.0\")" , "s->getSiaddr()", IOAddress("0.0.0.0"), s->getSiaddr( )))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6786, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6787 | EXPECT_TRUE(s->getSname().empty())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(s->getSname().empty ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6787, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getSname().empty()", "false", "true") .c_str()) = :: testing::Message(); | |||
| 6788 | EXPECT_TRUE(s->getFilename().empty())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(s->getFilename().empty ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6788, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getFilename().empty()", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6789 | EXPECT_FALSE(s->hasRelays())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(s->hasRelays())) ) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6789, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->hasRelays()", "true", "false") .c_str()) = ::testing ::Message(); | |||
| 6790 | EXPECT_FALSE(s->getReservationsGlobal())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(s->getReservationsGlobal ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6790, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getReservationsGlobal()", "true", "false") .c_str()) = ::testing::Message(); | |||
| 6791 | EXPECT_TRUE(s->getReservationsInSubnet())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(s->getReservationsInSubnet ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6791, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getReservationsInSubnet()", "false", "true") .c_str( )) = ::testing::Message(); | |||
| 6792 | EXPECT_FALSE(s->getReservationsOutOfPool())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(s->getReservationsOutOfPool ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6792, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s->getReservationsOutOfPool()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 6793 | } | |||
| 6794 | ||||
| 6795 | // Since it is not allowed to define both interface-id and interface | |||
| 6796 | // for the same subnet, we need dedicated test that will check | |||
| 6797 | // interface separately. | |||
| 6798 | TEST_F(Dhcp4ParserTest, sharedNetworksDeriveInterfaces)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("sharedNetworksDeriveInterfaces") > 1, "test_name must not be empty"); class Dhcp4ParserTest_sharedNetworksDeriveInterfaces_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_sharedNetworksDeriveInterfaces_Test () = default; ~Dhcp4ParserTest_sharedNetworksDeriveInterfaces_Test () override = default; Dhcp4ParserTest_sharedNetworksDeriveInterfaces_Test (const Dhcp4ParserTest_sharedNetworksDeriveInterfaces_Test & ) = delete; Dhcp4ParserTest_sharedNetworksDeriveInterfaces_Test & operator=( const Dhcp4ParserTest_sharedNetworksDeriveInterfaces_Test &) = delete; Dhcp4ParserTest_sharedNetworksDeriveInterfaces_Test (Dhcp4ParserTest_sharedNetworksDeriveInterfaces_Test && ) noexcept = delete; Dhcp4ParserTest_sharedNetworksDeriveInterfaces_Test & operator=( Dhcp4ParserTest_sharedNetworksDeriveInterfaces_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_sharedNetworksDeriveInterfaces_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "sharedNetworksDeriveInterfaces", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6798), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6798), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6798), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_sharedNetworksDeriveInterfaces_Test >); void Dhcp4ParserTest_sharedNetworksDeriveInterfaces_Test ::TestBody() { | |||
| 6799 | ||||
| 6800 | // We need to fake the interfaces present, because we want to test | |||
| 6801 | // interface names inheritance. However, there are sanity checks | |||
| 6802 | // on subnet level that would refuse the value if the interface | |||
| 6803 | // is not present. | |||
| 6804 | IfaceMgrTestConfig iface_config(true); | |||
| 6805 | ||||
| 6806 | string config = "{\n" | |||
| 6807 | "\"shared-networks\": [ {\n" | |||
| 6808 | " \"name\": \"foo\"\n," | |||
| 6809 | " \"interface\": \"eth0\",\n" | |||
| 6810 | " \"rebind-timer\": 10, \n" | |||
| 6811 | " \"subnet4\": [\n" | |||
| 6812 | " { \n" | |||
| 6813 | " \"id\": 1, \n" | |||
| 6814 | " \"subnet\": \"192.0.1.0/24\",\n" | |||
| 6815 | " \"pools\": [ { \"pool\": \"192.0.1.1-192.0.1.10\" } ]\n" | |||
| 6816 | " },\n" | |||
| 6817 | " { \n" | |||
| 6818 | " \"id\": 2, \n" | |||
| 6819 | " \"subnet\": \"192.0.2.0/24\",\n" | |||
| 6820 | " \"rebind-timer\": 100, \n" | |||
| 6821 | " \"pools\": [ { \"pool\": \"192.0.2.1-192.0.2.10\" } ],\n" | |||
| 6822 | " \"interface\": \"eth0\"\n" | |||
| 6823 | " }\n" | |||
| 6824 | " ]\n" | |||
| 6825 | " },\n" | |||
| 6826 | "{ // second shared-network starts here\n" | |||
| 6827 | " \"name\": \"bar\",\n" | |||
| 6828 | " \"subnet4\": [\n" | |||
| 6829 | " {\n" | |||
| 6830 | " \"id\": 3, \n" | |||
| 6831 | " \"subnet\": \"192.0.3.0/24\",\n" | |||
| 6832 | " \"pools\": [ { \"pool\": \"192.0.3.1-192.0.3.10\" } ]\n" | |||
| 6833 | " }\n" | |||
| 6834 | " ]\n" | |||
| 6835 | "} ]\n" | |||
| 6836 | "} \n"; | |||
| 6837 | ||||
| 6838 | configure(config, CONTROL_RESULT_SUCCESS, ""); | |||
| 6839 | ||||
| 6840 | // Now verify that the shared network was indeed configured. | |||
| 6841 | CfgSharedNetworks4Ptr cfg_net = CfgMgr::instance().getStagingCfg() | |||
| 6842 | ->getCfgSharedNetworks4(); | |||
| 6843 | ||||
| 6844 | // Two shared networks are expected. | |||
| 6845 | ASSERT_TRUE(cfg_net)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(cfg_net)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6845, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "cfg_net", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 6846 | const SharedNetwork4Collection* nets = cfg_net->getAll(); | |||
| 6847 | ASSERT_TRUE(nets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(nets)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6847 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "nets", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6848 | ASSERT_EQ(2, nets->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "nets->size()" , 2, nets->size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6848, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6849 | ||||
| 6850 | // Let's check the first one. | |||
| 6851 | SharedNetwork4Ptr net = nets->at(0); | |||
| 6852 | ASSERT_TRUE(net)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(net)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6852 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "net", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6853 | ||||
| 6854 | const Subnet4SimpleCollection* subs = net->getAllSubnets(); | |||
| 6855 | ASSERT_TRUE(subs)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subs)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6855 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subs", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6856 | EXPECT_EQ(2, subs->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "subs->size()" , 2, subs->size()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6856, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6857 | ||||
| 6858 | // For the first subnet, the rebind-timer should be 10, because it was | |||
| 6859 | // derived from shared-network level. Other parameters a derived | |||
| 6860 | // from global scope to shared-network level and later again to | |||
| 6861 | // subnet4 level. | |||
| 6862 | Subnet4Ptr s = checkSubnet(*subs, "192.0.1.0/24", 0, 10, 7200); | |||
| 6863 | ASSERT_TRUE(s)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(s)) ; else return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6863 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "s", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6864 | EXPECT_EQ("eth0", s->getIface().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"eth0\"" , "s->getIface().get()", "eth0", s->getIface().get()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6864, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6865 | ||||
| 6866 | // For the second subnet, the rebind-timer should be 100, because it | |||
| 6867 | // was specified explicitly. Other parameters a derived | |||
| 6868 | // from global scope to shared-network level and later again to | |||
| 6869 | // subnet4 level. | |||
| 6870 | checkSubnet(*subs, "192.0.2.0/24", 0, 100, 7200); | |||
| 6871 | EXPECT_EQ("eth0", s->getIface().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"eth0\"" , "s->getIface().get()", "eth0", s->getIface().get()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6871, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6872 | ||||
| 6873 | // Ok, now check the second shared subnet. | |||
| 6874 | net = nets->at(1); | |||
| 6875 | ASSERT_TRUE(net)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(net)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6875 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "net", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6876 | ||||
| 6877 | subs = net->getAllSubnets(); | |||
| 6878 | ASSERT_TRUE(subs)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subs)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6878 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subs", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6879 | EXPECT_EQ(1, subs->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "subs->size()" , 1, subs->size()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6879, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6880 | ||||
| 6881 | // This subnet should derive its rebind-timer from global scope. | |||
| 6882 | s = checkSubnet(*subs, "192.0.3.0/24", 0, 0, 7200); | |||
| 6883 | EXPECT_EQ("", s->getIface().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\"", "s->getIface().get()" , "", s->getIface().get()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6883, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6884 | } | |||
| 6885 | ||||
| 6886 | // It is not allowed to have different values for interfaces names is subnets | |||
| 6887 | // in the same shared network. | |||
| 6888 | TEST_F(Dhcp4ParserTest, sharedNetworksInterfacesMixed)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("sharedNetworksInterfacesMixed") > 1, "test_name must not be empty"); class Dhcp4ParserTest_sharedNetworksInterfacesMixed_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_sharedNetworksInterfacesMixed_Test () = default; ~Dhcp4ParserTest_sharedNetworksInterfacesMixed_Test () override = default; Dhcp4ParserTest_sharedNetworksInterfacesMixed_Test (const Dhcp4ParserTest_sharedNetworksInterfacesMixed_Test & ) = delete; Dhcp4ParserTest_sharedNetworksInterfacesMixed_Test & operator=( const Dhcp4ParserTest_sharedNetworksInterfacesMixed_Test &) = delete; Dhcp4ParserTest_sharedNetworksInterfacesMixed_Test (Dhcp4ParserTest_sharedNetworksInterfacesMixed_Test && ) noexcept = delete; Dhcp4ParserTest_sharedNetworksInterfacesMixed_Test & operator=( Dhcp4ParserTest_sharedNetworksInterfacesMixed_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_sharedNetworksInterfacesMixed_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "sharedNetworksInterfacesMixed", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6888), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6888), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6888), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_sharedNetworksInterfacesMixed_Test >); void Dhcp4ParserTest_sharedNetworksInterfacesMixed_Test ::TestBody() { | |||
| 6889 | ||||
| 6890 | // We need to fake the interfaces present, because we want to test | |||
| 6891 | // interface names inheritance. However, there are sanity checks | |||
| 6892 | // on subnet level that would refuse the value if the interface | |||
| 6893 | // is not present. | |||
| 6894 | IfaceMgrTestConfig iface_config(true); | |||
| 6895 | ||||
| 6896 | string config = "{\n" | |||
| 6897 | "\"shared-networks\": [ {\n" | |||
| 6898 | " \"name\": \"foo\"\n," | |||
| 6899 | " \"subnet4\": [\n" | |||
| 6900 | " { \n" | |||
| 6901 | " \"id\": 1, \n" | |||
| 6902 | " \"subnet\": \"192.0.1.0/24\",\n" | |||
| 6903 | " \"interface\": \"eth0\"\n" | |||
| 6904 | " },\n" | |||
| 6905 | " { \n" | |||
| 6906 | " \"id\": 2, \n" | |||
| 6907 | " \"subnet\": \"192.0.2.0/24\",\n" | |||
| 6908 | " \"interface\": \"eth1\"\n" | |||
| 6909 | " }\n" | |||
| 6910 | " ]\n" | |||
| 6911 | " } ]\n" | |||
| 6912 | "} \n"; | |||
| 6913 | ||||
| 6914 | configure(config, CONTROL_RESULT_ERROR, "Subnet 192.0.2.0/24 has specified " | |||
| 6915 | "interface eth1, but earlier subnet in the same shared-network " | |||
| 6916 | "or the shared-network itself used eth0"); | |||
| 6917 | } | |||
| 6918 | ||||
| 6919 | // This test checks multiple host data sources. | |||
| 6920 | TEST_F(Dhcp4ParserTest, hostsDatabases)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("hostsDatabases") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_hostsDatabases_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_hostsDatabases_Test() = default; ~ Dhcp4ParserTest_hostsDatabases_Test() override = default; Dhcp4ParserTest_hostsDatabases_Test (const Dhcp4ParserTest_hostsDatabases_Test &) = delete; Dhcp4ParserTest_hostsDatabases_Test & operator=( const Dhcp4ParserTest_hostsDatabases_Test & ) = delete; Dhcp4ParserTest_hostsDatabases_Test (Dhcp4ParserTest_hostsDatabases_Test &&) noexcept = delete; Dhcp4ParserTest_hostsDatabases_Test & operator=( Dhcp4ParserTest_hostsDatabases_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_hostsDatabases_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "hostsDatabases", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6920 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6920), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6920), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_hostsDatabases_Test >); void Dhcp4ParserTest_hostsDatabases_Test::TestBody() { | |||
| 6921 | ||||
| 6922 | string config = PARSER_CONFIGS[4]; | |||
| 6923 | extractConfig(config); | |||
| 6924 | configure(config, CONTROL_RESULT_SUCCESS, ""); | |||
| 6925 | ||||
| 6926 | // Check database config | |||
| 6927 | ConstCfgDbAccessPtr cfgdb = | |||
| 6928 | CfgMgr::instance().getStagingCfg()->getCfgDbAccess(); | |||
| 6929 | ASSERT_TRUE(cfgdb)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(cfgdb)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6929, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "cfgdb", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6930 | const std::list<std::string>& hal = cfgdb->getHostDbAccessStringList(); | |||
| 6931 | ASSERT_EQ(2, hal.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "hal.size()" , 2, hal.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6931, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6932 | // Keywords are in alphabetical order | |||
| 6933 | EXPECT_EQ("name=keatest1 password=keatest type=mysql user=keatest", hal.front())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"name=keatest1 password=keatest type=mysql user=keatest\"" , "hal.front()", "name=keatest1 password=keatest type=mysql user=keatest" , hal.front()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6933, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6934 | EXPECT_EQ("name=keatest2 password=keatest retry-on-startup=true type=mysql user=keatest", hal.back())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"name=keatest2 password=keatest retry-on-startup=true type=mysql user=keatest\"" , "hal.back()", "name=keatest2 password=keatest retry-on-startup=true type=mysql user=keatest" , hal.back()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6934, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6935 | } | |||
| 6936 | ||||
| 6937 | // This test checks comments. Please keep it last. | |||
| 6938 | TEST_F(Dhcp4ParserTest, comments)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("comments") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_comments_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_comments_Test() = default; ~Dhcp4ParserTest_comments_Test () override = default; Dhcp4ParserTest_comments_Test (const Dhcp4ParserTest_comments_Test &) = delete; Dhcp4ParserTest_comments_Test & operator =( const Dhcp4ParserTest_comments_Test &) = delete; Dhcp4ParserTest_comments_Test (Dhcp4ParserTest_comments_Test &&) noexcept = delete ; Dhcp4ParserTest_comments_Test & operator=( Dhcp4ParserTest_comments_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_comments_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "comments", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6938 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6938), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6938), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_comments_Test >); void Dhcp4ParserTest_comments_Test::TestBody() { | |||
| 6939 | Dhcpv4SrvTest::setSocketTestPath(); | |||
| 6940 | file::PathChecker::enableEnforcement(false); | |||
| 6941 | ||||
| 6942 | string config = PARSER_CONFIGS[6]; | |||
| 6943 | extractConfig(config); | |||
| 6944 | configure(config, CONTROL_RESULT_SUCCESS, ""); | |||
| 6945 | ||||
| 6946 | // Check global user context. | |||
| 6947 | ConstElementPtr ctx = CfgMgr::instance().getStagingCfg()->getContext(); | |||
| 6948 | ASSERT_TRUE(ctx)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6948 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6949 | ASSERT_EQ(1, ctx->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "ctx->size()" , 1, ctx->size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6949, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6950 | ASSERT_TRUE(ctx->get("comment"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx->get("comment" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6950, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx->get(\"comment\")", "false", "true") .c_str()) = :: testing::Message(); | |||
| 6951 | EXPECT_EQ("\"A DHCPv4 server\"", ctx->get("comment")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"A DHCPv4 server\\\"\"" , "ctx->get(\"comment\")->str()", "\"A DHCPv4 server\"" , ctx->get("comment")->str()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6951, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6952 | ||||
| 6953 | // There is a network interface configuration. | |||
| 6954 | ConstCfgIfacePtr iface = CfgMgr::instance().getStagingCfg()->getCfgIface(); | |||
| 6955 | 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/bin/dhcp4/tests/config_parser_unittest.cc" , 6955, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "iface", "false", "true") .c_str()) = ::testing::Message(); | |||
| 6956 | ||||
| 6957 | // Check network interface configuration user context. | |||
| 6958 | ConstElementPtr ctx_iface = iface->getContext(); | |||
| 6959 | ASSERT_TRUE(ctx_iface)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_iface)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6959, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_iface", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6960 | ASSERT_EQ(1, ctx_iface->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "ctx_iface->size()" , 1, ctx_iface->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6960, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6961 | ASSERT_TRUE(ctx_iface->get("comment"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_iface->get("comment" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6961, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_iface->get(\"comment\")", "false", "true") .c_str() ) = ::testing::Message(); | |||
| 6962 | EXPECT_EQ("\"Use wildcard\"", ctx_iface->get("comment")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"Use wildcard\\\"\"" , "ctx_iface->get(\"comment\")->str()", "\"Use wildcard\"" , ctx_iface->get("comment")->str()))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6962 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6963 | ||||
| 6964 | ConstElementPtr json; | |||
| 6965 | ASSERT_NO_THROW_LOG(json = parseDHCP4(config, true)){ try { json = parseDHCP4(config, true); } catch (const std:: exception& ex) { return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6965, "Failed") = ::testing::Message() << "json = parseDHCP4(config, true)" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6965 , "Failed") = ::testing::Message() << "json = parseDHCP4(config, true)" << " threw non-std::exception"; } }; | |||
| 6966 | bool const too_long(SocketPath::isTooLongFromConfig(json)); | |||
| 6967 | if (too_long) { | |||
| 6968 | return; | |||
| 6969 | } | |||
| 6970 | ||||
| 6971 | // There is a global option definition. | |||
| 6972 | const OptionDefinitionPtr& opt_def = | |||
| 6973 | LibDHCP::getRuntimeOptionDef("isc", 100); | |||
| 6974 | ASSERT_TRUE(opt_def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(opt_def)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6974, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "opt_def", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 6975 | EXPECT_EQ("foo", opt_def->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"foo\"" , "opt_def->getName()", "foo", opt_def->getName()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6975, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6976 | EXPECT_EQ(100, opt_def->getCode())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("100", "opt_def->getCode()" , 100, opt_def->getCode()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6976, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6977 | EXPECT_FALSE(opt_def->getArrayType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(opt_def->getArrayType ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6977, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "opt_def->getArrayType()", "true", "false") .c_str()) = :: testing::Message(); | |||
| 6978 | EXPECT_EQ(OPT_IPV4_ADDRESS_TYPE, opt_def->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("OPT_IPV4_ADDRESS_TYPE" , "opt_def->getType()", OPT_IPV4_ADDRESS_TYPE, opt_def-> getType()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6978, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6979 | EXPECT_TRUE(opt_def->getEncapsulatedSpace().empty())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(opt_def->getEncapsulatedSpace ().empty())) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6979, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "opt_def->getEncapsulatedSpace().empty()", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 6980 | ||||
| 6981 | // Check option definition user context. | |||
| 6982 | ConstElementPtr ctx_opt_def = opt_def->getContext(); | |||
| 6983 | ASSERT_TRUE(ctx_opt_def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_opt_def)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6983, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_opt_def", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6984 | ASSERT_EQ(1, ctx_opt_def->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "ctx_opt_def->size()" , 1, ctx_opt_def->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6984, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6985 | ASSERT_TRUE(ctx_opt_def->get("comment"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_opt_def->get("comment" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6985, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_opt_def->get(\"comment\")", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 6986 | EXPECT_EQ("\"An option definition\"", ctx_opt_def->get("comment")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"An option definition\\\"\"" , "ctx_opt_def->get(\"comment\")->str()", "\"An option definition\"" , ctx_opt_def->get("comment")->str()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 6986 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6987 | ||||
| 6988 | // There is an option descriptor aka option data. | |||
| 6989 | const OptionDescriptor& opt_desc = | |||
| 6990 | CfgMgr::instance().getStagingCfg()->getCfgOption()-> | |||
| 6991 | get(DHCP4_OPTION_SPACE"dhcp4", DHO_DHCP_MESSAGE); | |||
| 6992 | ASSERT_TRUE(opt_desc.option_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(opt_desc.option_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6992, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "opt_desc.option_", "false", "true") .c_str()) = ::testing:: Message(); | |||
| 6993 | EXPECT_EQ(DHO_DHCP_MESSAGE, opt_desc.option_->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("DHO_DHCP_MESSAGE" , "opt_desc.option_->getType()", DHO_DHCP_MESSAGE, opt_desc .option_->getType()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6993, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6994 | ||||
| 6995 | // Check option descriptor user context. | |||
| 6996 | ConstElementPtr ctx_opt_desc = opt_desc.getContext(); | |||
| 6997 | ASSERT_TRUE(ctx_opt_desc)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_opt_desc)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6997, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_opt_desc", "false", "true") .c_str()) = ::testing::Message (); | |||
| 6998 | ASSERT_EQ(1, ctx_opt_desc->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "ctx_opt_desc->size()" , 1, ctx_opt_desc->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6998, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 6999 | ASSERT_TRUE(ctx_opt_desc->get("comment"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_opt_desc->get( "comment"))) ; else return ::testing::internal::AssertHelper( ::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 6999, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_opt_desc->get(\"comment\")", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 7000 | EXPECT_EQ("\"Set option value\"", ctx_opt_desc->get("comment")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"Set option value\\\"\"" , "ctx_opt_desc->get(\"comment\")->str()", "\"Set option value\"" , ctx_opt_desc->get("comment")->str()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7000 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7001 | ||||
| 7002 | // And there are some client classes. | |||
| 7003 | const ClientClassDictionaryPtr& dict = | |||
| 7004 | CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); | |||
| 7005 | ASSERT_TRUE(dict)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dict)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7005 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dict", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7006 | EXPECT_EQ(3, dict->getClasses()->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("3", "dict->getClasses()->size()" , 3, dict->getClasses()->size()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7006, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7007 | ClientClassDefPtr cclass = dict->findClass("all"); | |||
| 7008 | ASSERT_TRUE(cclass)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(cclass)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7008, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "cclass", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7009 | EXPECT_EQ("all", cclass->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"all\"" , "cclass->getName()", "all", cclass->getName()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7009, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7010 | EXPECT_EQ("'' == ''", cclass->getTest())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"'' == ''\"" , "cclass->getTest()", "'' == ''", cclass->getTest()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7010, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7011 | ||||
| 7012 | // Check client class user context. | |||
| 7013 | ConstElementPtr ctx_class = cclass->getContext(); | |||
| 7014 | ASSERT_TRUE(ctx_class)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_class)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7014, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_class", "false", "true") .c_str()) = ::testing::Message (); | |||
| 7015 | ASSERT_EQ(1, ctx_class->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "ctx_class->size()" , 1, ctx_class->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7015, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7016 | ASSERT_TRUE(ctx_class->get("comment"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_class->get("comment" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7016, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_class->get(\"comment\")", "false", "true") .c_str() ) = ::testing::Message(); | |||
| 7017 | EXPECT_EQ("\"match all\"", ctx_class->get("comment")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"match all\\\"\"" , "ctx_class->get(\"comment\")->str()", "\"match all\"" , ctx_class->get("comment")->str()))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7017 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7018 | ||||
| 7019 | // The 'none' class has no user-context/comment. | |||
| 7020 | cclass = dict->findClass("none"); | |||
| 7021 | ASSERT_TRUE(cclass)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(cclass)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7021, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "cclass", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7022 | EXPECT_EQ("none", cclass->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"none\"" , "cclass->getName()", "none", cclass->getName()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7022, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7023 | EXPECT_EQ("", cclass->getTest())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\"", "cclass->getTest()" , "", cclass->getTest()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7023, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7024 | EXPECT_FALSE(cclass->getContext())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(cclass->getContext ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7024, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "cclass->getContext()", "true", "false") .c_str()) = ::testing ::Message(); | |||
| 7025 | ||||
| 7026 | // The 'both' class has a user context and a comment. | |||
| 7027 | cclass = dict->findClass("both"); | |||
| 7028 | EXPECT_EQ("both", cclass->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"both\"" , "cclass->getName()", "both", cclass->getName()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7028, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7029 | EXPECT_EQ("", cclass->getTest())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\"", "cclass->getTest()" , "", cclass->getTest()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7029, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7030 | ctx_class = cclass->getContext(); | |||
| 7031 | ASSERT_TRUE(ctx_class)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_class)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7031, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_class", "false", "true") .c_str()) = ::testing::Message (); | |||
| 7032 | ASSERT_EQ(2, ctx_class->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "ctx_class->size()" , 2, ctx_class->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7032, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7033 | ASSERT_TRUE(ctx_class->get("comment"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_class->get("comment" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7033, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_class->get(\"comment\")", "false", "true") .c_str() ) = ::testing::Message(); | |||
| 7034 | EXPECT_EQ("\"a comment\"", ctx_class->get("comment")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"a comment\\\"\"" , "ctx_class->get(\"comment\")->str()", "\"a comment\"" , ctx_class->get("comment")->str()))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7034 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7035 | ASSERT_TRUE(ctx_class->get("version"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_class->get("version" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7035, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_class->get(\"version\")", "false", "true") .c_str() ) = ::testing::Message(); | |||
| 7036 | EXPECT_EQ("1", ctx_class->get("version")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"1\"", "ctx_class->get(\"version\")->str()" , "1", ctx_class->get("version")->str()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7036 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7037 | ||||
| 7038 | // There is a UNIX control socket. | |||
| 7039 | ConstElementPtr socket = | |||
| 7040 | CfgMgr::instance().getStagingCfg()->getUnixControlSocketInfo(); | |||
| 7041 | ASSERT_TRUE(socket)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(socket)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7041, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "socket", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7042 | ASSERT_EQ(Element::list, socket->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("Element::list" , "socket->getType()", Element::list, socket->getType() ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7042, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7043 | ASSERT_EQ(socket->size(), 1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("socket->size()" , "1", socket->size(), 1))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7043, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7044 | socket = socket->get(0); | |||
| 7045 | ASSERT_TRUE(socket)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(socket)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7045, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "socket", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7046 | ASSERT_TRUE(socket->get("socket-type"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(socket->get("socket-type" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7046, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "socket->get(\"socket-type\")", "false", "true") .c_str( )) = ::testing::Message(); | |||
| 7047 | EXPECT_EQ("\"unix\"", socket->get("socket-type")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"unix\\\"\"" , "socket->get(\"socket-type\")->str()", "\"unix\"", socket ->get("socket-type")->str()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7047, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7048 | ASSERT_TRUE(socket->get("socket-name"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(socket->get("socket-name" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7048, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "socket->get(\"socket-name\")", "false", "true") .c_str( )) = ::testing::Message(); | |||
| 7049 | EXPECT_EQ("\"kea4-ctrl-socket\"", socket->get("socket-name")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"kea4-ctrl-socket\\\"\"" , "socket->get(\"socket-name\")->str()", "\"kea4-ctrl-socket\"" , socket->get("socket-name")->str()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7049 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7050 | ||||
| 7051 | // Check UNIX control socket comment and user context. | |||
| 7052 | ConstElementPtr ctx_socket = socket->get("user-context"); | |||
| 7053 | ASSERT_TRUE(ctx_socket)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_socket)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7053, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_socket", "false", "true") .c_str()) = ::testing::Message (); | |||
| 7054 | ASSERT_EQ(1, ctx_socket->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "ctx_socket->size()" , 1, ctx_socket->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7054, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7055 | ASSERT_TRUE(ctx_socket->get("comment"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_socket->get("comment" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7055, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_socket->get(\"comment\")", "false", "true") .c_str( )) = ::testing::Message(); | |||
| 7056 | EXPECT_EQ("\"Indirect comment\"", ctx_socket->get("comment")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"Indirect comment\\\"\"" , "ctx_socket->get(\"comment\")->str()", "\"Indirect comment\"" , ctx_socket->get("comment")->str()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7056 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7057 | ||||
| 7058 | // There is a HTTP control socket with authentication. | |||
| 7059 | socket = CfgMgr::instance().getStagingCfg()->getHttpControlSocketInfo(); | |||
| 7060 | ASSERT_TRUE(socket)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(socket)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7060, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "socket", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7061 | ASSERT_EQ(Element::list, socket->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("Element::list" , "socket->getType()", Element::list, socket->getType() ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7061, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7062 | ASSERT_EQ(socket->size(), 1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("socket->size()" , "1", socket->size(), 1))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7062, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7063 | socket = socket->get(0); | |||
| 7064 | ASSERT_TRUE(socket)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(socket)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7064, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "socket", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7065 | /// @todo use the configuration object. | |||
| 7066 | ASSERT_TRUE(socket->get("socket-type"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(socket->get("socket-type" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7066, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "socket->get(\"socket-type\")", "false", "true") .c_str( )) = ::testing::Message(); | |||
| 7067 | EXPECT_EQ("\"http\"", socket->get("socket-type")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"http\\\"\"" , "socket->get(\"socket-type\")->str()", "\"http\"", socket ->get("socket-type")->str()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7067, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7068 | ASSERT_TRUE(socket->get("socket-address"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(socket->get("socket-address" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7068, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "socket->get(\"socket-address\")", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 7069 | EXPECT_EQ("\"::1\"", socket->get("socket-address")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"::1\\\"\"" , "socket->get(\"socket-address\")->str()", "\"::1\"", socket ->get("socket-address")->str()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7069, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7070 | ASSERT_TRUE(socket->get("socket-port"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(socket->get("socket-port" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7070, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "socket->get(\"socket-port\")", "false", "true") .c_str( )) = ::testing::Message(); | |||
| 7071 | EXPECT_EQ("8000", socket->get("socket-port")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"8000\"" , "socket->get(\"socket-port\")->str()", "8000", socket ->get("socket-port")->str()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7071, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7072 | ||||
| 7073 | // Check HTTP control socket comment. | |||
| 7074 | ctx_socket = socket->get("user-context"); | |||
| 7075 | ASSERT_TRUE(ctx_socket)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_socket)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7075, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_socket", "false", "true") .c_str()) = ::testing::Message (); | |||
| 7076 | ASSERT_EQ(1, ctx_socket->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "ctx_socket->size()" , 1, ctx_socket->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7076, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7077 | ASSERT_TRUE(ctx_socket->get("comment"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_socket->get("comment" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7077, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_socket->get(\"comment\")", "false", "true") .c_str( )) = ::testing::Message(); | |||
| 7078 | EXPECT_EQ("\"HTTP control socket\"", ctx_socket->get("comment")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"HTTP control socket\\\"\"" , "ctx_socket->get(\"comment\")->str()", "\"HTTP control socket\"" , ctx_socket->get("comment")->str()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7078 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7079 | ||||
| 7080 | // HTTP headers. | |||
| 7081 | ConstElementPtr headers = socket->get("http-headers"); | |||
| 7082 | ASSERT_TRUE(headers)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(headers)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7082, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "headers", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7083 | ASSERT_EQ(1, headers->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "headers->size()" , 1, headers->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7083, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7084 | ConstElementPtr header = headers->get(0); | |||
| 7085 | ASSERT_TRUE(header)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(header)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7085, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "header", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7086 | ASSERT_TRUE(header->get("name"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(header->get("name" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7086, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "header->get(\"name\")", "false", "true") .c_str()) = :: testing::Message(); | |||
| 7087 | EXPECT_EQ("\"Strict-Transport-Security\"", header->get("name")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"Strict-Transport-Security\\\"\"" , "header->get(\"name\")->str()", "\"Strict-Transport-Security\"" , header->get("name")->str()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7087, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7088 | ASSERT_TRUE(header->get("value"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(header->get("value" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7088, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "header->get(\"value\")", "false", "true") .c_str()) = :: testing::Message(); | |||
| 7089 | EXPECT_EQ("\"max-age=31536000\"", header->get("value")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"max-age=31536000\\\"\"" , "header->get(\"value\")->str()", "\"max-age=31536000\"" , header->get("value")->str()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7089, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7090 | ||||
| 7091 | // Check HTTP header user context. | |||
| 7092 | ConstElementPtr ctx_header = header->get("user-context"); | |||
| 7093 | ASSERT_TRUE(ctx_header)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_header)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7093, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_header", "false", "true") .c_str()) = ::testing::Message (); | |||
| 7094 | ASSERT_EQ(1, ctx_header->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "ctx_header->size()" , 1, ctx_header->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7094, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7095 | ASSERT_TRUE(ctx_header->get("comment"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_header->get("comment" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7095, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_header->get(\"comment\")", "false", "true") .c_str( )) = ::testing::Message(); | |||
| 7096 | EXPECT_EQ("\"HSTS header\"", ctx_header->get("comment")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"HSTS header\\\"\"" , "ctx_header->get(\"comment\")->str()", "\"HSTS header\"" , ctx_header->get("comment")->str()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7096 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7097 | ||||
| 7098 | // HTTP authentication. | |||
| 7099 | ConstElementPtr auth = socket->get("authentication"); | |||
| 7100 | ASSERT_TRUE(auth)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(auth)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7100 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "auth", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7101 | ASSERT_TRUE(auth->get("type"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(auth->get("type")) ) ; else return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7101, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "auth->get(\"type\")", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 7102 | EXPECT_EQ("\"basic\"", auth->get("type")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"basic\\\"\"" , "auth->get(\"type\")->str()", "\"basic\"", auth->get ("type")->str()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7102, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7103 | ConstElementPtr ctx_auth = auth->get("user-context"); | |||
| 7104 | ASSERT_TRUE(ctx_auth)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_auth)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7104, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_auth", "false", "true") .c_str()) = ::testing::Message (); | |||
| 7105 | ASSERT_EQ(1, ctx_auth->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "ctx_auth->size()" , 1, ctx_auth->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7105, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7106 | ASSERT_TRUE(ctx_auth->get("comment"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_auth->get("comment" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7106, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_auth->get(\"comment\")", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7107 | EXPECT_EQ("\"basic HTTP authentication\"", ctx_auth->get("comment")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"basic HTTP authentication\\\"\"" , "ctx_auth->get(\"comment\")->str()", "\"basic HTTP authentication\"" , ctx_auth->get("comment")->str()))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7107 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7108 | ||||
| 7109 | // Authentication client. | |||
| 7110 | ConstElementPtr clients = auth->get("clients"); | |||
| 7111 | ASSERT_TRUE(clients)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(clients)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7111, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "clients", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7112 | ASSERT_EQ(1, clients->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "clients->size()" , 1, clients->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7112, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7113 | ConstElementPtr client; | |||
| 7114 | ASSERT_NO_THROW(client = clients->get(0))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { client = clients->get(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_7114 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_7114 ; } } else gtest_label_testnothrow_7114 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7114, ("Expected: " "client = clients->get(0)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 7115 | ASSERT_TRUE(client)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(client)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7115, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "client", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7116 | ASSERT_TRUE(client->get("user"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(client->get("user" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7116, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "client->get(\"user\")", "false", "true") .c_str()) = :: testing::Message(); | |||
| 7117 | ASSERT_EQ("\"admin\"", client->get("user")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"admin\\\"\"" , "client->get(\"user\")->str()", "\"admin\"", client-> get("user")->str()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7117, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7118 | ASSERT_TRUE(client->get("password"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(client->get("password" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7118, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "client->get(\"password\")", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7119 | ASSERT_EQ("\"foobar\"", client->get("password")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"foobar\\\"\"" , "client->get(\"password\")->str()", "\"foobar\"", client ->get("password")->str()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7119, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7120 | ConstElementPtr ctx_client = client->get("user-context"); | |||
| 7121 | ASSERT_TRUE(ctx_client)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_client)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7121, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_client", "false", "true") .c_str()) = ::testing::Message (); | |||
| 7122 | ASSERT_EQ(1, ctx_client->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "ctx_client->size()" , 1, ctx_client->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7122, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7123 | ASSERT_TRUE(ctx_client->get("comment"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_client->get("comment" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7123, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_client->get(\"comment\")", "false", "true") .c_str( )) = ::testing::Message(); | |||
| 7124 | EXPECT_EQ("\"admin is authorized\"", ctx_client->get("comment")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"admin is authorized\\\"\"" , "ctx_client->get(\"comment\")->str()", "\"admin is authorized\"" , ctx_client->get("comment")->str()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7124 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7125 | ||||
| 7126 | // Now verify that the shared network was indeed configured. | |||
| 7127 | const CfgSharedNetworks4Ptr& cfg_net = | |||
| 7128 | CfgMgr::instance().getStagingCfg()->getCfgSharedNetworks4(); | |||
| 7129 | ASSERT_TRUE(cfg_net)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(cfg_net)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7129, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "cfg_net", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7130 | const SharedNetwork4Collection* nets = cfg_net->getAll(); | |||
| 7131 | ASSERT_TRUE(nets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(nets)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7131 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "nets", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7132 | ASSERT_EQ(1, nets->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "nets->size()" , 1, nets->size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7132, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7133 | SharedNetwork4Ptr net = nets->at(0); | |||
| 7134 | ASSERT_TRUE(net)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(net)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7134 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "net", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7135 | EXPECT_EQ("foo", net->getName())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"foo\"" , "net->getName()", "foo", net->getName()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7135 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7136 | ||||
| 7137 | // Check shared network user context. | |||
| 7138 | ConstElementPtr ctx_net = net->getContext(); | |||
| 7139 | ASSERT_TRUE(ctx_net)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_net)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7139, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_net", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7140 | ASSERT_EQ(1, ctx_net->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "ctx_net->size()" , 1, ctx_net->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7140, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7141 | ASSERT_TRUE(ctx_net->get("comment"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_net->get("comment" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7141, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_net->get(\"comment\")", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7142 | EXPECT_EQ("\"A shared network\"", ctx_net->get("comment")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"A shared network\\\"\"" , "ctx_net->get(\"comment\")->str()", "\"A shared network\"" , ctx_net->get("comment")->str()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7142, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7143 | ||||
| 7144 | // The shared network has a subnet. | |||
| 7145 | const Subnet4SimpleCollection* subs = net->getAllSubnets(); | |||
| 7146 | ASSERT_TRUE(subs)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subs)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7146 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subs", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7147 | ASSERT_EQ(1, subs->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "subs->size()" , 1, subs->size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7147, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7148 | Subnet4Ptr sub = *subs->begin(); | |||
| 7149 | ASSERT_TRUE(sub)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(sub)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7149 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "sub", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7150 | EXPECT_EQ(100, sub->getID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("100", "sub->getID()" , 100, sub->getID()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7150, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7151 | EXPECT_EQ("192.0.1.0/24", sub->toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.1.0/24\"" , "sub->toText()", "192.0.1.0/24", sub->toText()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7151, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7152 | ||||
| 7153 | // Check subnet user context. | |||
| 7154 | ConstElementPtr ctx_sub = sub->getContext(); | |||
| 7155 | ASSERT_TRUE(ctx_sub)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_sub)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7155, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_sub", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7156 | ASSERT_EQ(1, ctx_sub->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "ctx_sub->size()" , 1, ctx_sub->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7156, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7157 | ASSERT_TRUE(ctx_sub->get("comment"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_sub->get("comment" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7157, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_sub->get(\"comment\")", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7158 | EXPECT_EQ("\"A subnet\"", ctx_sub->get("comment")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"A subnet\\\"\"" , "ctx_sub->get(\"comment\")->str()", "\"A subnet\"", ctx_sub ->get("comment")->str()))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7158, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7159 | ||||
| 7160 | // The subnet has a pool. | |||
| 7161 | const PoolCollection& pools = sub->getPools(Lease::TYPE_V4); | |||
| 7162 | ASSERT_EQ(1, pools.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "pools.size()" , 1, pools.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7162, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7163 | PoolPtr pool = pools.at(0); | |||
| 7164 | ASSERT_TRUE(pool)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7164 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7165 | ||||
| 7166 | // Check pool user context. | |||
| 7167 | ConstElementPtr ctx_pool = pool->getContext(); | |||
| 7168 | ASSERT_TRUE(ctx_pool)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_pool)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7168, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_pool", "false", "true") .c_str()) = ::testing::Message (); | |||
| 7169 | ASSERT_EQ(1, ctx_pool->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "ctx_pool->size()" , 1, ctx_pool->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7169, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7170 | ASSERT_TRUE(ctx_pool->get("comment"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_pool->get("comment" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7170, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_pool->get(\"comment\")", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7171 | EXPECT_EQ("\"A pool\"", ctx_pool->get("comment")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"A pool\\\"\"" , "ctx_pool->get(\"comment\")->str()", "\"A pool\"", ctx_pool ->get("comment")->str()))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7171, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7172 | ||||
| 7173 | // The subnet has a host reservation. | |||
| 7174 | uint8_t hw[] = { 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; | |||
| 7175 | ConstHostPtr host = | |||
| 7176 | CfgMgr::instance().getStagingCfg()->getCfgHosts()-> | |||
| 7177 | get4(100, Host::IDENT_HWADDR, &hw[0], sizeof(hw)); | |||
| 7178 | ASSERT_TRUE(host)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(host)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7178 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "host", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7179 | EXPECT_EQ(Host::IDENT_HWADDR, host->getIdentifierType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("Host::IDENT_HWADDR" , "host->getIdentifierType()", Host::IDENT_HWADDR, host-> getIdentifierType()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7179, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7180 | EXPECT_EQ("aa:bb:cc:dd:ee:ff", host->getHWAddress()->toText(false))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"aa:bb:cc:dd:ee:ff\"" , "host->getHWAddress()->toText(false)", "aa:bb:cc:dd:ee:ff" , host->getHWAddress()->toText(false)))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7180 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7181 | EXPECT_FALSE(host->getDuid())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(host->getDuid()) )) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7181, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "host->getDuid()", "true", "false") .c_str()) = ::testing ::Message(); | |||
| 7182 | EXPECT_EQ(100, host->getIPv4SubnetID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("100", "host->getIPv4SubnetID()" , 100, host->getIPv4SubnetID()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7182, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7183 | EXPECT_EQ(SUBNET_ID_UNUSED, host->getIPv6SubnetID())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("SUBNET_ID_UNUSED" , "host->getIPv6SubnetID()", SUBNET_ID_UNUSED, host->getIPv6SubnetID ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7183, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7184 | EXPECT_EQ("foo.example.com", host->getHostname())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"foo.example.com\"" , "host->getHostname()", "foo.example.com", host->getHostname ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7184, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7185 | ||||
| 7186 | // Check host user context. | |||
| 7187 | ConstElementPtr ctx_host = host->getContext(); | |||
| 7188 | ASSERT_TRUE(ctx_host)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_host)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7188, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_host", "false", "true") .c_str()) = ::testing::Message (); | |||
| 7189 | ASSERT_EQ(1, ctx_host->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "ctx_host->size()" , 1, ctx_host->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7189, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7190 | ASSERT_TRUE(ctx_host->get("comment"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_host->get("comment" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7190, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_host->get(\"comment\")", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7191 | EXPECT_EQ("\"A host reservation\"", ctx_host->get("comment")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"A host reservation\\\"\"" , "ctx_host->get(\"comment\")->str()", "\"A host reservation\"" , ctx_host->get("comment")->str()))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7191 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7192 | ||||
| 7193 | // The host reservation has an option data. | |||
| 7194 | ConstCfgOptionPtr opts = host->getCfgOption4(); | |||
| 7195 | ASSERT_TRUE(opts)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(opts)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7195 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "opts", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7196 | EXPECT_FALSE(opts->empty())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(opts->empty()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7196, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "opts->empty()", "true", "false") .c_str()) = ::testing:: Message(); | |||
| 7197 | const OptionDescriptor& host_desc = | |||
| 7198 | opts->get(DHCP4_OPTION_SPACE"dhcp4", DHO_DOMAIN_NAME); | |||
| 7199 | ASSERT_TRUE(host_desc.option_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(host_desc.option_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7199, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "host_desc.option_", "false", "true") .c_str()) = ::testing ::Message(); | |||
| 7200 | EXPECT_EQ(DHO_DOMAIN_NAME, host_desc.option_->getType())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("DHO_DOMAIN_NAME" , "host_desc.option_->getType()", DHO_DOMAIN_NAME, host_desc .option_->getType()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7200, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7201 | ||||
| 7202 | // Check embedded option data user context. | |||
| 7203 | ConstElementPtr ctx_host_desc = host_desc.getContext(); | |||
| 7204 | ASSERT_TRUE(ctx_host_desc)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_host_desc)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7204, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_host_desc", "false", "true") .c_str()) = ::testing::Message (); | |||
| 7205 | ASSERT_EQ(1, ctx_host_desc->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "ctx_host_desc->size()" , 1, ctx_host_desc->size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7205, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7206 | ASSERT_TRUE(ctx_host_desc->get("comment"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_host_desc->get ("comment"))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7206, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_host_desc->get(\"comment\")", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 7207 | EXPECT_EQ("\"An option in a reservation\"",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"An option in a reservation\\\"\"" , "ctx_host_desc->get(\"comment\")->str()", "\"An option in a reservation\"" , ctx_host_desc->get("comment")->str()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7208 , gtest_ar.failure_message()) = ::testing::Message() | |||
| 7208 | ctx_host_desc->get("comment")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"An option in a reservation\\\"\"" , "ctx_host_desc->get(\"comment\")->str()", "\"An option in a reservation\"" , ctx_host_desc->get("comment")->str()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7208 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7209 | ||||
| 7210 | // Finally dynamic DNS update configuration. | |||
| 7211 | const D2ClientConfigPtr& d2 = | |||
| 7212 | CfgMgr::instance().getStagingCfg()->getD2ClientConfig(); | |||
| 7213 | ASSERT_TRUE(d2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(d2)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7213 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "d2", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7214 | EXPECT_FALSE(d2->getEnableUpdates())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(d2->getEnableUpdates ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7214, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "d2->getEnableUpdates()", "true", "false") .c_str()) = :: testing::Message(); | |||
| 7215 | ||||
| 7216 | // Check dynamic DNS update configuration user context. | |||
| 7217 | ConstElementPtr ctx_d2 = d2->getContext(); | |||
| 7218 | ASSERT_TRUE(ctx_d2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_d2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7218, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_d2", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7219 | ASSERT_EQ(1, ctx_d2->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "ctx_d2->size()" , 1, ctx_d2->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7219, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7220 | ASSERT_TRUE(ctx_d2->get("comment"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ctx_d2->get("comment" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7220, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ctx_d2->get(\"comment\")", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7221 | EXPECT_EQ("\"No dynamic DNS\"", ctx_d2->get("comment")->str())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"\\\"No dynamic DNS\\\"\"" , "ctx_d2->get(\"comment\")->str()", "\"No dynamic DNS\"" , ctx_d2->get("comment")->str()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7221, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7222 | } | |||
| 7223 | ||||
| 7224 | // This test verifies that the global host reservations can be specified. | |||
| 7225 | TEST_F(Dhcp4ParserTest, globalReservations)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("globalReservations") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_globalReservations_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_globalReservations_Test() = default ; ~Dhcp4ParserTest_globalReservations_Test() override = default ; Dhcp4ParserTest_globalReservations_Test (const Dhcp4ParserTest_globalReservations_Test &) = delete; Dhcp4ParserTest_globalReservations_Test & operator=( const Dhcp4ParserTest_globalReservations_Test & ) = delete; Dhcp4ParserTest_globalReservations_Test (Dhcp4ParserTest_globalReservations_Test &&) noexcept = delete; Dhcp4ParserTest_globalReservations_Test & operator=( Dhcp4ParserTest_globalReservations_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_globalReservations_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "globalReservations", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7225), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7225), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7225), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_globalReservations_Test >); void Dhcp4ParserTest_globalReservations_Test::TestBody () { | |||
| 7226 | ConstElementPtr x; | |||
| 7227 | string config = "{ " + genIfaceConfig() + "," | |||
| 7228 | "\"rebind-timer\": 2000, \n" | |||
| 7229 | "\"renew-timer\": 1000,\n" | |||
| 7230 | "\"reservations\": [\n" | |||
| 7231 | " {\n" | |||
| 7232 | " \"duid\": \"01:02:03:04:05:06:07:08:09:0A\",\n" | |||
| 7233 | " \"ip-address\": \"192.0.200.1\",\n" | |||
| 7234 | " \"hostname\": \"global1\",\n" | |||
| 7235 | " \"option-data\": [\n" | |||
| 7236 | " {\n" | |||
| 7237 | " \"name\": \"name-servers\",\n" | |||
| 7238 | " \"data\": \"192.0.3.15\"\n" | |||
| 7239 | " },\n" | |||
| 7240 | " {\n" | |||
| 7241 | " \"name\": \"default-ip-ttl\",\n" | |||
| 7242 | " \"data\": \"32\"\n" | |||
| 7243 | " }\n" | |||
| 7244 | " ]\n" | |||
| 7245 | " },\n" | |||
| 7246 | " {\n" | |||
| 7247 | " \"hw-address\": \"01:02:03:04:05:06\",\n" | |||
| 7248 | " \"hostname\": \"global2\",\n" | |||
| 7249 | " \"option-data\": [\n" | |||
| 7250 | " {\n" | |||
| 7251 | " \"name\": \"name-servers\",\n" | |||
| 7252 | " \"data\": \"192.0.3.95\"\n" | |||
| 7253 | " },\n" | |||
| 7254 | " {\n" | |||
| 7255 | " \"name\": \"default-ip-ttl\",\n" | |||
| 7256 | " \"data\": \"11\"\n" | |||
| 7257 | " }\n" | |||
| 7258 | " ]\n" | |||
| 7259 | " }],\n" | |||
| 7260 | "\"subnet4\": [ \n" | |||
| 7261 | " { \n" | |||
| 7262 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ],\n" | |||
| 7263 | " \"subnet\": \"192.0.2.0/24\", \n" | |||
| 7264 | " \"id\": 123,\n" | |||
| 7265 | " \"reservations\": [\n" | |||
| 7266 | " ]\n" | |||
| 7267 | " },\n" | |||
| 7268 | " {\n" | |||
| 7269 | " \"pools\": [ { \"pool\": \"192.0.4.101 - 192.0.4.150\" } ],\n" | |||
| 7270 | " \"subnet\": \"192.0.4.0/24\",\n" | |||
| 7271 | " \"id\": 542\n" | |||
| 7272 | " }\n" | |||
| 7273 | "],\n" | |||
| 7274 | "\"valid-lifetime\": 4000 }\n"; | |||
| 7275 | ||||
| 7276 | ConstElementPtr json; | |||
| 7277 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_7277 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_7277 ; } } else gtest_label_testnothrow_7277 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7277, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 7278 | extractConfig(config); | |||
| 7279 | ||||
| 7280 | EXPECT_NO_THROW(x = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { x = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_7280; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_7280; } } else gtest_label_testnothrow_7280 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7280, ("Expected: " "x = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 7281 | checkResult(x, 0); | |||
| 7282 | ||||
| 7283 | // Make sure all subnets have been successfully configured. There is no | |||
| 7284 | // need to sanity check the subnet properties because it should have | |||
| 7285 | // been already tested by other tests. | |||
| 7286 | const Subnet4Collection* subnets = | |||
| 7287 | CfgMgr::instance().getStagingCfg()->getCfgSubnets4()->getAll(); | |||
| 7288 | ASSERT_TRUE(subnets)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnets)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7288, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnets", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7289 | ASSERT_EQ(2, subnets->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "subnets->size()" , 2, subnets->size()))) ; else return ::testing::internal:: AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7289, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7290 | ||||
| 7291 | // Hosts configuration must be available. | |||
| 7292 | CfgHostsPtr hosts_cfg = CfgMgr::instance().getStagingCfg()->getCfgHosts(); | |||
| 7293 | ASSERT_TRUE(hosts_cfg)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(hosts_cfg)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7293, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg", "false", "true") .c_str()) = ::testing::Message (); | |||
| 7294 | ||||
| 7295 | // Let's create a hardware address of the host named "global2" | |||
| 7296 | std::vector<uint8_t> hwaddr; | |||
| 7297 | for (unsigned int i = 1; i < 7; ++i) { | |||
| 7298 | hwaddr.push_back(static_cast<uint8_t>(i)); | |||
| 7299 | } | |||
| 7300 | ||||
| 7301 | // Retrieve the global reservation and sanity check the hostname reserved. | |||
| 7302 | ConstHostPtr host = hosts_cfg->get4(SUBNET_ID_GLOBAL, Host::IDENT_HWADDR, | |||
| 7303 | &hwaddr[0], hwaddr.size()); | |||
| 7304 | ASSERT_TRUE(host)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(host)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7304 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "host", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7305 | EXPECT_EQ("global2", host->getHostname())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"global2\"" , "host->getHostname()", "global2", host->getHostname() ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7305, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7306 | ||||
| 7307 | // This reservation should be solely assigned to the subnet 234, | |||
| 7308 | // and not to other two. | |||
| 7309 | EXPECT_FALSE(hosts_cfg->get4(123, Host::IDENT_HWADDR,switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 123, Host::IDENT_HWADDR, &hwaddr[0], hwaddr.size())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7310, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(123, Host::IDENT_HWADDR, &hwaddr[0], hwaddr.size())" , "true", "false") .c_str()) = ::testing::Message() | |||
| 7310 | &hwaddr[0], hwaddr.size()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 123, Host::IDENT_HWADDR, &hwaddr[0], hwaddr.size())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7310, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(123, Host::IDENT_HWADDR, &hwaddr[0], hwaddr.size())" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 7311 | ||||
| 7312 | EXPECT_FALSE(hosts_cfg->get4(542, Host::IDENT_HWADDR,switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 542, Host::IDENT_HWADDR, &hwaddr[0], hwaddr.size())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7313, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(542, Host::IDENT_HWADDR, &hwaddr[0], hwaddr.size())" , "true", "false") .c_str()) = ::testing::Message() | |||
| 7313 | &hwaddr[0], hwaddr.size()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 542, Host::IDENT_HWADDR, &hwaddr[0], hwaddr.size())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7313, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(542, Host::IDENT_HWADDR, &hwaddr[0], hwaddr.size())" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 7314 | // Check that options are assigned correctly. | |||
| 7315 | Option4AddrLstPtr opt_dns = | |||
| 7316 | retrieveOption<Option4AddrLstPtr>(*host, DHO_NAME_SERVERS); | |||
| 7317 | ASSERT_TRUE(opt_dns)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(opt_dns)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7317, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "opt_dns", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7318 | Option4AddrLst::AddressContainer dns_addrs = opt_dns->getAddresses(); | |||
| 7319 | ASSERT_EQ(1, dns_addrs.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "dns_addrs.size()" , 1, dns_addrs.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7319, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7320 | EXPECT_EQ("192.0.3.95", dns_addrs[0].toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.3.95\"" , "dns_addrs[0].toText()", "192.0.3.95", dns_addrs[0].toText( )))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7320, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7321 | OptionUint8Ptr opt_ttl = | |||
| 7322 | retrieveOption<OptionUint8Ptr>(*host, DHO_DEFAULT_IP_TTL); | |||
| 7323 | ASSERT_TRUE(opt_ttl)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(opt_ttl)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7323, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "opt_ttl", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7324 | EXPECT_EQ(11, static_cast<int>(opt_ttl->getValue()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("11", "static_cast<int>(opt_ttl->getValue())" , 11, static_cast<int>(opt_ttl->getValue())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7324, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7325 | ||||
| 7326 | // Do the same test for the DUID based reservation. | |||
| 7327 | std::vector<uint8_t> duid; | |||
| 7328 | for (unsigned int i = 1; i < 0xb; ++i) { | |||
| 7329 | duid.push_back(static_cast<uint8_t>(i)); | |||
| 7330 | } | |||
| 7331 | ||||
| 7332 | // Retrieve the global reservation and sanity check the hostname reserved. | |||
| 7333 | host = hosts_cfg->get4(SUBNET_ID_GLOBAL, Host::IDENT_DUID, &duid[0], duid.size()); | |||
| 7334 | ASSERT_TRUE(host)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(host)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7334 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "host", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7335 | EXPECT_EQ("global1", host->getHostname())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"global1\"" , "host->getHostname()", "global1", host->getHostname() ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7335, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7336 | ||||
| 7337 | // Check that options are assigned correctly. | |||
| 7338 | opt_dns = retrieveOption<Option4AddrLstPtr>(*host, DHO_NAME_SERVERS); | |||
| 7339 | ASSERT_TRUE(opt_dns)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(opt_dns)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7339, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "opt_dns", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7340 | dns_addrs = opt_dns->getAddresses(); | |||
| 7341 | ASSERT_EQ(1, dns_addrs.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "dns_addrs.size()" , 1, dns_addrs.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7341, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7342 | EXPECT_EQ("192.0.3.15", dns_addrs[0].toText())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"192.0.3.15\"" , "dns_addrs[0].toText()", "192.0.3.15", dns_addrs[0].toText( )))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7342, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7343 | opt_ttl = retrieveOption<OptionUint8Ptr>(*host, DHO_DEFAULT_IP_TTL); | |||
| 7344 | ASSERT_TRUE(opt_ttl)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(opt_ttl)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7344, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "opt_ttl", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7345 | EXPECT_EQ(32, static_cast<int>(opt_ttl->getValue()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("32", "static_cast<int>(opt_ttl->getValue())" , 32, static_cast<int>(opt_ttl->getValue())))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7345, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7346 | ||||
| 7347 | // This reservation should be global solely and not assigned to | |||
| 7348 | // either subnet | |||
| 7349 | EXPECT_FALSE(hosts_cfg->get4(123, Host::IDENT_DUID, &duid[0], duid.size()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 123, Host::IDENT_DUID, &duid[0], duid.size())))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7349 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(123, Host::IDENT_DUID, &duid[0], duid.size())" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 7350 | EXPECT_FALSE(hosts_cfg->get4(542, Host::IDENT_DUID, &duid[0], duid.size()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(hosts_cfg->get4( 542, Host::IDENT_DUID, &duid[0], duid.size())))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7350 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "hosts_cfg->get4(542, Host::IDENT_DUID, &duid[0], duid.size())" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 7351 | } | |||
| 7352 | ||||
| 7353 | // Rather than disable these tests they are compiled out. This avoids them | |||
| 7354 | // reporting as disabled and thereby drawing attention to them. | |||
| 7355 | // This test verifies that configuration control with unsupported type fails | |||
| 7356 | TEST_F(Dhcp4ParserTest, configControlInfoNoFactory)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("configControlInfoNoFactory") > 1, "test_name must not be empty"); class Dhcp4ParserTest_configControlInfoNoFactory_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_configControlInfoNoFactory_Test () = default; ~Dhcp4ParserTest_configControlInfoNoFactory_Test () override = default; Dhcp4ParserTest_configControlInfoNoFactory_Test (const Dhcp4ParserTest_configControlInfoNoFactory_Test & ) = delete; Dhcp4ParserTest_configControlInfoNoFactory_Test & operator=( const Dhcp4ParserTest_configControlInfoNoFactory_Test &) = delete; Dhcp4ParserTest_configControlInfoNoFactory_Test (Dhcp4ParserTest_configControlInfoNoFactory_Test &&) noexcept = delete; Dhcp4ParserTest_configControlInfoNoFactory_Test & operator=( Dhcp4ParserTest_configControlInfoNoFactory_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_configControlInfoNoFactory_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "configControlInfoNoFactory", nullptr, nullptr, ::testing:: internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7356), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7356), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7356), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_configControlInfoNoFactory_Test >); void Dhcp4ParserTest_configControlInfoNoFactory_Test:: TestBody() { | |||
| 7357 | string config = PARSER_CONFIGS[5]; | |||
| 7358 | ||||
| 7359 | // Unregister "mysql" and ignore the return value. | |||
| 7360 | static_cast<void>(TestConfigBackendDHCPv4:: | |||
| 7361 | unregisterBackendType(ConfigBackendDHCPv4Mgr::instance(), | |||
| 7362 | "mysql")); | |||
| 7363 | ||||
| 7364 | // Should fail because "type=mysql" has no factories. | |||
| 7365 | configure(config, CONTROL_RESULT_ERROR, | |||
| 7366 | "during update from config backend database: " | |||
| 7367 | "The Kea server has not been compiled with support for configuration " | |||
| 7368 | "database type: mysql. Did you forget to use -D mysql=enabled during " | |||
| 7369 | "setup or to load libdhcp_mysql hook library?"); | |||
| 7370 | } | |||
| 7371 | ||||
| 7372 | // This test verifies that configuration control info gets populated. | |||
| 7373 | TEST_F(Dhcp4ParserTest, configControlInfo)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("configControlInfo") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_configControlInfo_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_configControlInfo_Test() = default ; ~Dhcp4ParserTest_configControlInfo_Test() override = default ; Dhcp4ParserTest_configControlInfo_Test (const Dhcp4ParserTest_configControlInfo_Test &) = delete; Dhcp4ParserTest_configControlInfo_Test & operator=( const Dhcp4ParserTest_configControlInfo_Test & ) = delete; Dhcp4ParserTest_configControlInfo_Test (Dhcp4ParserTest_configControlInfo_Test &&) noexcept = delete; Dhcp4ParserTest_configControlInfo_Test & operator=( Dhcp4ParserTest_configControlInfo_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_configControlInfo_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "configControlInfo", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7373), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7373), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7373), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_configControlInfo_Test >); void Dhcp4ParserTest_configControlInfo_Test::TestBody( ) { | |||
| 7374 | string config = PARSER_CONFIGS[5]; | |||
| 7375 | ||||
| 7376 | // Should be able to register a backend factory for "mysql". | |||
| 7377 | ASSERT_TRUE(TestConfigBackendDHCPv4::switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(TestConfigBackendDHCPv4 :: registerBackendType(ConfigBackendDHCPv4Mgr::instance(), "mysql" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7379, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "TestConfigBackendDHCPv4:: registerBackendType(ConfigBackendDHCPv4Mgr::instance(), \"mysql\")" , "false", "true") .c_str()) = ::testing::Message() | |||
| 7378 | registerBackendType(ConfigBackendDHCPv4Mgr::instance(),switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(TestConfigBackendDHCPv4 :: registerBackendType(ConfigBackendDHCPv4Mgr::instance(), "mysql" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7379, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "TestConfigBackendDHCPv4:: registerBackendType(ConfigBackendDHCPv4Mgr::instance(), \"mysql\")" , "false", "true") .c_str()) = ::testing::Message() | |||
| 7379 | "mysql"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(TestConfigBackendDHCPv4 :: registerBackendType(ConfigBackendDHCPv4Mgr::instance(), "mysql" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7379, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "TestConfigBackendDHCPv4:: registerBackendType(ConfigBackendDHCPv4Mgr::instance(), \"mysql\")" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 7380 | ||||
| 7381 | // Should parse ok, now that the factory has been registered. | |||
| 7382 | configure(config, CONTROL_RESULT_SUCCESS, ""); | |||
| 7383 | ||||
| 7384 | // Make sure the config control info is there. | |||
| 7385 | process::ConstConfigControlInfoPtr info = | |||
| 7386 | CfgMgr::instance().getStagingCfg()->getConfigControlInfo(); | |||
| 7387 | ASSERT_TRUE(info)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(info)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7387 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "info", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7388 | ||||
| 7389 | // Fetch the list of config dbs. It should have two entries. | |||
| 7390 | const process::ConfigDbInfoList& dblist = info->getConfigDatabases(); | |||
| 7391 | ASSERT_EQ(2, dblist.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("2", "dblist.size()" , 2, dblist.size()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7391, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7392 | ||||
| 7393 | // Make sure the entries are what we expect and in the right order. | |||
| 7394 | // (DbAccessParser creates access strings with the keywords in | |||
| 7395 | // alphabetical order). | |||
| 7396 | EXPECT_EQ("name=keatest1 password=keatest type=mysql user=keatest",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"name=keatest1 password=keatest type=mysql user=keatest\"" , "dblist.front().getAccessString()", "name=keatest1 password=keatest type=mysql user=keatest" , dblist.front().getAccessString()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7397, gtest_ar.failure_message()) = ::testing::Message() | |||
| 7397 | dblist.front().getAccessString())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"name=keatest1 password=keatest type=mysql user=keatest\"" , "dblist.front().getAccessString()", "name=keatest1 password=keatest type=mysql user=keatest" , dblist.front().getAccessString()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7397, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7398 | EXPECT_EQ("name=keatest2 password=keatest retry-on-startup=true type=mysql user=keatest",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"name=keatest2 password=keatest retry-on-startup=true type=mysql user=keatest\"" , "dblist.back().getAccessString()", "name=keatest2 password=keatest retry-on-startup=true type=mysql user=keatest" , dblist.back().getAccessString()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7399, gtest_ar.failure_message()) = ::testing::Message() | |||
| 7399 | dblist.back().getAccessString())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"name=keatest2 password=keatest retry-on-startup=true type=mysql user=keatest\"" , "dblist.back().getAccessString()", "name=keatest2 password=keatest retry-on-startup=true type=mysql user=keatest" , dblist.back().getAccessString()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7399, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7400 | ||||
| 7401 | // Verify that the config-fetch-wait-time is correct. | |||
| 7402 | EXPECT_FALSE(info->getConfigFetchWaitTime().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(info->getConfigFetchWaitTime ().unspecified()))) ; else ::testing::internal::AssertHelper( ::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7402, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "info->getConfigFetchWaitTime().unspecified()", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 7403 | EXPECT_EQ(10, info->getConfigFetchWaitTime().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("10", "info->getConfigFetchWaitTime().get()" , 10, info->getConfigFetchWaitTime().get()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7403 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7404 | } | |||
| 7405 | ||||
| 7406 | // Check whether it is possible to configure server-tag | |||
| 7407 | TEST_F(Dhcp4ParserTest, serverTag)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("serverTag") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_serverTag_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_serverTag_Test() = default; ~Dhcp4ParserTest_serverTag_Test () override = default; Dhcp4ParserTest_serverTag_Test (const Dhcp4ParserTest_serverTag_Test &) = delete; Dhcp4ParserTest_serverTag_Test & operator =( const Dhcp4ParserTest_serverTag_Test &) = delete; Dhcp4ParserTest_serverTag_Test (Dhcp4ParserTest_serverTag_Test &&) noexcept = delete ; Dhcp4ParserTest_serverTag_Test & operator=( Dhcp4ParserTest_serverTag_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_serverTag_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "serverTag", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7407 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7407), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7407), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_serverTag_Test >); void Dhcp4ParserTest_serverTag_Test::TestBody() { | |||
| 7408 | // Config without server-tag | |||
| 7409 | string config_no_tag = "{ " + genIfaceConfig() + "," | |||
| 7410 | "\"subnet4\": [ ] " | |||
| 7411 | "}"; | |||
| 7412 | ||||
| 7413 | // Config with server-tag | |||
| 7414 | string config_tag = "{ " + genIfaceConfig() + "," | |||
| 7415 | "\"server-tag\": \"boo\", " | |||
| 7416 | "\"subnet4\": [ ] " | |||
| 7417 | "}"; | |||
| 7418 | ||||
| 7419 | // Config with an invalid server-tag | |||
| 7420 | string bad_tag = "{ " + genIfaceConfig() + "," | |||
| 7421 | "\"server-tag\": 777, " | |||
| 7422 | "\"subnet4\": [ ] " | |||
| 7423 | "}"; | |||
| 7424 | ||||
| 7425 | // Let's check the default. It should be empty. | |||
| 7426 | ASSERT_TRUE(CfgMgr::instance().getStagingCfg()->getServerTag().empty())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(CfgMgr::instance().getStagingCfg ()->getServerTag().empty())) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7426, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()->getServerTag().empty()" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 7427 | ||||
| 7428 | // Configuration with no tag should default to an emtpy tag value. | |||
| 7429 | configure(config_no_tag, CONTROL_RESULT_SUCCESS, ""); | |||
| 7430 | EXPECT_TRUE(CfgMgr::instance().getStagingCfg()->getServerTag().empty())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(CfgMgr::instance().getStagingCfg ()->getServerTag().empty())) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7430, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()->getServerTag().empty()" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 7431 | ||||
| 7432 | // Clear the config | |||
| 7433 | CfgMgr::instance().clear(); | |||
| 7434 | ||||
| 7435 | // Configuration with the tag should have the tag value. | |||
| 7436 | configure(config_tag, CONTROL_RESULT_SUCCESS, ""); | |||
| 7437 | EXPECT_EQ("boo", CfgMgr::instance().getStagingCfg()->getServerTag().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"boo\"" , "CfgMgr::instance().getStagingCfg()->getServerTag().get()" , "boo", CfgMgr::instance().getStagingCfg()->getServerTag( ).get()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7437, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7438 | ||||
| 7439 | // Make sure a invalid server-tag fails to parse. | |||
| 7440 | ASSERT_THROW(parseDHCP4(bad_tag), std::exception)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { parseDHCP4(bad_tag); } else static_assert(true, ""); } catch (std::exception const&) { gtest_caught_expected = true; } catch (typename std::conditional < std::is_same<typename std::remove_cv<typename std:: remove_reference< std::exception>::type>::type, std:: exception>::value, const ::testing::internal::NeverThrown& , const std::exception&>::type e) { gtest_msg.value = "Expected: " "parseDHCP4(bad_tag)" " throws an exception of type " "std::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_7440; } catch (...) { gtest_msg.value = "Expected: " "parseDHCP4(bad_tag)" " throws an exception of type " "std::exception" ".\n Actual: it throws a different type."; goto gtest_label_testthrow_7440; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "parseDHCP4(bad_tag)" " throws an exception of type " "std::exception" ".\n Actual: it throws nothing."; goto gtest_label_testthrow_7440 ; } } else gtest_label_testthrow_7440 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7440, gtest_msg.value.c_str()) = ::testing::Message(); | |||
| 7441 | } | |||
| 7442 | ||||
| 7443 | // Check whether it is possible to configure packet queue | |||
| 7444 | TEST_F(Dhcp4ParserTest, dhcpQueueControl)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("dhcpQueueControl") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_dhcpQueueControl_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_dhcpQueueControl_Test() = default; ~Dhcp4ParserTest_dhcpQueueControl_Test() override = default; Dhcp4ParserTest_dhcpQueueControl_Test (const Dhcp4ParserTest_dhcpQueueControl_Test &) = delete; Dhcp4ParserTest_dhcpQueueControl_Test & operator=( const Dhcp4ParserTest_dhcpQueueControl_Test & ) = delete; Dhcp4ParserTest_dhcpQueueControl_Test (Dhcp4ParserTest_dhcpQueueControl_Test &&) noexcept = delete; Dhcp4ParserTest_dhcpQueueControl_Test & operator=( Dhcp4ParserTest_dhcpQueueControl_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_dhcpQueueControl_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "dhcpQueueControl", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7444), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7444), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7444), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_dhcpQueueControl_Test >); void Dhcp4ParserTest_dhcpQueueControl_Test::TestBody() { | |||
| 7445 | struct Scenario { | |||
| 7446 | std::string description_; | |||
| 7447 | std::string json_; | |||
| 7448 | std::string mt_json_; | |||
| 7449 | }; | |||
| 7450 | ||||
| 7451 | std::vector<Scenario> scenarios = { | |||
| 7452 | { | |||
| 7453 | "no entry", | |||
| 7454 | "", | |||
| 7455 | "", | |||
| 7456 | }, | |||
| 7457 | { | |||
| 7458 | "queue disabled", | |||
| 7459 | "{ \n" | |||
| 7460 | " \"enable-queue\": false \n" | |||
| 7461 | "} \n", | |||
| 7462 | R"("multi-threading": { | |||
| 7463 | "enable-multi-threading": false | |||
| 7464 | })", | |||
| 7465 | }, | |||
| 7466 | { | |||
| 7467 | "queue enabled at first, but gets forcefully disabled by MT", | |||
| 7468 | "{ \n" | |||
| 7469 | " \"enable-queue\": true \n" | |||
| 7470 | "} \n", | |||
| 7471 | R"("multi-threading": { | |||
| 7472 | "enable-multi-threading": true | |||
| 7473 | })", | |||
| 7474 | }, | |||
| 7475 | { | |||
| 7476 | "queue disabled, arbitrary content allowed", | |||
| 7477 | "{ \n" | |||
| 7478 | " \"enable-queue\": false, \n" | |||
| 7479 | " \"foo\": \"bogus\", \n" | |||
| 7480 | " \"random-int\" : 1234 \n" | |||
| 7481 | "} \n", | |||
| 7482 | R"("multi-threading": { | |||
| 7483 | "enable-multi-threading": false | |||
| 7484 | })", | |||
| 7485 | }, | |||
| 7486 | { | |||
| 7487 | "queue enabled, with queue-type", | |||
| 7488 | "{ \n" | |||
| 7489 | " \"enable-queue\": true, \n" | |||
| 7490 | " \"queue-type\": \"some-type\" \n" | |||
| 7491 | "} \n", | |||
| 7492 | R"("multi-threading": { | |||
| 7493 | "enable-multi-threading": false | |||
| 7494 | })", | |||
| 7495 | }, | |||
| 7496 | { | |||
| 7497 | "queue enabled with queue-type and arbitrary content", | |||
| 7498 | "{ \n" | |||
| 7499 | " \"enable-queue\": true, \n" | |||
| 7500 | " \"queue-type\": \"some-type\", \n" | |||
| 7501 | " \"foo\": \"bogus\", \n" | |||
| 7502 | " \"random-int\" : 1234 \n" | |||
| 7503 | "} \n", | |||
| 7504 | R"("multi-threading": { | |||
| 7505 | "enable-multi-threading": false | |||
| 7506 | })", | |||
| 7507 | } | |||
| 7508 | }; | |||
| 7509 | ||||
| 7510 | // Let's check the default. It should be empty. | |||
| 7511 | data::ConstElementPtr staged_control; | |||
| 7512 | staged_control = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl(); | |||
| 7513 | ASSERT_FALSE(staged_control)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(staged_control))) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7513, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "staged_control", "true", "false") .c_str()) = ::testing::Message (); | |||
| 7514 | ||||
| 7515 | // Iterate over the valid scenarios and verify they succeed. | |||
| 7516 | data::ElementPtr exp_control; | |||
| 7517 | for (auto const& scenario : scenarios) { | |||
| 7518 | SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_7518( "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7518, (scenario.description_)); | |||
| 7519 | { | |||
| 7520 | // Clear the config | |||
| 7521 | CfgMgr::instance().clear(); | |||
| 7522 | ||||
| 7523 | // Construct the config JSON | |||
| 7524 | std::stringstream os; | |||
| 7525 | os << "{ " + genIfaceConfig(); | |||
| 7526 | if (!scenario.json_.empty()) { | |||
| 7527 | os << ",\n \"dhcp-queue-control\": " << scenario.json_; | |||
| 7528 | } | |||
| 7529 | if (!scenario.mt_json_.empty()) { | |||
| 7530 | os << ",\n" << scenario.mt_json_; | |||
| 7531 | } | |||
| 7532 | os << "\n}\n"; | |||
| 7533 | ||||
| 7534 | // Configure the server. This should succeed. | |||
| 7535 | configure(os.str(), CONTROL_RESULT_SUCCESS, ""); | |||
| 7536 | ||||
| 7537 | // Fetch the queue control info. | |||
| 7538 | staged_control = CfgMgr::instance().getStagingCfg()->getDHCPQueueControl(); | |||
| 7539 | ||||
| 7540 | // Make sure the staged queue config exists. | |||
| 7541 | ASSERT_TRUE(staged_control)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(staged_control)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7541, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "staged_control", "false", "true") .c_str()) = ::testing::Message (); | |||
| 7542 | ||||
| 7543 | // Now build the expected queue control content. | |||
| 7544 | if (scenario.json_.empty()) { | |||
| 7545 | exp_control = Element::createMap(); | |||
| 7546 | } else { | |||
| 7547 | try { | |||
| 7548 | exp_control = boost::const_pointer_cast<Element>(Element::fromJSON(scenario.json_)); | |||
| 7549 | } catch (const std::exception& ex) { | |||
| 7550 | ADD_FAILURE()::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7550, "Failed") = ::testing::Message() << " cannot convert expected JSON, test is broken:" | |||
| 7551 | << ex.what(); | |||
| 7552 | } | |||
| 7553 | } | |||
| 7554 | ||||
| 7555 | // Add the defaults to expected queue control. | |||
| 7556 | SimpleParser4::setDefaults(exp_control, SimpleParser4::DHCP_QUEUE_CONTROL4_DEFAULTS); | |||
| 7557 | ||||
| 7558 | // This specific scenario is the only one where we expect enable-queue | |||
| 7559 | // to be changed from what the user set it to. | |||
| 7560 | if (scenario.description_ == "queue enabled at first, but gets forcefully disabled by MT") { | |||
| 7561 | exp_control->set("enable-queue", Element::create(false)); | |||
| 7562 | } | |||
| 7563 | ||||
| 7564 | // Verify that the staged queue control equals the expected queue control. | |||
| 7565 | expectEqWithDiff(staged_control, exp_control); | |||
| 7566 | } | |||
| 7567 | } | |||
| 7568 | } | |||
| 7569 | ||||
| 7570 | // Check that we catch invalid dhcp-queue-control content | |||
| 7571 | TEST_F(Dhcp4ParserTest, dhcpQueueControlInvalid)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("dhcpQueueControlInvalid") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_dhcpQueueControlInvalid_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_dhcpQueueControlInvalid_Test () = default; ~Dhcp4ParserTest_dhcpQueueControlInvalid_Test() override = default; Dhcp4ParserTest_dhcpQueueControlInvalid_Test (const Dhcp4ParserTest_dhcpQueueControlInvalid_Test &) = delete; Dhcp4ParserTest_dhcpQueueControlInvalid_Test & operator =( const Dhcp4ParserTest_dhcpQueueControlInvalid_Test &) = delete; Dhcp4ParserTest_dhcpQueueControlInvalid_Test (Dhcp4ParserTest_dhcpQueueControlInvalid_Test &&) noexcept = delete; Dhcp4ParserTest_dhcpQueueControlInvalid_Test & operator=( Dhcp4ParserTest_dhcpQueueControlInvalid_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_dhcpQueueControlInvalid_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "dhcpQueueControlInvalid", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7571), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7571), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7571), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_dhcpQueueControlInvalid_Test >); void Dhcp4ParserTest_dhcpQueueControlInvalid_Test::TestBody () { | |||
| 7572 | struct Scenario { | |||
| 7573 | std::string description_; | |||
| 7574 | std::string json_; | |||
| 7575 | std::string exp_error_; | |||
| 7576 | }; | |||
| 7577 | ||||
| 7578 | std::vector<Scenario> scenarios = { | |||
| 7579 | { | |||
| 7580 | "not a map", | |||
| 7581 | "75 \n", | |||
| 7582 | "<string>:2.24-25: syntax error, unexpected integer, expecting {" | |||
| 7583 | }, | |||
| 7584 | { | |||
| 7585 | "enable-queue missing", | |||
| 7586 | "{ \n" | |||
| 7587 | " \"enable-type\": \"some-type\" \n" | |||
| 7588 | "} \n", | |||
| 7589 | "missing parameter 'enable-queue' (<string>:2:2) " | |||
| 7590 | "[dhcp-queue-control map between <string>:2:24 and <string>:4:1]" | |||
| 7591 | }, | |||
| 7592 | { | |||
| 7593 | "enable-queue not boolean", | |||
| 7594 | "{ \n" | |||
| 7595 | " \"enable-queue\": \"always\" \n" | |||
| 7596 | "} \n", | |||
| 7597 | "<string>:3.20-27: syntax error, unexpected constant string, " | |||
| 7598 | "expecting boolean" | |||
| 7599 | }, | |||
| 7600 | { | |||
| 7601 | "queue enabled, type not a string", | |||
| 7602 | "{ \n" | |||
| 7603 | " \"enable-queue\": true, \n" | |||
| 7604 | " \"queue-type\": 7777 \n" | |||
| 7605 | "} \n", | |||
| 7606 | "<string>:4.18-21: syntax error, unexpected integer, " | |||
| 7607 | "expecting constant string" | |||
| 7608 | } | |||
| 7609 | }; | |||
| 7610 | ||||
| 7611 | // Iterate over the incorrect scenarios and verify they | |||
| 7612 | // fail as expected. Note, we use parseDHCP4() directly | |||
| 7613 | // as all of the errors above are enforced by the grammar. | |||
| 7614 | for (auto const& scenario : scenarios) { | |||
| 7615 | SCOPED_TRACE(scenario.description_)const ::testing::ScopedTrace gtest_trace_7615( "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7615, (scenario.description_)); | |||
| 7616 | { | |||
| 7617 | // Construct the config JSON | |||
| 7618 | std::stringstream os; | |||
| 7619 | os << "{ " + genIfaceConfig(); | |||
| 7620 | os << ",\n \"dhcp-queue-control\": " << scenario.json_; | |||
| 7621 | os << "} \n"; | |||
| 7622 | ||||
| 7623 | std::string error_msg = ""; | |||
| 7624 | try { | |||
| 7625 | ASSERT_TRUE(parseDHCP4(os.str(), false))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(parseDHCP4(os.str(), false ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7625, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "parseDHCP4(os.str(), false)", "false", "true") .c_str()) = ::testing::Message() << "parser returned empty element"; | |||
| 7626 | } catch(const std::exception& ex) { | |||
| 7627 | error_msg = ex.what(); | |||
| 7628 | } | |||
| 7629 | ||||
| 7630 | ASSERT_FALSE(error_msg.empty())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(error_msg.empty())) ) ; else return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7630, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "error_msg.empty()", "true", "false") .c_str()) = ::testing ::Message() << "parseDHCP4 should have thrown"; | |||
| 7631 | EXPECT_EQ(scenario.exp_error_, error_msg)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("scenario.exp_error_" , "error_msg", scenario.exp_error_, error_msg))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7631 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7632 | } | |||
| 7633 | } | |||
| 7634 | } | |||
| 7635 | ||||
| 7636 | // Checks inheritence of calculate-tee-times, t1-percent, t2-percent | |||
| 7637 | TEST_F(Dhcp4ParserTest, calculateTeeTimesInheritence)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("calculateTeeTimesInheritence") > 1 , "test_name must not be empty"); class Dhcp4ParserTest_calculateTeeTimesInheritence_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_calculateTeeTimesInheritence_Test () = default; ~Dhcp4ParserTest_calculateTeeTimesInheritence_Test () override = default; Dhcp4ParserTest_calculateTeeTimesInheritence_Test (const Dhcp4ParserTest_calculateTeeTimesInheritence_Test & ) = delete; Dhcp4ParserTest_calculateTeeTimesInheritence_Test & operator=( const Dhcp4ParserTest_calculateTeeTimesInheritence_Test &) = delete; Dhcp4ParserTest_calculateTeeTimesInheritence_Test (Dhcp4ParserTest_calculateTeeTimesInheritence_Test && ) noexcept = delete; Dhcp4ParserTest_calculateTeeTimesInheritence_Test & operator=( Dhcp4ParserTest_calculateTeeTimesInheritence_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_calculateTeeTimesInheritence_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "calculateTeeTimesInheritence", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7637), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7637), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7637), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_calculateTeeTimesInheritence_Test >); void Dhcp4ParserTest_calculateTeeTimesInheritence_Test ::TestBody() { | |||
| 7638 | // Configure the server. This should succeed. | |||
| 7639 | string config = | |||
| 7640 | "{ \n" | |||
| 7641 | " \"interfaces-config\": { \n" | |||
| 7642 | " \"interfaces\": [\"*\" ] \n" | |||
| 7643 | " }, \n" | |||
| 7644 | " \"valid-lifetime\": 4000, \n" | |||
| 7645 | " \"shared-networks\": [ { \n" | |||
| 7646 | " \"name\": \"foo\", \n" | |||
| 7647 | " \"calculate-tee-times\": true, \n" | |||
| 7648 | " \"t1-percent\": .4, \n" | |||
| 7649 | " \"t2-percent\": .75,\n" | |||
| 7650 | " \"subnet4\": [" | |||
| 7651 | " { " | |||
| 7652 | " \"id\": 100," | |||
| 7653 | " \"subnet\": \"192.0.1.0/24\", \n" | |||
| 7654 | " \"pools\": [ { \"pool\": \"192.0.1.1-192.0.1.10\" } ], \n" | |||
| 7655 | " \"calculate-tee-times\": false,\n" | |||
| 7656 | " \"t1-percent\": .45, \n" | |||
| 7657 | " \"t2-percent\": .65 \n" | |||
| 7658 | " }, \n" | |||
| 7659 | " { \n" | |||
| 7660 | " \"id\": 200, \n" | |||
| 7661 | " \"subnet\": \"192.0.2.0/24\", \n" | |||
| 7662 | " \"pools\": [ { \"pool\": \"192.0.2.1-192.0.2.10\" } ] \n" | |||
| 7663 | " } \n" | |||
| 7664 | " ] \n" | |||
| 7665 | " } ], \n" | |||
| 7666 | " \"subnet4\": [ { \n" | |||
| 7667 | " \"id\": 300, \n" | |||
| 7668 | " \"subnet\": \"192.0.3.0/24\", \n" | |||
| 7669 | " \"pools\": [ { \"pool\": \"192.0.3.0 - 192.0.3.15\" } ]\n" | |||
| 7670 | " } ] \n" | |||
| 7671 | "} \n"; | |||
| 7672 | ||||
| 7673 | extractConfig(config); | |||
| 7674 | configure(config, CONTROL_RESULT_SUCCESS, ""); | |||
| 7675 | ||||
| 7676 | CfgSubnets4Ptr subnets4 = CfgMgr::instance().getStagingCfg()->getCfgSubnets4(); | |||
| 7677 | ||||
| 7678 | // Subnet 100 should use its own explicit values. | |||
| 7679 | ConstSubnet4Ptr subnet4 = subnets4->getBySubnetId(100); | |||
| 7680 | ASSERT_TRUE(subnet4)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet4)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7680, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet4", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7681 | EXPECT_FALSE(subnet4->getCalculateTeeTimes())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet4->getCalculateTeeTimes ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7681, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet4->getCalculateTeeTimes()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 7682 | EXPECT_TRUE(util::areDoublesEquivalent(0.45, subnet4->getT1Percent()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(util::areDoublesEquivalent (0.45, subnet4->getT1Percent()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7682, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "util::areDoublesEquivalent(0.45, subnet4->getT1Percent())" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 7683 | EXPECT_TRUE(util::areDoublesEquivalent(0.65, subnet4->getT2Percent()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(util::areDoublesEquivalent (0.65, subnet4->getT2Percent()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7683, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "util::areDoublesEquivalent(0.65, subnet4->getT2Percent())" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 7684 | ||||
| 7685 | // Subnet 200 should use the shared-network values. | |||
| 7686 | subnet4 = subnets4->getBySubnetId(200); | |||
| 7687 | ASSERT_TRUE(subnet4)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet4)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7687, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet4", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7688 | EXPECT_TRUE(subnet4->getCalculateTeeTimes())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet4->getCalculateTeeTimes ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7688, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet4->getCalculateTeeTimes()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 7689 | EXPECT_TRUE(util::areDoublesEquivalent(0.4, subnet4->getT1Percent()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(util::areDoublesEquivalent (0.4, subnet4->getT1Percent()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7689, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "util::areDoublesEquivalent(0.4, subnet4->getT1Percent())" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 7690 | EXPECT_TRUE(util::areDoublesEquivalent(0.75, subnet4->getT2Percent()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(util::areDoublesEquivalent (0.75, subnet4->getT2Percent()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7690, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "util::areDoublesEquivalent(0.75, subnet4->getT2Percent())" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 7691 | ||||
| 7692 | // Subnet 300 should use the global values. | |||
| 7693 | subnet4 = subnets4->getBySubnetId(300); | |||
| 7694 | ASSERT_TRUE(subnet4)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet4)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7694, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet4", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7695 | EXPECT_FALSE(subnet4->getCalculateTeeTimes())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet4->getCalculateTeeTimes ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7695, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet4->getCalculateTeeTimes()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 7696 | EXPECT_TRUE(util::areDoublesEquivalent(0.5, subnet4->getT1Percent()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(util::areDoublesEquivalent (0.5, subnet4->getT1Percent()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7696, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "util::areDoublesEquivalent(0.5, subnet4->getT1Percent())" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 7697 | EXPECT_TRUE(util::areDoublesEquivalent(0.875, subnet4->getT2Percent()))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(util::areDoublesEquivalent (0.875, subnet4->getT2Percent()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7697, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "util::areDoublesEquivalent(0.875, subnet4->getT2Percent())" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 7698 | } | |||
| 7699 | ||||
| 7700 | // This test checks that the global store-extended-info parameter is optional | |||
| 7701 | // and that values under the subnet are used. | |||
| 7702 | TEST_F(Dhcp4ParserTest, storeExtendedInfoNoGlobal)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("storeExtendedInfoNoGlobal") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_storeExtendedInfoNoGlobal_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_storeExtendedInfoNoGlobal_Test () = default; ~Dhcp4ParserTest_storeExtendedInfoNoGlobal_Test () override = default; Dhcp4ParserTest_storeExtendedInfoNoGlobal_Test (const Dhcp4ParserTest_storeExtendedInfoNoGlobal_Test &) = delete; Dhcp4ParserTest_storeExtendedInfoNoGlobal_Test & operator=( const Dhcp4ParserTest_storeExtendedInfoNoGlobal_Test &) = delete; Dhcp4ParserTest_storeExtendedInfoNoGlobal_Test (Dhcp4ParserTest_storeExtendedInfoNoGlobal_Test &&) noexcept = delete; Dhcp4ParserTest_storeExtendedInfoNoGlobal_Test & operator=( Dhcp4ParserTest_storeExtendedInfoNoGlobal_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_storeExtendedInfoNoGlobal_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "storeExtendedInfoNoGlobal", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7702), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7702), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7702), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_storeExtendedInfoNoGlobal_Test >); void Dhcp4ParserTest_storeExtendedInfoNoGlobal_Test::TestBody () { | |||
| 7703 | const string config = "{ " + genIfaceConfig() + "," | |||
| 7704 | "\"rebind-timer\": 2000, " | |||
| 7705 | "\"renew-timer\": 1000, " | |||
| 7706 | "\"subnet4\": [ " | |||
| 7707 | "{" | |||
| 7708 | " \"id\": 1," | |||
| 7709 | " \"store-extended-info\": true," | |||
| 7710 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 7711 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 7712 | "}," | |||
| 7713 | "{" | |||
| 7714 | " \"id\": 2," | |||
| 7715 | " \"store-extended-info\": false," | |||
| 7716 | " \"pools\": [ { \"pool\": \"192.0.3.1 - 192.0.3.100\" } ]," | |||
| 7717 | " \"subnet\": \"192.0.3.0/24\"" | |||
| 7718 | "} ]," | |||
| 7719 | "\"valid-lifetime\": 4000 }"; | |||
| 7720 | ||||
| 7721 | ConstElementPtr json; | |||
| 7722 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_7722 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_7722 ; } } else gtest_label_testnothrow_7722 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7722, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 7723 | extractConfig(config); | |||
| 7724 | ||||
| 7725 | ConstElementPtr status; | |||
| 7726 | ASSERT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_7726; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_7726; } } else gtest_label_testnothrow_7726 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7726, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 7727 | checkResult(status, 0); | |||
| 7728 | ||||
| 7729 | // First subnet should use global default. | |||
| 7730 | CfgSubnets4Ptr cfg = CfgMgr::instance().getStagingCfg()->getCfgSubnets4(); | |||
| 7731 | ConstSubnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1")); | |||
| 7732 | ASSERT_TRUE(subnet1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet1)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7732, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7733 | // Reset the fetch global function to staging (vs current) config. | |||
| 7734 | Subnet4Ptr mutable_subnet1 = boost::const_pointer_cast<Subnet4>(subnet1); | |||
| 7735 | mutable_subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr { | |||
| 7736 | return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals()); | |||
| 7737 | }); | |||
| 7738 | EXPECT_TRUE(subnet1->getStoreExtendedInfo())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet1->getStoreExtendedInfo ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7738, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1->getStoreExtendedInfo()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 7739 | ||||
| 7740 | // Second subnet should use its own value. | |||
| 7741 | ConstSubnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1")); | |||
| 7742 | ASSERT_TRUE(subnet2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7742, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7743 | // Reset the fetch global function to staging (vs current) config. | |||
| 7744 | Subnet4Ptr mutable_subnet2 = boost::const_pointer_cast<Subnet4>(subnet2); | |||
| 7745 | mutable_subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr { | |||
| 7746 | return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals()); | |||
| 7747 | }); | |||
| 7748 | EXPECT_FALSE(subnet2->getStoreExtendedInfo())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet2->getStoreExtendedInfo ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7748, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2->getStoreExtendedInfo()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 7749 | } | |||
| 7750 | ||||
| 7751 | // This test checks that the global store-extended-info parameter is used | |||
| 7752 | // when there is no such parameter under subnet and that the parameter | |||
| 7753 | // specified for a subnet overrides the global setting. | |||
| 7754 | TEST_F(Dhcp4ParserTest, storeExtendedInfoGlobal)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("storeExtendedInfoGlobal") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_storeExtendedInfoGlobal_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_storeExtendedInfoGlobal_Test () = default; ~Dhcp4ParserTest_storeExtendedInfoGlobal_Test() override = default; Dhcp4ParserTest_storeExtendedInfoGlobal_Test (const Dhcp4ParserTest_storeExtendedInfoGlobal_Test &) = delete; Dhcp4ParserTest_storeExtendedInfoGlobal_Test & operator =( const Dhcp4ParserTest_storeExtendedInfoGlobal_Test &) = delete; Dhcp4ParserTest_storeExtendedInfoGlobal_Test (Dhcp4ParserTest_storeExtendedInfoGlobal_Test &&) noexcept = delete; Dhcp4ParserTest_storeExtendedInfoGlobal_Test & operator=( Dhcp4ParserTest_storeExtendedInfoGlobal_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_storeExtendedInfoGlobal_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "storeExtendedInfoGlobal", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7754), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7754), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7754), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_storeExtendedInfoGlobal_Test >); void Dhcp4ParserTest_storeExtendedInfoGlobal_Test::TestBody () { | |||
| 7755 | const string config = "{ " + genIfaceConfig() + "," | |||
| 7756 | "\"rebind-timer\": 2000, " | |||
| 7757 | "\"renew-timer\": 1000, " | |||
| 7758 | "\"store-extended-info\": true," | |||
| 7759 | "\"subnet4\": [ " | |||
| 7760 | "{" | |||
| 7761 | " \"id\": 1," | |||
| 7762 | " \"store-extended-info\": false," | |||
| 7763 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 7764 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 7765 | "}," | |||
| 7766 | "{" | |||
| 7767 | " \"id\": 2," | |||
| 7768 | " \"pools\": [ { \"pool\": \"192.0.3.1 - 192.0.3.100\" } ]," | |||
| 7769 | " \"subnet\": \"192.0.3.0/24\"" | |||
| 7770 | "} ]," | |||
| 7771 | "\"valid-lifetime\": 4000 }"; | |||
| 7772 | ||||
| 7773 | ConstElementPtr json; | |||
| 7774 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_7774 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_7774 ; } } else gtest_label_testnothrow_7774 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7774, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 7775 | extractConfig(config); | |||
| 7776 | ||||
| 7777 | ConstElementPtr status; | |||
| 7778 | ASSERT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_7778; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_7778; } } else gtest_label_testnothrow_7778 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7778, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 7779 | checkResult(status, 0); | |||
| 7780 | ||||
| 7781 | // First subnet should override the global value. | |||
| 7782 | CfgSubnets4Ptr cfg = CfgMgr::instance().getStagingCfg()->getCfgSubnets4(); | |||
| 7783 | ConstSubnet4Ptr subnet1 = cfg->selectSubnet(IOAddress("192.0.2.1")); | |||
| 7784 | ASSERT_TRUE(subnet1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet1)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7784, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7785 | // Reset the fetch global function to staging (vs current) config. | |||
| 7786 | Subnet4Ptr mutable_subnet1 = boost::const_pointer_cast<Subnet4>(subnet1); | |||
| 7787 | mutable_subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr { | |||
| 7788 | return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals()); | |||
| 7789 | }); | |||
| 7790 | EXPECT_FALSE(subnet1->getStoreExtendedInfo())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet1->getStoreExtendedInfo ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7790, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1->getStoreExtendedInfo()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 7791 | ||||
| 7792 | ConstSubnet4Ptr subnet2 = cfg->selectSubnet(IOAddress("192.0.3.1")); | |||
| 7793 | ASSERT_TRUE(subnet2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7793, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7794 | // Reset the fetch global function to staging (vs current) config. | |||
| 7795 | Subnet4Ptr mutable_subnet2 = boost::const_pointer_cast<Subnet4>(subnet2); | |||
| 7796 | mutable_subnet2->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr { | |||
| 7797 | return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals()); | |||
| 7798 | }); | |||
| 7799 | EXPECT_TRUE(subnet2->getStoreExtendedInfo())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet2->getStoreExtendedInfo ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7799, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet2->getStoreExtendedInfo()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 7800 | } | |||
| 7801 | ||||
| 7802 | /// This test checks that the statistic-default-sample-count and age | |||
| 7803 | /// global parameters are committed to the stats manager as expected. | |||
| 7804 | TEST_F(Dhcp4ParserTest, statsDefaultLimits)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("statsDefaultLimits") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_statsDefaultLimits_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_statsDefaultLimits_Test() = default ; ~Dhcp4ParserTest_statsDefaultLimits_Test() override = default ; Dhcp4ParserTest_statsDefaultLimits_Test (const Dhcp4ParserTest_statsDefaultLimits_Test &) = delete; Dhcp4ParserTest_statsDefaultLimits_Test & operator=( const Dhcp4ParserTest_statsDefaultLimits_Test & ) = delete; Dhcp4ParserTest_statsDefaultLimits_Test (Dhcp4ParserTest_statsDefaultLimits_Test &&) noexcept = delete; Dhcp4ParserTest_statsDefaultLimits_Test & operator=( Dhcp4ParserTest_statsDefaultLimits_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_statsDefaultLimits_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "statsDefaultLimits", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7804), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7804), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7804), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_statsDefaultLimits_Test >); void Dhcp4ParserTest_statsDefaultLimits_Test::TestBody () { | |||
| 7805 | std::string config = "{ " + genIfaceConfig() + "," | |||
| 7806 | "\"rebind-timer\": 2000, " | |||
| 7807 | "\"renew-timer\": 1000, " | |||
| 7808 | "\"statistic-default-sample-count\": 10, " | |||
| 7809 | "\"statistic-default-sample-age\": 5, " | |||
| 7810 | "\"valid-lifetime\": 4000 }"; | |||
| 7811 | ||||
| 7812 | ConstElementPtr json; | |||
| 7813 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_7813 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_7813 ; } } else gtest_label_testnothrow_7813 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7813, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 7814 | extractConfig(config); | |||
| 7815 | ||||
| 7816 | ConstElementPtr status; | |||
| 7817 | ASSERT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_7817; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_7817; } } else gtest_label_testnothrow_7817 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7817, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 7818 | checkResult(status, 0); | |||
| 7819 | ||||
| 7820 | CfgMgr::instance().commit(); | |||
| 7821 | ||||
| 7822 | stats::StatsMgr& stats_mgr = stats::StatsMgr::instance(); | |||
| 7823 | EXPECT_EQ(10, stats_mgr.getMaxSampleCountDefault())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("10", "stats_mgr.getMaxSampleCountDefault()" , 10, stats_mgr.getMaxSampleCountDefault()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7823 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7824 | EXPECT_EQ("00:00:05",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"00:00:05\"" , "util::durationToText(stats_mgr.getMaxSampleAgeDefault(), 0)" , "00:00:05", util::durationToText(stats_mgr.getMaxSampleAgeDefault (), 0)))) ; else ::testing::internal::AssertHelper(::testing:: TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7825, gtest_ar.failure_message()) = ::testing::Message() | |||
| 7825 | util::durationToText(stats_mgr.getMaxSampleAgeDefault(), 0))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"00:00:05\"" , "util::durationToText(stats_mgr.getMaxSampleAgeDefault(), 0)" , "00:00:05", util::durationToText(stats_mgr.getMaxSampleAgeDefault (), 0)))) ; else ::testing::internal::AssertHelper(::testing:: TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7825, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7826 | } | |||
| 7827 | ||||
| 7828 | // This test checks that using default multi threading settings works. | |||
| 7829 | TEST_F(Dhcp4ParserTest, multiThreadingDefaultSettings)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("multiThreadingDefaultSettings") > 1, "test_name must not be empty"); class Dhcp4ParserTest_multiThreadingDefaultSettings_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_multiThreadingDefaultSettings_Test () = default; ~Dhcp4ParserTest_multiThreadingDefaultSettings_Test () override = default; Dhcp4ParserTest_multiThreadingDefaultSettings_Test (const Dhcp4ParserTest_multiThreadingDefaultSettings_Test & ) = delete; Dhcp4ParserTest_multiThreadingDefaultSettings_Test & operator=( const Dhcp4ParserTest_multiThreadingDefaultSettings_Test &) = delete; Dhcp4ParserTest_multiThreadingDefaultSettings_Test (Dhcp4ParserTest_multiThreadingDefaultSettings_Test && ) noexcept = delete; Dhcp4ParserTest_multiThreadingDefaultSettings_Test & operator=( Dhcp4ParserTest_multiThreadingDefaultSettings_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_multiThreadingDefaultSettings_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "multiThreadingDefaultSettings", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7829), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7829), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7829), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_multiThreadingDefaultSettings_Test >); void Dhcp4ParserTest_multiThreadingDefaultSettings_Test ::TestBody() { | |||
| 7830 | std::string config = "{ " + genIfaceConfig() + "," | |||
| 7831 | "\"subnet4\": [ ]" | |||
| 7832 | "}"; | |||
| 7833 | ||||
| 7834 | ConstElementPtr json; | |||
| 7835 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_7835 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_7835 ; } } else gtest_label_testnothrow_7835 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7835, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 7836 | extractConfig(config); | |||
| 7837 | ||||
| 7838 | ConstElementPtr status; | |||
| 7839 | ASSERT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_7839; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_7839; } } else gtest_label_testnothrow_7839 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7839, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 7840 | checkResult(status, 0); | |||
| 7841 | ||||
| 7842 | ConstElementPtr cfg = CfgMgr::instance().getStagingCfg()->getDHCPMultiThreading(); | |||
| 7843 | ASSERT_TRUE(cfg)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(cfg)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7843 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "cfg", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7844 | ||||
| 7845 | std::string content_json = | |||
| 7846 | "{" | |||
| 7847 | " \"enable-multi-threading\": true,\n" | |||
| 7848 | " \"thread-pool-size\": 0,\n" | |||
| 7849 | " \"packet-queue-size\": 64\n" | |||
| 7850 | "}"; | |||
| 7851 | ConstElementPtr param; | |||
| 7852 | ASSERT_NO_THROW(param = Element::fromJSON(content_json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { param = Element::fromJSON(content_json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_7852; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_7852; } } else gtest_label_testnothrow_7852 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7852, ("Expected: " "param = Element::fromJSON(content_json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() | |||
| 7853 | << "invalid context_json, test is broken"; | |||
| 7854 | ASSERT_TRUE(param->equals(*cfg))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(param->equals(*cfg ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7854, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "param->equals(*cfg)", "false", "true") .c_str()) = ::testing ::Message() | |||
| 7855 | << "expected: " << *(param) << std::endl | |||
| 7856 | << " actual: " << *(cfg) << std::endl; | |||
| 7857 | } | |||
| 7858 | ||||
| 7859 | // This test checks that adding multi threading settings works. | |||
| 7860 | TEST_F(Dhcp4ParserTest, multiThreadingSettings)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("multiThreadingSettings") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_multiThreadingSettings_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_multiThreadingSettings_Test () = default; ~Dhcp4ParserTest_multiThreadingSettings_Test() override = default; Dhcp4ParserTest_multiThreadingSettings_Test (const Dhcp4ParserTest_multiThreadingSettings_Test &) = delete; Dhcp4ParserTest_multiThreadingSettings_Test & operator=( const Dhcp4ParserTest_multiThreadingSettings_Test &) = delete ; Dhcp4ParserTest_multiThreadingSettings_Test (Dhcp4ParserTest_multiThreadingSettings_Test &&) noexcept = delete; Dhcp4ParserTest_multiThreadingSettings_Test & operator=( Dhcp4ParserTest_multiThreadingSettings_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_multiThreadingSettings_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "multiThreadingSettings", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7860), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7860), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7860), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_multiThreadingSettings_Test >); void Dhcp4ParserTest_multiThreadingSettings_Test::TestBody () { | |||
| 7861 | std::string content_json = | |||
| 7862 | "{" | |||
| 7863 | " \"enable-multi-threading\": true,\n" | |||
| 7864 | " \"thread-pool-size\": 48,\n" | |||
| 7865 | " \"packet-queue-size\": 1024\n" | |||
| 7866 | "}"; | |||
| 7867 | std::string config = "{ " + genIfaceConfig() + "," | |||
| 7868 | "\"subnet4\": [ ], " | |||
| 7869 | "\"multi-threading\": " + content_json + "}"; | |||
| 7870 | ||||
| 7871 | ConstElementPtr json; | |||
| 7872 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_7872 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_7872 ; } } else gtest_label_testnothrow_7872 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7872, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 7873 | extractConfig(config); | |||
| 7874 | ||||
| 7875 | ConstElementPtr status; | |||
| 7876 | ASSERT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_7876; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_7876; } } else gtest_label_testnothrow_7876 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7876, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 7877 | checkResult(status, 0); | |||
| 7878 | ||||
| 7879 | ConstElementPtr cfg = CfgMgr::instance().getStagingCfg()->getDHCPMultiThreading(); | |||
| 7880 | ASSERT_TRUE(cfg)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(cfg)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 7880 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "cfg", "false", "true") .c_str()) = ::testing::Message(); | |||
| 7881 | ||||
| 7882 | ConstElementPtr param; | |||
| 7883 | ASSERT_NO_THROW(param = Element::fromJSON(content_json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { param = Element::fromJSON(content_json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_7883; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_7883; } } else gtest_label_testnothrow_7883 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7883, ("Expected: " "param = Element::fromJSON(content_json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message() | |||
| 7884 | << "invalid context_json, test is broken"; | |||
| 7885 | ASSERT_TRUE(param->equals(*cfg))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(param->equals(*cfg ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7885, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "param->equals(*cfg)", "false", "true") .c_str()) = ::testing ::Message() | |||
| 7886 | << "expected: " << *(param) << std::endl | |||
| 7887 | << " actual: " << *(cfg) << std::endl; | |||
| 7888 | } | |||
| 7889 | ||||
| 7890 | // Verify that parsing for the global parameter, parked-packet-limit, | |||
| 7891 | // is correct. | |||
| 7892 | TEST_F(Dhcp4ParserTest, parkedPacketLimit)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("parkedPacketLimit") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_parkedPacketLimit_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_parkedPacketLimit_Test() = default ; ~Dhcp4ParserTest_parkedPacketLimit_Test() override = default ; Dhcp4ParserTest_parkedPacketLimit_Test (const Dhcp4ParserTest_parkedPacketLimit_Test &) = delete; Dhcp4ParserTest_parkedPacketLimit_Test & operator=( const Dhcp4ParserTest_parkedPacketLimit_Test & ) = delete; Dhcp4ParserTest_parkedPacketLimit_Test (Dhcp4ParserTest_parkedPacketLimit_Test &&) noexcept = delete; Dhcp4ParserTest_parkedPacketLimit_Test & operator=( Dhcp4ParserTest_parkedPacketLimit_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_parkedPacketLimit_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "parkedPacketLimit", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7892), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7892), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7892), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_parkedPacketLimit_Test >); void Dhcp4ParserTest_parkedPacketLimit_Test::TestBody( ) { | |||
| 7893 | // Config without parked-packet-limit | |||
| 7894 | string config_no_limit = "{ " + genIfaceConfig() + "," | |||
| 7895 | "\"subnet4\": [ ] " | |||
| 7896 | "}"; | |||
| 7897 | ||||
| 7898 | // Config with parked-packet-limit | |||
| 7899 | string config_limit = "{ " + genIfaceConfig() + "," | |||
| 7900 | "\"parked-packet-limit\": 777, " | |||
| 7901 | "\"subnet4\": [ ] " | |||
| 7902 | "}"; | |||
| 7903 | ||||
| 7904 | // Config with an invalid parked-packet-limit | |||
| 7905 | string bad_limit = "{ " + genIfaceConfig() + "," | |||
| 7906 | "\"parked-packet-limit\": \"boo\", " | |||
| 7907 | "\"subnet4\": [ ] " | |||
| 7908 | "}"; | |||
| 7909 | ||||
| 7910 | // Should not exist after construction. | |||
| 7911 | ASSERT_FALSE(CfgMgr::instance().getStagingCfg()->getConfiguredGlobal("parked-packet-limit"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(CfgMgr::instance(). getStagingCfg()->getConfiguredGlobal("parked-packet-limit" )))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7911, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "CfgMgr::instance().getStagingCfg()->getConfiguredGlobal(\"parked-packet-limit\")" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 7912 | ||||
| 7913 | // Configuration with no limit should default to 256. | |||
| 7914 | configure(config_no_limit, CONTROL_RESULT_SUCCESS, ""); | |||
| 7915 | ConstElementPtr ppl; | |||
| 7916 | ASSERT_TRUE(ppl = CfgMgr::instance().getStagingCfg()->getConfiguredGlobal("parked-packet-limit"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ppl = CfgMgr::instance ().getStagingCfg()->getConfiguredGlobal("parked-packet-limit" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7916, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ppl = CfgMgr::instance().getStagingCfg()->getConfiguredGlobal(\"parked-packet-limit\")" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 7917 | EXPECT_EQ(256, ppl->intValue())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("256", "ppl->intValue()" , 256, ppl->intValue()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7917, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7918 | ||||
| 7919 | // Clear the config | |||
| 7920 | CfgMgr::instance().clear(); | |||
| 7921 | ||||
| 7922 | // Configuration with the limit should have the limit value. | |||
| 7923 | configure(config_limit, CONTROL_RESULT_SUCCESS, ""); | |||
| 7924 | ||||
| 7925 | ASSERT_TRUE(ppl = CfgMgr::instance().getStagingCfg()->getConfiguredGlobal("parked-packet-limit"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(ppl = CfgMgr::instance ().getStagingCfg()->getConfiguredGlobal("parked-packet-limit" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7925, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "ppl = CfgMgr::instance().getStagingCfg()->getConfiguredGlobal(\"parked-packet-limit\")" , "false", "true") .c_str()) = ::testing::Message(); | |||
| 7926 | EXPECT_EQ(777, ppl->intValue())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("777", "ppl->intValue()" , 777, ppl->intValue()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7926, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 7927 | ||||
| 7928 | // Make sure an invalid limit fails to parse. | |||
| 7929 | ASSERT_THROW(parseDHCP4(bad_limit), std::exception)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { parseDHCP4(bad_limit); } else static_assert(true, ""); } catch (std::exception const& ) { gtest_caught_expected = true; } catch (typename std::conditional < std::is_same<typename std::remove_cv<typename std:: remove_reference< std::exception>::type>::type, std:: exception>::value, const ::testing::internal::NeverThrown& , const std::exception&>::type e) { gtest_msg.value = "Expected: " "parseDHCP4(bad_limit)" " throws an exception of type " "std::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_7929; } catch (...) { gtest_msg.value = "Expected: " "parseDHCP4(bad_limit)" " throws an exception of type " "std::exception" ".\n Actual: it throws a different type."; goto gtest_label_testthrow_7929; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "parseDHCP4(bad_limit)" " throws an exception of type " "std::exception" ".\n Actual: it throws nothing."; goto gtest_label_testthrow_7929 ; } } else gtest_label_testthrow_7929 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7929, gtest_msg.value.c_str()) = ::testing::Message(); | |||
| 7930 | } | |||
| 7931 | ||||
| 7932 | // This test checks that ddns-conflict-resolution-mode value can be specified at | |||
| 7933 | // global and subnet levels. | |||
| 7934 | TEST_F(Dhcp4ParserTest, storeDdnsConflictResolutionMode)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("storeDdnsConflictResolutionMode") > 1, "test_name must not be empty"); class Dhcp4ParserTest_storeDdnsConflictResolutionMode_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_storeDdnsConflictResolutionMode_Test () = default; ~Dhcp4ParserTest_storeDdnsConflictResolutionMode_Test () override = default; Dhcp4ParserTest_storeDdnsConflictResolutionMode_Test (const Dhcp4ParserTest_storeDdnsConflictResolutionMode_Test & ) = delete; Dhcp4ParserTest_storeDdnsConflictResolutionMode_Test & operator=( const Dhcp4ParserTest_storeDdnsConflictResolutionMode_Test &) = delete; Dhcp4ParserTest_storeDdnsConflictResolutionMode_Test (Dhcp4ParserTest_storeDdnsConflictResolutionMode_Test && ) noexcept = delete; Dhcp4ParserTest_storeDdnsConflictResolutionMode_Test & operator=( Dhcp4ParserTest_storeDdnsConflictResolutionMode_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_storeDdnsConflictResolutionMode_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "storeDdnsConflictResolutionMode", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7934), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7934), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7934), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_storeDdnsConflictResolutionMode_Test >); void Dhcp4ParserTest_storeDdnsConflictResolutionMode_Test ::TestBody() { | |||
| 7935 | std::string config = "{ " + genIfaceConfig() + "," | |||
| 7936 | "\"rebind-timer\": 2000, " | |||
| 7937 | "\"renew-timer\": 1000, " | |||
| 7938 | "\"subnet4\": [ " | |||
| 7939 | "{" | |||
| 7940 | " \"id\": 1," | |||
| 7941 | " \"pools\": [ { \"pool\": \"192.0.2.1 - 192.0.2.100\" } ]," | |||
| 7942 | " \"ddns-conflict-resolution-mode\": \"check-with-dhcid\"," | |||
| 7943 | " \"subnet\": \"192.0.2.0/24\"" | |||
| 7944 | "}," | |||
| 7945 | "{" | |||
| 7946 | " \"id\": 2," | |||
| 7947 | " \"pools\": [ { \"pool\": \"192.0.3.1 - 192.0.3.100\" } ]," | |||
| 7948 | " \"ddns-conflict-resolution-mode\": \"check-exists-with-dhcid\"," | |||
| 7949 | " \"subnet\": \"192.0.3.0/24\"" | |||
| 7950 | "}," | |||
| 7951 | "{" | |||
| 7952 | " \"id\": 3," | |||
| 7953 | " \"pools\": [ { \"pool\": \"192.0.4.1 - 192.0.4.100\" } ]," | |||
| 7954 | " \"ddns-conflict-resolution-mode\": \"no-check-without-dhcid\"," | |||
| 7955 | " \"subnet\": \"192.0.4.0/24\"" | |||
| 7956 | "}," | |||
| 7957 | "{" | |||
| 7958 | " \"id\": 4," | |||
| 7959 | " \"pools\": [ { \"pool\": \"192.0.5.1 - 192.0.5.100\" } ]," | |||
| 7960 | " \"ddns-conflict-resolution-mode\": \"no-check-with-dhcid\"," | |||
| 7961 | " \"subnet\": \"192.0.5.0/24\"" | |||
| 7962 | "}," | |||
| 7963 | "{" | |||
| 7964 | " \"id\": 5," | |||
| 7965 | " \"pools\": [ { \"pool\": \"192.0.6.1 - 192.0.6.100\" } ]," | |||
| 7966 | " \"subnet\": \"192.0.6.0/24\"" | |||
| 7967 | "} ]," | |||
| 7968 | "\"valid-lifetime\": 4000," | |||
| 7969 | "\"ddns-conflict-resolution-mode\": \"no-check-with-dhcid\" }"; | |||
| 7970 | ||||
| 7971 | ConstElementPtr json; | |||
| 7972 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_7972 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_7972 ; } } else gtest_label_testnothrow_7972 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7972, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 7973 | extractConfig(config); | |||
| 7974 | ||||
| 7975 | ConstElementPtr status; | |||
| 7976 | ASSERT_NO_THROW(status = configureDhcp4Server(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = configureDhcp4Server(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_7976; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_7976; } } else gtest_label_testnothrow_7976 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7976, ("Expected: " "status = configureDhcp4Server(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 7977 | checkResult(status, 0); | |||
| 7978 | ||||
| 7979 | // Check global value. | |||
| 7980 | checkGlobal("ddns-conflict-resolution-mode", "no-check-with-dhcid"); | |||
| 7981 | ||||
| 7982 | // Check values for all the subnets. | |||
| 7983 | std::string expectedValues[] = { | |||
| 7984 | "check-with-dhcid", | |||
| 7985 | "check-exists-with-dhcid", | |||
| 7986 | "no-check-without-dhcid", | |||
| 7987 | "no-check-with-dhcid", | |||
| 7988 | "no-check-with-dhcid" | |||
| 7989 | }; | |||
| 7990 | CfgSubnets4Ptr cfg = CfgMgr::instance().getStagingCfg()->getCfgSubnets4(); | |||
| 7991 | char addr[10]; | |||
| 7992 | ConstSubnet4Ptr subnet1; | |||
| 7993 | for (int i = 0; i < 5; i++) { | |||
| 7994 | snprintf(addr, sizeof(addr), "192.0.%d.1", i+2); | |||
| 7995 | subnet1 = cfg->selectSubnet(IOAddress(addr)); | |||
| 7996 | ASSERT_TRUE(subnet1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet1)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 7996, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet1", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 7997 | // Reset the fetch global function to staging (vs current) config. | |||
| 7998 | Subnet4Ptr mutable_subnet1 = boost::const_pointer_cast<Subnet4>(subnet1); | |||
| 7999 | mutable_subnet1->setFetchGlobalsFn([]() -> ConstCfgGlobalsPtr { | |||
| 8000 | return (CfgMgr::instance().getStagingCfg()->getConfiguredGlobals()); | |||
| 8001 | }); | |||
| 8002 | EXPECT_EQ(expectedValues[i], subnet1->getDdnsConflictResolutionMode().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("expectedValues[i]" , "subnet1->getDdnsConflictResolutionMode().get()", expectedValues [i], subnet1->getDdnsConflictResolutionMode().get()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8002, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8003 | } | |||
| 8004 | } | |||
| 8005 | ||||
| 8006 | // This test verifies that class tagging can occur at any scope. | |||
| 8007 | TEST_F(Dhcp4ParserTest, classTagging)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("classTagging") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_classTagging_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_classTagging_Test() = default; ~Dhcp4ParserTest_classTagging_Test () override = default; Dhcp4ParserTest_classTagging_Test (const Dhcp4ParserTest_classTagging_Test &) = delete; Dhcp4ParserTest_classTagging_Test & operator=( const Dhcp4ParserTest_classTagging_Test & ) = delete; Dhcp4ParserTest_classTagging_Test (Dhcp4ParserTest_classTagging_Test &&) noexcept = delete; Dhcp4ParserTest_classTagging_Test & operator=( Dhcp4ParserTest_classTagging_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_classTagging_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "classTagging", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8007 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8007), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8007), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_classTagging_Test >); void Dhcp4ParserTest_classTagging_Test::TestBody() { | |||
| 8008 | std::string config = "{ " + genIfaceConfig() + "," | |||
| 8009 | R"^( | |||
| 8010 | "option-data": [{ | |||
| 8011 | "name": "domain-name", | |||
| 8012 | "data": "example.com", | |||
| 8013 | "client-classes": [ "in-global" ] | |||
| 8014 | }], | |||
| 8015 | "valid-lifetime": 4000, | |||
| 8016 | "rebind-timer": 2000, | |||
| 8017 | "renew-timer": 1000, | |||
| 8018 | "shared-networks": [{ | |||
| 8019 | "name": "foo", | |||
| 8020 | "subnet4": [{ | |||
| 8021 | "id": 1, | |||
| 8022 | "subnet": "192.0.2.0/24", | |||
| 8023 | "option-data": [{ | |||
| 8024 | "name": "domain-name", | |||
| 8025 | "data": "example.com", | |||
| 8026 | "client-classes": [ "in-subnet" ] | |||
| 8027 | }], | |||
| 8028 | "pools": [{ | |||
| 8029 | "pool": "192.0.2.0/28", | |||
| 8030 | "option-data": [{ | |||
| 8031 | "name": "domain-name", | |||
| 8032 | "data": "example.com", | |||
| 8033 | "client-classes": [ "in-pool" ] | |||
| 8034 | }] | |||
| 8035 | }], | |||
| 8036 | "reservations": [{ | |||
| 8037 | "hw-address": "AA:BB:CC:DD:EE:FF", | |||
| 8038 | "option-data": [{ | |||
| 8039 | "name": "domain-name", | |||
| 8040 | "data": "example.com", | |||
| 8041 | "client-classes": [ "in-reservation" ] | |||
| 8042 | }] | |||
| 8043 | }] | |||
| 8044 | }], | |||
| 8045 | "option-data": [{ | |||
| 8046 | "name": "domain-name", | |||
| 8047 | "data": "example.com", | |||
| 8048 | "client-classes": [ "in-network" ] | |||
| 8049 | }] | |||
| 8050 | }], | |||
| 8051 | "client-classes": [{ | |||
| 8052 | "name": "foo", | |||
| 8053 | "option-data": [{ | |||
| 8054 | "name": "domain-name", | |||
| 8055 | "data": "example.com", | |||
| 8056 | "client-classes": [ "in-class" ] | |||
| 8057 | }] | |||
| 8058 | }] | |||
| 8059 | })^"; | |||
| 8060 | ||||
| 8061 | ConstElementPtr json; | |||
| 8062 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_8062 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8062 ; } } else gtest_label_testnothrow_8062 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8062, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 8063 | extractConfig(config); | |||
| 8064 | ||||
| 8065 | ConstElementPtr status; | |||
| 8066 | ASSERT_NO_THROW(status = configureDhcp4Server(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = configureDhcp4Server(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_8066; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8066; } } else gtest_label_testnothrow_8066 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8066, ("Expected: " "status = configureDhcp4Server(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 8067 | checkResult(status, 0); | |||
| 8068 | } | |||
| 8069 | ||||
| 8070 | // This test verifies that duplicates in option-data.client-classes | |||
| 8071 | // are ignored and do not affect class order. | |||
| 8072 | TEST_F(Dhcp4ParserTest, optionClientClassesDuplicateCheck)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("optionClientClassesDuplicateCheck") > 1, "test_name must not be empty"); class Dhcp4ParserTest_optionClientClassesDuplicateCheck_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_optionClientClassesDuplicateCheck_Test () = default; ~Dhcp4ParserTest_optionClientClassesDuplicateCheck_Test () override = default; Dhcp4ParserTest_optionClientClassesDuplicateCheck_Test (const Dhcp4ParserTest_optionClientClassesDuplicateCheck_Test &) = delete; Dhcp4ParserTest_optionClientClassesDuplicateCheck_Test & operator=( const Dhcp4ParserTest_optionClientClassesDuplicateCheck_Test &) = delete; Dhcp4ParserTest_optionClientClassesDuplicateCheck_Test (Dhcp4ParserTest_optionClientClassesDuplicateCheck_Test && ) noexcept = delete; Dhcp4ParserTest_optionClientClassesDuplicateCheck_Test & operator=( Dhcp4ParserTest_optionClientClassesDuplicateCheck_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_optionClientClassesDuplicateCheck_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "optionClientClassesDuplicateCheck", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8072), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8072), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8072), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_optionClientClassesDuplicateCheck_Test >); void Dhcp4ParserTest_optionClientClassesDuplicateCheck_Test ::TestBody() { | |||
| 8073 | std::string config = "{ " + genIfaceConfig() + "," | |||
| 8074 | R"^( | |||
| 8075 | "option-data": [{ | |||
| 8076 | "name": "domain-name", | |||
| 8077 | "data": "example.com", | |||
| 8078 | "client-classes": [ "foo", "bar", "foo", "bar" ] | |||
| 8079 | }], | |||
| 8080 | "rebind-timer": 2000, | |||
| 8081 | "renew-timer": 1000, | |||
| 8082 | "subnet4": [], | |||
| 8083 | "valid-lifetime": 400 | |||
| 8084 | })^"; | |||
| 8085 | ||||
| 8086 | ConstElementPtr json; | |||
| 8087 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_8087 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8087 ; } } else gtest_label_testnothrow_8087 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8087, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 8088 | extractConfig(config); | |||
| 8089 | ||||
| 8090 | ConstElementPtr status; | |||
| 8091 | ASSERT_NO_THROW(status = configureDhcp4Server(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = configureDhcp4Server(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_8091; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8091; } } else gtest_label_testnothrow_8091 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8091, ("Expected: " "status = configureDhcp4Server(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 8092 | checkResult(status, 0); | |||
| 8093 | ||||
| 8094 | CfgOptionPtr cfg = CfgMgr::instance().getStagingCfg()->getCfgOption(); | |||
| 8095 | const auto desc = cfg->get(DHCP4_OPTION_SPACE"dhcp4", DHO_DOMAIN_NAME); | |||
| 8096 | ASSERT_TRUE(desc.option_)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(desc.option_)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8096, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "desc.option_", "false", "true") .c_str()) = ::testing::Message (); | |||
| 8097 | ASSERT_EQ(desc.client_classes_.size(), 2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("desc.client_classes_.size()" , "2", desc.client_classes_.size(), 2))) ; else return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8097 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8098 | auto cclasses = desc.client_classes_.begin(); | |||
| 8099 | EXPECT_EQ(*cclasses, "foo")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("*cclasses" , "\"foo\"", *cclasses, "foo"))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8099, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8100 | ++cclasses; | |||
| 8101 | EXPECT_EQ(*cclasses, "bar")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("*cclasses" , "\"bar\"", *cclasses, "bar"))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8101, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8102 | } | |||
| 8103 | ||||
| 8104 | // This test verifies that deprecated require-client-classes | |||
| 8105 | // gets handled properly. | |||
| 8106 | TEST_F(Dhcp4ParserTest, deprecatedRequireClientClassesCheck)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("deprecatedRequireClientClassesCheck" ) > 1, "test_name must not be empty"); class Dhcp4ParserTest_deprecatedRequireClientClassesCheck_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_deprecatedRequireClientClassesCheck_Test () = default; ~Dhcp4ParserTest_deprecatedRequireClientClassesCheck_Test () override = default; Dhcp4ParserTest_deprecatedRequireClientClassesCheck_Test (const Dhcp4ParserTest_deprecatedRequireClientClassesCheck_Test &) = delete; Dhcp4ParserTest_deprecatedRequireClientClassesCheck_Test & operator=( const Dhcp4ParserTest_deprecatedRequireClientClassesCheck_Test &) = delete; Dhcp4ParserTest_deprecatedRequireClientClassesCheck_Test (Dhcp4ParserTest_deprecatedRequireClientClassesCheck_Test && ) noexcept = delete; Dhcp4ParserTest_deprecatedRequireClientClassesCheck_Test & operator=( Dhcp4ParserTest_deprecatedRequireClientClassesCheck_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_deprecatedRequireClientClassesCheck_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "deprecatedRequireClientClassesCheck", nullptr, nullptr, :: testing::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8106), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8106), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8106), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_deprecatedRequireClientClassesCheck_Test >); void Dhcp4ParserTest_deprecatedRequireClientClassesCheck_Test ::TestBody() { | |||
| 8107 | // Verify that require-client-classes gets translated | |||
| 8108 | // to evaluate-additional-classes. | |||
| 8109 | std::string config = "{ " + genIfaceConfig() + "," | |||
| 8110 | R"^( | |||
| 8111 | "rebind-timer": 2000, | |||
| 8112 | "renew-timer": 1000, | |||
| 8113 | "shared-networks":[{ | |||
| 8114 | "name": "net1", | |||
| 8115 | "require-client-classes": [ "one" ], | |||
| 8116 | "subnet4": [{ | |||
| 8117 | "require-client-classes": [ "two" ], | |||
| 8118 | "pools": [{ | |||
| 8119 | "pool": "192.0.2.0/28", | |||
| 8120 | "require-client-classes": [ "three" ] | |||
| 8121 | }], | |||
| 8122 | "id": 1, | |||
| 8123 | "subnet": "192.0.2.0/24" | |||
| 8124 | }], | |||
| 8125 | }], | |||
| 8126 | "valid-lifetime": 400 | |||
| 8127 | })^"; | |||
| 8128 | ||||
| 8129 | ConstElementPtr json; | |||
| 8130 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_8130 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8130 ; } } else gtest_label_testnothrow_8130 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8130, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 8131 | extractConfig(config); | |||
| 8132 | ||||
| 8133 | ConstElementPtr status; | |||
| 8134 | ASSERT_NO_THROW(status = configureDhcp4Server(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = configureDhcp4Server(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_8134; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8134; } } else gtest_label_testnothrow_8134 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8134, ("Expected: " "status = configureDhcp4Server(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 8135 | checkResult(status, 0); | |||
| 8136 | ||||
| 8137 | SharedNetwork4Ptr network = CfgMgr::instance().getStagingCfg()-> | |||
| 8138 | getCfgSharedNetworks4()->getByName("net1"); | |||
| 8139 | ASSERT_TRUE(network)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(network)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8139, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "network", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 8140 | ||||
| 8141 | auto& net_class_list = network->getAdditionalClasses(); | |||
| 8142 | EXPECT_EQ(1, net_class_list.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "net_class_list.size()" , 1, net_class_list.size()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8142, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8143 | auto cclasses = net_class_list.begin(); | |||
| 8144 | EXPECT_EQ(*cclasses, "one")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("*cclasses" , "\"one\"", *cclasses, "one"))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8144, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8145 | ||||
| 8146 | ConstSubnet4Ptr subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 8147 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.2.0")); | |||
| 8148 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8148, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 8149 | ||||
| 8150 | auto& sub_class_list = subnet->getAdditionalClasses(); | |||
| 8151 | EXPECT_EQ(1, sub_class_list.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "sub_class_list.size()" , 1, sub_class_list.size()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8151, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8152 | cclasses = sub_class_list.begin(); | |||
| 8153 | EXPECT_EQ(*cclasses, "two")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("*cclasses" , "\"two\"", *cclasses, "two"))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8153, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8154 | ||||
| 8155 | PoolPtr pool = subnet->getPool(Lease::TYPE_V4, IOAddress("192.0.2.0"), false); | |||
| 8156 | ASSERT_TRUE(pool)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8156 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool", "false", "true") .c_str()) = ::testing::Message(); | |||
| 8157 | ||||
| 8158 | auto& pool_class_list = pool->getAdditionalClasses(); | |||
| 8159 | EXPECT_EQ(1, pool_class_list.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "pool_class_list.size()" , 1, pool_class_list.size()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8159, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8160 | cclasses = pool_class_list.begin(); | |||
| 8161 | EXPECT_EQ(*cclasses, "three")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("*cclasses" , "\"three\"", *cclasses, "three"))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8161, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8162 | ||||
| 8163 | // Now verify that users cannot specify both. | |||
| 8164 | config = "{ " + genIfaceConfig() + "," | |||
| 8165 | R"^( | |||
| 8166 | "rebind-timer": 2000, | |||
| 8167 | "renew-timer": 1000, | |||
| 8168 | "subnet4": [{ | |||
| 8169 | "require-client-classes": [ "foo" ], | |||
| 8170 | "evaluate-additional-classes": [ "foo" ], | |||
| 8171 | "pools": [{ "pool": "192.0.2.0/28" }], | |||
| 8172 | "id": 1, | |||
| 8173 | "subnet": "192.0.2.0/24" | |||
| 8174 | }], | |||
| 8175 | "valid-lifetime": 400 | |||
| 8176 | })^"; | |||
| 8177 | ||||
| 8178 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_8178 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8178 ; } } else gtest_label_testnothrow_8178 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8178, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 8179 | ||||
| 8180 | ASSERT_NO_THROW(status = configureDhcp4Server(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = configureDhcp4Server(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_8180; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8180; } } else gtest_label_testnothrow_8180 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8180, ("Expected: " "status = configureDhcp4Server(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 8181 | checkResult(status, 1, | |||
| 8182 | "subnet configuration failed: cannot specify both 'require-client-classes'" | |||
| 8183 | " and 'evaluate-additional-classes'. Use only the latter."); | |||
| 8184 | } | |||
| 8185 | ||||
| 8186 | // This test verifies that deprecated only-if-required | |||
| 8187 | // gets handled properly. | |||
| 8188 | TEST_F(Dhcp4ParserTest, deprecatedOnlyIfRequiredCheck)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("deprecatedOnlyIfRequiredCheck") > 1, "test_name must not be empty"); class Dhcp4ParserTest_deprecatedOnlyIfRequiredCheck_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_deprecatedOnlyIfRequiredCheck_Test () = default; ~Dhcp4ParserTest_deprecatedOnlyIfRequiredCheck_Test () override = default; Dhcp4ParserTest_deprecatedOnlyIfRequiredCheck_Test (const Dhcp4ParserTest_deprecatedOnlyIfRequiredCheck_Test & ) = delete; Dhcp4ParserTest_deprecatedOnlyIfRequiredCheck_Test & operator=( const Dhcp4ParserTest_deprecatedOnlyIfRequiredCheck_Test &) = delete; Dhcp4ParserTest_deprecatedOnlyIfRequiredCheck_Test (Dhcp4ParserTest_deprecatedOnlyIfRequiredCheck_Test && ) noexcept = delete; Dhcp4ParserTest_deprecatedOnlyIfRequiredCheck_Test & operator=( Dhcp4ParserTest_deprecatedOnlyIfRequiredCheck_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_deprecatedOnlyIfRequiredCheck_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "deprecatedOnlyIfRequiredCheck", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8188), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8188), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8188), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_deprecatedOnlyIfRequiredCheck_Test >); void Dhcp4ParserTest_deprecatedOnlyIfRequiredCheck_Test ::TestBody() { | |||
| 8189 | // Verifies that only-if-required gets translated | |||
| 8190 | // to only-in-additional-list. | |||
| 8191 | std::string config = "{ " + genIfaceConfig() + "," | |||
| 8192 | R"^( | |||
| 8193 | "rebind-timer": 2000, | |||
| 8194 | "renew-timer": 1000, | |||
| 8195 | "client-classes": [{ | |||
| 8196 | "name": "foo", | |||
| 8197 | "only-if-required": true | |||
| 8198 | }], | |||
| 8199 | "subnet4": [ ], | |||
| 8200 | "valid-lifetime": 400 | |||
| 8201 | })^"; | |||
| 8202 | ||||
| 8203 | ConstElementPtr json; | |||
| 8204 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_8204 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8204 ; } } else gtest_label_testnothrow_8204 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8204, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 8205 | extractConfig(config); | |||
| 8206 | ||||
| 8207 | ConstElementPtr status; | |||
| 8208 | ASSERT_NO_THROW(status = configureDhcp4Server(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = configureDhcp4Server(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_8208; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8208; } } else gtest_label_testnothrow_8208 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8208, ("Expected: " "status = configureDhcp4Server(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 8209 | checkResult(status, 0); | |||
| 8210 | ||||
| 8211 | auto dictionary = CfgMgr::instance().getStagingCfg()->getClientClassDictionary(); | |||
| 8212 | ASSERT_TRUE(dictionary)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(dictionary)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8212, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "dictionary", "false", "true") .c_str()) = ::testing::Message (); | |||
| 8213 | EXPECT_EQ(1, dictionary->getClasses()->size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "dictionary->getClasses()->size()" , 1, dictionary->getClasses()->size()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8213 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8214 | ||||
| 8215 | ClientClassDefPtr class_def = dictionary->findClass("foo"); | |||
| 8216 | ASSERT_TRUE(class_def)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(class_def)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8216, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "class_def", "false", "true") .c_str()) = ::testing::Message (); | |||
| 8217 | EXPECT_TRUE(class_def->getAdditional())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(class_def->getAdditional ())) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8217, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "class_def->getAdditional()", "false", "true") .c_str()) = ::testing::Message(); | |||
| 8218 | ||||
| 8219 | // Now verify that users cannot specify both. | |||
| 8220 | config = "{ " + genIfaceConfig() + "," | |||
| 8221 | R"^( | |||
| 8222 | "rebind-timer": 2000, | |||
| 8223 | "renew-timer": 1000, | |||
| 8224 | "client-classes": [{ | |||
| 8225 | "name": "foo", | |||
| 8226 | "only-if-required": true, | |||
| 8227 | "only-in-additional-list": true | |||
| 8228 | }], | |||
| 8229 | "subnet4": [ ], | |||
| 8230 | "valid-lifetime": 400 | |||
| 8231 | })^"; | |||
| 8232 | ||||
| 8233 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_8233 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8233 ; } } else gtest_label_testnothrow_8233 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8233, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 8234 | ||||
| 8235 | ASSERT_NO_THROW(status = configureDhcp4Server(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = configureDhcp4Server(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_8235; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8235; } } else gtest_label_testnothrow_8235 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8235, ("Expected: " "status = configureDhcp4Server(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 8236 | checkResult(status, 1, | |||
| 8237 | "cannot specify both 'only-if-required' and" | |||
| 8238 | " 'only-in-additional-list'. Use only the latter."); | |||
| 8239 | } | |||
| 8240 | ||||
| 8241 | // This test verifies that deprecated client-class | |||
| 8242 | // gets handled properly. | |||
| 8243 | TEST_F(Dhcp4ParserTest, deprecatedClientClassesCheck)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("deprecatedClientClassesCheck") > 1 , "test_name must not be empty"); class Dhcp4ParserTest_deprecatedClientClassesCheck_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_deprecatedClientClassesCheck_Test () = default; ~Dhcp4ParserTest_deprecatedClientClassesCheck_Test () override = default; Dhcp4ParserTest_deprecatedClientClassesCheck_Test (const Dhcp4ParserTest_deprecatedClientClassesCheck_Test & ) = delete; Dhcp4ParserTest_deprecatedClientClassesCheck_Test & operator=( const Dhcp4ParserTest_deprecatedClientClassesCheck_Test &) = delete; Dhcp4ParserTest_deprecatedClientClassesCheck_Test (Dhcp4ParserTest_deprecatedClientClassesCheck_Test && ) noexcept = delete; Dhcp4ParserTest_deprecatedClientClassesCheck_Test & operator=( Dhcp4ParserTest_deprecatedClientClassesCheck_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_deprecatedClientClassesCheck_Test ::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "deprecatedClientClassesCheck", nullptr, nullptr, ::testing ::internal::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8243), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8243), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8243), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_deprecatedClientClassesCheck_Test >); void Dhcp4ParserTest_deprecatedClientClassesCheck_Test ::TestBody() { | |||
| 8244 | // Verify that require-client-classes gets translated | |||
| 8245 | // to evaluate-additional-classes. | |||
| 8246 | std::string config = "{ " + genIfaceConfig() + "," | |||
| 8247 | R"^( | |||
| 8248 | "rebind-timer": 2000, | |||
| 8249 | "renew-timer": 1000, | |||
| 8250 | "shared-networks":[{ | |||
| 8251 | "name": "net1", | |||
| 8252 | "client-class": "one", | |||
| 8253 | "subnet4": [{ | |||
| 8254 | "client-class": "two", | |||
| 8255 | "pools": [{ | |||
| 8256 | "pool": "192.0.2.0/28", | |||
| 8257 | "client-class": "three" | |||
| 8258 | }], | |||
| 8259 | "id": 1, | |||
| 8260 | "subnet": "192.0.2.0/24" | |||
| 8261 | }], | |||
| 8262 | }], | |||
| 8263 | "valid-lifetime": 400 | |||
| 8264 | })^"; | |||
| 8265 | ||||
| 8266 | ConstElementPtr json; | |||
| 8267 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_8267 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8267 ; } } else gtest_label_testnothrow_8267 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8267, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 8268 | extractConfig(config); | |||
| 8269 | ||||
| 8270 | ConstElementPtr status; | |||
| 8271 | ASSERT_NO_THROW(status = configureDhcp4Server(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = configureDhcp4Server(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_8271; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8271; } } else gtest_label_testnothrow_8271 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8271, ("Expected: " "status = configureDhcp4Server(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 8272 | checkResult(status, 0); | |||
| 8273 | ||||
| 8274 | SharedNetwork4Ptr network = CfgMgr::instance().getStagingCfg()-> | |||
| 8275 | getCfgSharedNetworks4()->getByName("net1"); | |||
| 8276 | ASSERT_TRUE(network)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(network)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8276, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "network", "false", "true") .c_str()) = ::testing::Message( ); | |||
| 8277 | ||||
| 8278 | auto& net_class_list = network->getClientClasses(); | |||
| 8279 | ASSERT_EQ(1, net_class_list.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "net_class_list.size()" , 1, net_class_list.size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8279, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8280 | auto cclasses = net_class_list.begin(); | |||
| 8281 | EXPECT_EQ(*cclasses, "one")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("*cclasses" , "\"one\"", *cclasses, "one"))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8281, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8282 | ||||
| 8283 | auto subnet = CfgMgr::instance().getStagingCfg()-> | |||
| 8284 | getCfgSubnets4()->getBySubnetId(1); | |||
| 8285 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8285, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 8286 | ||||
| 8287 | auto& sub_class_list = subnet->getClientClasses(); | |||
| 8288 | ASSERT_EQ(1, sub_class_list.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "sub_class_list.size()" , 1, sub_class_list.size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8288, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8289 | cclasses = sub_class_list.begin(); | |||
| 8290 | EXPECT_EQ(*cclasses, "two")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("*cclasses" , "\"two\"", *cclasses, "two"))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8290, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8291 | ||||
| 8292 | PoolPtr pool = subnet->getPool(Lease::TYPE_V4, IOAddress("192.0.2.0"), false); | |||
| 8293 | ASSERT_TRUE(pool)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8293 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool", "false", "true") .c_str()) = ::testing::Message(); | |||
| 8294 | ||||
| 8295 | auto& pool_class_list = pool->getClientClasses(); | |||
| 8296 | ASSERT_EQ(1, pool_class_list.size())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("1", "pool_class_list.size()" , 1, pool_class_list.size()))) ; else return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8296, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8297 | cclasses = pool_class_list.begin(); | |||
| 8298 | EXPECT_EQ(*cclasses, "three")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("*cclasses" , "\"three\"", *cclasses, "three"))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8298, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8299 | ||||
| 8300 | // Now verify that users cannot specify both. We don't check all scopes | |||
| 8301 | // as they all use the same function. | |||
| 8302 | config = "{ " + genIfaceConfig() + "," | |||
| 8303 | R"^( | |||
| 8304 | "rebind-timer": 2000, | |||
| 8305 | "renew-timer": 1000, | |||
| 8306 | "subnet4": [{ | |||
| 8307 | "client-class": "foo", | |||
| 8308 | "client-classes": [ "bar" ], | |||
| 8309 | "pools": [{ "pool": "192.0.2.0/28" }], | |||
| 8310 | "id": 1, | |||
| 8311 | "subnet": "192.0.2.0/24" | |||
| 8312 | }], | |||
| 8313 | "valid-lifetime": 400 | |||
| 8314 | })^"; | |||
| 8315 | ||||
| 8316 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_8316 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8316 ; } } else gtest_label_testnothrow_8316 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8316, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 8317 | ||||
| 8318 | ASSERT_NO_THROW(status = configureDhcp4Server(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = configureDhcp4Server(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_8318; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8318; } } else gtest_label_testnothrow_8318 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8318, ("Expected: " "status = configureDhcp4Server(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 8319 | checkResult(status, 1, | |||
| 8320 | "subnet configuration failed: cannot specify both 'client-class'" | |||
| 8321 | " and 'client-classes'. Use only the latter."); | |||
| 8322 | } | |||
| 8323 | ||||
| 8324 | // Verifies ddns-ttl-percent is supported at global, | |||
| 8325 | // shared-network, and subnet scopes. | |||
| 8326 | TEST_F(Dhcp4ParserTest, ddnsTtlPercent)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("ddnsTtlPercent") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_ddnsTtlPercent_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_ddnsTtlPercent_Test() = default; ~ Dhcp4ParserTest_ddnsTtlPercent_Test() override = default; Dhcp4ParserTest_ddnsTtlPercent_Test (const Dhcp4ParserTest_ddnsTtlPercent_Test &) = delete; Dhcp4ParserTest_ddnsTtlPercent_Test & operator=( const Dhcp4ParserTest_ddnsTtlPercent_Test & ) = delete; Dhcp4ParserTest_ddnsTtlPercent_Test (Dhcp4ParserTest_ddnsTtlPercent_Test &&) noexcept = delete; Dhcp4ParserTest_ddnsTtlPercent_Test & operator=( Dhcp4ParserTest_ddnsTtlPercent_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_ddnsTtlPercent_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "ddnsTtlPercent", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8326 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8326), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8326), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_ddnsTtlPercent_Test >); void Dhcp4ParserTest_ddnsTtlPercent_Test::TestBody() { | |||
| 8327 | string config = R"( | |||
| 8328 | { | |||
| 8329 | "ddns-ttl-percent": 0.75, | |||
| 8330 | "valid-lifetime": 4000, | |||
| 8331 | "shared-networks": [{ | |||
| 8332 | "name": "net", | |||
| 8333 | "ddns-ttl-percent": 0.50, | |||
| 8334 | "subnet4": [{ | |||
| 8335 | "id": 1, | |||
| 8336 | "subnet": "10.0.2.0/24", | |||
| 8337 | "ddns-ttl-percent": 0.25 | |||
| 8338 | }], | |||
| 8339 | }] | |||
| 8340 | } | |||
| 8341 | )"; | |||
| 8342 | ||||
| 8343 | ConstElementPtr json; | |||
| 8344 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_8344 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8344 ; } } else gtest_label_testnothrow_8344 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8344, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 8345 | extractConfig(config); | |||
| 8346 | ||||
| 8347 | ConstElementPtr status; | |||
| 8348 | ||||
| 8349 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_8349; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8349; } } else gtest_label_testnothrow_8349 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8349, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 8350 | // returned value should be 0 (success) | |||
| 8351 | checkResult(status, 0); | |||
| 8352 | ||||
| 8353 | // Commit it so global inheritance works. | |||
| 8354 | CfgMgr::instance().commit(); | |||
| 8355 | ||||
| 8356 | ConstSubnet4Ptr subnet = CfgMgr::instance().getCurrentCfg()-> | |||
| 8357 | getCfgSubnets4()->selectSubnet(IOAddress("10.0.2.0")); | |||
| 8358 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8358, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 8359 | ||||
| 8360 | EXPECT_FALSE(subnet->getDdnsTtlPercent(Network::Inheritance::NONE).unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getDdnsTtlPercent (Network::Inheritance::NONE).unspecified()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8360 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getDdnsTtlPercent(Network::Inheritance::NONE).unspecified()" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 8361 | EXPECT_EQ(0.25, subnet->getDdnsTtlPercent(Network::Inheritance::NONE).get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0.25", "subnet->getDdnsTtlPercent(Network::Inheritance::NONE).get()" , 0.25, subnet->getDdnsTtlPercent(Network::Inheritance::NONE ).get()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8361, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8362 | ||||
| 8363 | EXPECT_FALSE(subnet->getDdnsTtlPercent(Network::Inheritance::PARENT_NETWORK).unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getDdnsTtlPercent (Network::Inheritance::PARENT_NETWORK).unspecified()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8363, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getDdnsTtlPercent(Network::Inheritance::PARENT_NETWORK).unspecified()" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 8364 | EXPECT_EQ(0.50, subnet->getDdnsTtlPercent(Network::Inheritance::PARENT_NETWORK).get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0.50", "subnet->getDdnsTtlPercent(Network::Inheritance::PARENT_NETWORK).get()" , 0.50, subnet->getDdnsTtlPercent(Network::Inheritance::PARENT_NETWORK ).get()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8364, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8365 | ||||
| 8366 | EXPECT_FALSE(subnet->getDdnsTtlPercent(Network::Inheritance::GLOBAL).unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getDdnsTtlPercent (Network::Inheritance::GLOBAL).unspecified()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8366 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getDdnsTtlPercent(Network::Inheritance::GLOBAL).unspecified()" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 8367 | EXPECT_EQ(0.75, subnet->getDdnsTtlPercent(Network::Inheritance::GLOBAL).get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("0.75", "subnet->getDdnsTtlPercent(Network::Inheritance::GLOBAL).get()" , 0.75, subnet->getDdnsTtlPercent(Network::Inheritance::GLOBAL ).get()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8367, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8368 | } | |||
| 8369 | ||||
| 8370 | // Verifies ddns-ttl is supported at global, | |||
| 8371 | // shared-network, and subnet scopes. | |||
| 8372 | TEST_F(Dhcp4ParserTest, ddnsTtl)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("ddnsTtl") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_ddnsTtl_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_ddnsTtl_Test() = default; ~Dhcp4ParserTest_ddnsTtl_Test () override = default; Dhcp4ParserTest_ddnsTtl_Test (const Dhcp4ParserTest_ddnsTtl_Test &) = delete; Dhcp4ParserTest_ddnsTtl_Test & operator =( const Dhcp4ParserTest_ddnsTtl_Test &) = delete; Dhcp4ParserTest_ddnsTtl_Test (Dhcp4ParserTest_ddnsTtl_Test &&) noexcept = delete; Dhcp4ParserTest_ddnsTtl_Test & operator=( Dhcp4ParserTest_ddnsTtl_Test &&) noexcept = delete; private: void TestBody() override ; [[maybe_unused]] static ::testing::TestInfo* const test_info_ ; }; ::testing::TestInfo* const Dhcp4ParserTest_ddnsTtl_Test:: test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "ddnsTtl", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8372 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8372), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8372), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_ddnsTtl_Test >); void Dhcp4ParserTest_ddnsTtl_Test::TestBody() { | |||
| 8373 | string config = R"( | |||
| 8374 | { | |||
| 8375 | "ddns-ttl": 750, | |||
| 8376 | "valid-lifetime": 4000, | |||
| 8377 | "shared-networks": [{ | |||
| 8378 | "name": "net", | |||
| 8379 | "ddns-ttl": 500, | |||
| 8380 | "subnet4": [{ | |||
| 8381 | "id": 1, | |||
| 8382 | "subnet": "10.0.2.0/24", | |||
| 8383 | "ddns-ttl": 250 | |||
| 8384 | }], | |||
| 8385 | }] | |||
| 8386 | } | |||
| 8387 | )"; | |||
| 8388 | ||||
| 8389 | ConstElementPtr json; | |||
| 8390 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_8390 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8390 ; } } else gtest_label_testnothrow_8390 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8390, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 8391 | extractConfig(config); | |||
| 8392 | ||||
| 8393 | ConstElementPtr status; | |||
| 8394 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_8394; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8394; } } else gtest_label_testnothrow_8394 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8394, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 8395 | ||||
| 8396 | // returned value should be 0 (success) | |||
| 8397 | checkResult(status, 0); | |||
| 8398 | ||||
| 8399 | // Commit it so global inheritance works. | |||
| 8400 | CfgMgr::instance().commit(); | |||
| 8401 | ||||
| 8402 | ConstSubnet4Ptr subnet = CfgMgr::instance().getCurrentCfg()-> | |||
| 8403 | getCfgSubnets4()->selectSubnet(IOAddress("10.0.2.0")); | |||
| 8404 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8404, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 8405 | ||||
| 8406 | EXPECT_FALSE(subnet->getDdnsTtl(Network::Inheritance::NONE).unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getDdnsTtl (Network::Inheritance::NONE).unspecified()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8406 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getDdnsTtl(Network::Inheritance::NONE).unspecified()" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 8407 | EXPECT_EQ(250, subnet->getDdnsTtl(Network::Inheritance::NONE).get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("250", "subnet->getDdnsTtl(Network::Inheritance::NONE).get()" , 250, subnet->getDdnsTtl(Network::Inheritance::NONE).get( )))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8407, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8408 | ||||
| 8409 | EXPECT_FALSE(subnet->getDdnsTtl(Network::Inheritance::PARENT_NETWORK).unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getDdnsTtl (Network::Inheritance::PARENT_NETWORK).unspecified()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8409, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getDdnsTtl(Network::Inheritance::PARENT_NETWORK).unspecified()" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 8410 | EXPECT_EQ(500, subnet->getDdnsTtl(Network::Inheritance::PARENT_NETWORK).get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("500", "subnet->getDdnsTtl(Network::Inheritance::PARENT_NETWORK).get()" , 500, subnet->getDdnsTtl(Network::Inheritance::PARENT_NETWORK ).get()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8410, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8411 | ||||
| 8412 | EXPECT_FALSE(subnet->getDdnsTtl(Network::Inheritance::GLOBAL).unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getDdnsTtl (Network::Inheritance::GLOBAL).unspecified()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8412 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getDdnsTtl(Network::Inheritance::GLOBAL).unspecified()" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 8413 | EXPECT_EQ(750, subnet->getDdnsTtl(Network::Inheritance::GLOBAL).get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("750", "subnet->getDdnsTtl(Network::Inheritance::GLOBAL).get()" , 750, subnet->getDdnsTtl(Network::Inheritance::GLOBAL).get ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8413, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8414 | } | |||
| 8415 | ||||
| 8416 | // Verifies ddns-ttl-min is supported at global, | |||
| 8417 | // shared-network, and subnet scopes. | |||
| 8418 | TEST_F(Dhcp4ParserTest, ddnsTtlMin)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("ddnsTtlMin") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_ddnsTtlMin_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_ddnsTtlMin_Test() = default; ~Dhcp4ParserTest_ddnsTtlMin_Test () override = default; Dhcp4ParserTest_ddnsTtlMin_Test (const Dhcp4ParserTest_ddnsTtlMin_Test &) = delete; Dhcp4ParserTest_ddnsTtlMin_Test & operator=( const Dhcp4ParserTest_ddnsTtlMin_Test & ) = delete; Dhcp4ParserTest_ddnsTtlMin_Test (Dhcp4ParserTest_ddnsTtlMin_Test &&) noexcept = delete; Dhcp4ParserTest_ddnsTtlMin_Test & operator=( Dhcp4ParserTest_ddnsTtlMin_Test &&) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_ddnsTtlMin_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "ddnsTtlMin", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8418 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8418), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8418), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_ddnsTtlMin_Test >); void Dhcp4ParserTest_ddnsTtlMin_Test::TestBody() { | |||
| 8419 | string config = R"( | |||
| 8420 | { | |||
| 8421 | "ddns-ttl-min": 750, | |||
| 8422 | "valid-lifetime": 4000, | |||
| 8423 | "shared-networks": [{ | |||
| 8424 | "name": "net", | |||
| 8425 | "ddns-ttl-min": 500, | |||
| 8426 | "subnet4": [{ | |||
| 8427 | "id": 1, | |||
| 8428 | "subnet": "10.0.2.0/24", | |||
| 8429 | "ddns-ttl-min": 250 | |||
| 8430 | }], | |||
| 8431 | }] | |||
| 8432 | } | |||
| 8433 | )"; | |||
| 8434 | ||||
| 8435 | ConstElementPtr json; | |||
| 8436 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_8436 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8436 ; } } else gtest_label_testnothrow_8436 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8436, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 8437 | extractConfig(config); | |||
| 8438 | ||||
| 8439 | ConstElementPtr status; | |||
| 8440 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_8440; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8440; } } else gtest_label_testnothrow_8440 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8440, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 8441 | ||||
| 8442 | // returned value should be 0 (success) | |||
| 8443 | checkResult(status, 0); | |||
| 8444 | ||||
| 8445 | // Commit it so global inheritance works. | |||
| 8446 | CfgMgr::instance().commit(); | |||
| 8447 | ||||
| 8448 | ConstSubnet4Ptr subnet = CfgMgr::instance().getCurrentCfg()-> | |||
| 8449 | getCfgSubnets4()->selectSubnet(IOAddress("10.0.2.0")); | |||
| 8450 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8450, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 8451 | ||||
| 8452 | EXPECT_FALSE(subnet->getDdnsTtlMin(Network::Inheritance::NONE).unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getDdnsTtlMin (Network::Inheritance::NONE).unspecified()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8452 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getDdnsTtlMin(Network::Inheritance::NONE).unspecified()" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 8453 | EXPECT_EQ(250, subnet->getDdnsTtlMin(Network::Inheritance::NONE).get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("250", "subnet->getDdnsTtlMin(Network::Inheritance::NONE).get()" , 250, subnet->getDdnsTtlMin(Network::Inheritance::NONE).get ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8453, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8454 | ||||
| 8455 | EXPECT_FALSE(subnet->getDdnsTtlMin(Network::Inheritance::PARENT_NETWORK).unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getDdnsTtlMin (Network::Inheritance::PARENT_NETWORK).unspecified()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8455, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getDdnsTtlMin(Network::Inheritance::PARENT_NETWORK).unspecified()" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 8456 | EXPECT_EQ(500, subnet->getDdnsTtlMin(Network::Inheritance::PARENT_NETWORK).get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("500", "subnet->getDdnsTtlMin(Network::Inheritance::PARENT_NETWORK).get()" , 500, subnet->getDdnsTtlMin(Network::Inheritance::PARENT_NETWORK ).get()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8456, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8457 | ||||
| 8458 | EXPECT_FALSE(subnet->getDdnsTtlMin(Network::Inheritance::GLOBAL).unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getDdnsTtlMin (Network::Inheritance::GLOBAL).unspecified()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8458 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getDdnsTtlMin(Network::Inheritance::GLOBAL).unspecified()" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 8459 | EXPECT_EQ(750, subnet->getDdnsTtlMin(Network::Inheritance::GLOBAL).get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("750", "subnet->getDdnsTtlMin(Network::Inheritance::GLOBAL).get()" , 750, subnet->getDdnsTtlMin(Network::Inheritance::GLOBAL) .get()))) ; else ::testing::internal::AssertHelper(::testing:: TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8459, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8460 | } | |||
| 8461 | ||||
| 8462 | // Verifies ddns-ttl-max is supported at global, | |||
| 8463 | // shared-network, and subnet scopes. | |||
| 8464 | TEST_F(Dhcp4ParserTest, ddnsTtlMax)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("ddnsTtlMax") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_ddnsTtlMax_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_ddnsTtlMax_Test() = default; ~Dhcp4ParserTest_ddnsTtlMax_Test () override = default; Dhcp4ParserTest_ddnsTtlMax_Test (const Dhcp4ParserTest_ddnsTtlMax_Test &) = delete; Dhcp4ParserTest_ddnsTtlMax_Test & operator=( const Dhcp4ParserTest_ddnsTtlMax_Test & ) = delete; Dhcp4ParserTest_ddnsTtlMax_Test (Dhcp4ParserTest_ddnsTtlMax_Test &&) noexcept = delete; Dhcp4ParserTest_ddnsTtlMax_Test & operator=( Dhcp4ParserTest_ddnsTtlMax_Test &&) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_ddnsTtlMax_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "ddnsTtlMax", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8464 ), (::testing::internal::GetTypeId<Dhcp4ParserTest>()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest> ::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8464), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8464), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_ddnsTtlMax_Test >); void Dhcp4ParserTest_ddnsTtlMax_Test::TestBody() { | |||
| 8465 | string config = R"( | |||
| 8466 | { | |||
| 8467 | "ddns-ttl-max": 750, | |||
| 8468 | "valid-lifetime": 4000, | |||
| 8469 | "shared-networks": [{ | |||
| 8470 | "name": "net", | |||
| 8471 | "ddns-ttl-max": 500, | |||
| 8472 | "subnet4": [{ | |||
| 8473 | "id": 1, | |||
| 8474 | "subnet": "10.0.2.0/24", | |||
| 8475 | "ddns-ttl-max": 250 | |||
| 8476 | }], | |||
| 8477 | }] | |||
| 8478 | } | |||
| 8479 | )"; | |||
| 8480 | ||||
| 8481 | ConstElementPtr json; | |||
| 8482 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_8482 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8482 ; } } else gtest_label_testnothrow_8482 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8482, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 8483 | extractConfig(config); | |||
| 8484 | ||||
| 8485 | ConstElementPtr status; | |||
| 8486 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_8486; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8486; } } else gtest_label_testnothrow_8486 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8486, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 8487 | ||||
| 8488 | // returned value should be 0 (success) | |||
| 8489 | checkResult(status, 0); | |||
| 8490 | ||||
| 8491 | // Commit it so global inheritance works. | |||
| 8492 | CfgMgr::instance().commit(); | |||
| 8493 | ||||
| 8494 | ConstSubnet4Ptr subnet = CfgMgr::instance().getCurrentCfg()-> | |||
| 8495 | getCfgSubnets4()->selectSubnet(IOAddress("10.0.2.0")); | |||
| 8496 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8496, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 8497 | ||||
| 8498 | EXPECT_FALSE(subnet->getDdnsTtlMax(Network::Inheritance::NONE).unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getDdnsTtlMax (Network::Inheritance::NONE).unspecified()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8498 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getDdnsTtlMax(Network::Inheritance::NONE).unspecified()" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 8499 | EXPECT_EQ(250, subnet->getDdnsTtlMax(Network::Inheritance::NONE).get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("250", "subnet->getDdnsTtlMax(Network::Inheritance::NONE).get()" , 250, subnet->getDdnsTtlMax(Network::Inheritance::NONE).get ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8499, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8500 | ||||
| 8501 | EXPECT_FALSE(subnet->getDdnsTtlMax(Network::Inheritance::PARENT_NETWORK).unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getDdnsTtlMax (Network::Inheritance::PARENT_NETWORK).unspecified()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8501, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getDdnsTtlMax(Network::Inheritance::PARENT_NETWORK).unspecified()" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 8502 | EXPECT_EQ(500, subnet->getDdnsTtlMax(Network::Inheritance::PARENT_NETWORK).get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("500", "subnet->getDdnsTtlMax(Network::Inheritance::PARENT_NETWORK).get()" , 500, subnet->getDdnsTtlMax(Network::Inheritance::PARENT_NETWORK ).get()))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8502, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8503 | ||||
| 8504 | EXPECT_FALSE(subnet->getDdnsTtlMax(Network::Inheritance::GLOBAL).unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(subnet->getDdnsTtlMax (Network::Inheritance::GLOBAL).unspecified()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8504 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet->getDdnsTtlMax(Network::Inheritance::GLOBAL).unspecified()" , "true", "false") .c_str()) = ::testing::Message(); | |||
| 8505 | EXPECT_EQ(750, subnet->getDdnsTtlMax(Network::Inheritance::GLOBAL).get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("750", "subnet->getDdnsTtlMax(Network::Inheritance::GLOBAL).get()" , 750, subnet->getDdnsTtlMax(Network::Inheritance::GLOBAL) .get()))) ; else ::testing::internal::AssertHelper(::testing:: TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8505, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8506 | } | |||
| 8507 | ||||
| 8508 | // Verifies that DDNS parameters are supported in pools. | |||
| 8509 | TEST_F(Dhcp4ParserTest, poolDdnsParameters)static_assert(sizeof("Dhcp4ParserTest") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("poolDdnsParameters") > 1, "test_name must not be empty" ); class Dhcp4ParserTest_poolDdnsParameters_Test : public Dhcp4ParserTest { public: Dhcp4ParserTest_poolDdnsParameters_Test() = default ; ~Dhcp4ParserTest_poolDdnsParameters_Test() override = default ; Dhcp4ParserTest_poolDdnsParameters_Test (const Dhcp4ParserTest_poolDdnsParameters_Test &) = delete; Dhcp4ParserTest_poolDdnsParameters_Test & operator=( const Dhcp4ParserTest_poolDdnsParameters_Test & ) = delete; Dhcp4ParserTest_poolDdnsParameters_Test (Dhcp4ParserTest_poolDdnsParameters_Test &&) noexcept = delete; Dhcp4ParserTest_poolDdnsParameters_Test & operator=( Dhcp4ParserTest_poolDdnsParameters_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const Dhcp4ParserTest_poolDdnsParameters_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "Dhcp4ParserTest" , "poolDdnsParameters", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8509), (::testing::internal::GetTypeId<Dhcp4ParserTest> ()), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetSetUpCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8509), ::testing::internal::SuiteApiResolver< Dhcp4ParserTest >::GetTearDownCaseOrSuite("../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8509), new ::testing::internal::TestFactoryImpl<Dhcp4ParserTest_poolDdnsParameters_Test >); void Dhcp4ParserTest_poolDdnsParameters_Test::TestBody () { | |||
| 8510 | string config = R"( | |||
| 8511 | { | |||
| 8512 | "valid-lifetime": 4000, | |||
| 8513 | "subnet4": [{ | |||
| 8514 | "id": 1, | |||
| 8515 | "subnet": "192.0.0.0/16", | |||
| 8516 | "pools": [{ | |||
| 8517 | "pool": "192.0.1.0/24", | |||
| 8518 | "ddns-send-updates": true, | |||
| 8519 | "ddns-override-no-update": true, | |||
| 8520 | "ddns-override-client-update": true, | |||
| 8521 | "ddns-replace-client-name": "always", | |||
| 8522 | "ddns-generated-prefix": "prefix", | |||
| 8523 | "ddns-qualifying-suffix": "suffix", | |||
| 8524 | "hostname-char-set": "[a-z]", | |||
| 8525 | "hostname-char-replacement": "X", | |||
| 8526 | "ddns-update-on-renew": true, | |||
| 8527 | "ddns-ttl-percent": 0.5, | |||
| 8528 | "ddns-conflict-resolution-mode": "check-with-dhcid", | |||
| 8529 | "ddns-ttl-min": 200, | |||
| 8530 | "ddns-ttl-max": 500 | |||
| 8531 | }, | |||
| 8532 | { | |||
| 8533 | "pool": "192.0.2.0/24", | |||
| 8534 | "ddns-ttl": 300 | |||
| 8535 | }] | |||
| 8536 | }] | |||
| 8537 | } | |||
| 8538 | )"; | |||
| 8539 | ||||
| 8540 | ConstElementPtr json; | |||
| 8541 | ASSERT_NO_THROW(json = parseDHCP4(config))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { json = parseDHCP4(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_8541 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8541 ; } } else gtest_label_testnothrow_8541 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8541, ("Expected: " "json = parseDHCP4(config)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); | |||
| 8542 | extractConfig(config); | |||
| 8543 | ||||
| 8544 | ConstElementPtr status; | |||
| 8545 | EXPECT_NO_THROW(status = Dhcpv4SrvTest::configure(*srv_, json))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { status = Dhcpv4SrvTest::configure(*srv_, json); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_8545; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_8545; } } else gtest_label_testnothrow_8545 : ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8545, ("Expected: " "status = Dhcpv4SrvTest::configure(*srv_, json)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); | |||
| 8546 | ||||
| 8547 | // returned value should be 0 (success) | |||
| 8548 | checkResult(status, 0); | |||
| 8549 | ||||
| 8550 | // Commit it so global inheritance works. | |||
| 8551 | CfgMgr::instance().commit(); | |||
| 8552 | ||||
| 8553 | ConstSubnet4Ptr subnet = CfgMgr::instance().getCurrentCfg()-> | |||
| 8554 | getCfgSubnets4()->selectSubnet(IOAddress("192.0.0.0")); | |||
| 8555 | ASSERT_TRUE(subnet)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(subnet)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8555, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "subnet", "false", "true") .c_str()) = ::testing::Message(); | |||
| 8556 | ||||
| 8557 | const PoolCollection pools = subnet->getPools(Lease::TYPE_V4); | |||
| 8558 | ASSERT_GE(pools.size(), 2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperGE("pools.size()", "2", pools.size(), 2))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8558, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8559 | ||||
| 8560 | // First pool specifies all but ddns-ttl. | |||
| 8561 | PoolPtr pool = pools.at(0); | |||
| 8562 | ASSERT_TRUE(pool)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8562 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool", "false", "true") .c_str()) = ::testing::Message(); | |||
| 8563 | ||||
| 8564 | ASSERT_FALSE(pool->getDdnsSendUpdates().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pool->getDdnsSendUpdates ().unspecified()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8564, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsSendUpdates().unspecified()", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 8565 | EXPECT_TRUE(pool->getDdnsSendUpdates().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getDdnsSendUpdates ().get())) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8565, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsSendUpdates().get()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 8566 | ||||
| 8567 | ASSERT_FALSE(pool->getDdnsOverrideNoUpdate().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pool->getDdnsOverrideNoUpdate ().unspecified()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8567, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsOverrideNoUpdate().unspecified()", "true", "false") .c_str()) = ::testing::Message(); | |||
| 8568 | EXPECT_TRUE(pool->getDdnsOverrideNoUpdate().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getDdnsOverrideNoUpdate ().get())) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8568, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsOverrideNoUpdate().get()", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 8569 | ||||
| 8570 | ASSERT_FALSE(pool->getDdnsOverrideClientUpdate().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pool->getDdnsOverrideClientUpdate ().unspecified()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8570, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsOverrideClientUpdate().unspecified()", "true" , "false") .c_str()) = ::testing::Message(); | |||
| 8571 | EXPECT_TRUE(pool->getDdnsOverrideClientUpdate().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getDdnsOverrideClientUpdate ().get())) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8571, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsOverrideClientUpdate().get()", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 8572 | ||||
| 8573 | ASSERT_FALSE(pool->getDdnsReplaceClientNameMode().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pool->getDdnsReplaceClientNameMode ().unspecified()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8573, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsReplaceClientNameMode().unspecified()", "true" , "false") .c_str()) = ::testing::Message(); | |||
| 8574 | EXPECT_EQ(pool->getDdnsReplaceClientNameMode().get(),switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("pool->getDdnsReplaceClientNameMode().get()" , "D2ClientConfig::RCM_ALWAYS", pool->getDdnsReplaceClientNameMode ().get(), D2ClientConfig::RCM_ALWAYS))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8575, gtest_ar.failure_message()) = ::testing::Message() | |||
| 8575 | D2ClientConfig::RCM_ALWAYS)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("pool->getDdnsReplaceClientNameMode().get()" , "D2ClientConfig::RCM_ALWAYS", pool->getDdnsReplaceClientNameMode ().get(), D2ClientConfig::RCM_ALWAYS))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8575, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8576 | ||||
| 8577 | ASSERT_FALSE(pool->getDdnsGeneratedPrefix().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pool->getDdnsGeneratedPrefix ().unspecified()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8577, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsGeneratedPrefix().unspecified()", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 8578 | EXPECT_EQ(pool->getDdnsGeneratedPrefix().get(), "prefix")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("pool->getDdnsGeneratedPrefix().get()" , "\"prefix\"", pool->getDdnsGeneratedPrefix().get(), "prefix" ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8578, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8579 | ||||
| 8580 | ASSERT_FALSE(pool->getDdnsQualifyingSuffix().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pool->getDdnsQualifyingSuffix ().unspecified()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8580, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsQualifyingSuffix().unspecified()", "true", "false") .c_str()) = ::testing::Message(); | |||
| 8581 | EXPECT_EQ(pool->getDdnsQualifyingSuffix().get(), "suffix")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("pool->getDdnsQualifyingSuffix().get()" , "\"suffix\"", pool->getDdnsQualifyingSuffix().get(), "suffix" ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8581, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8582 | ||||
| 8583 | ASSERT_FALSE(pool->getHostnameCharSet().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pool->getHostnameCharSet ().unspecified()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8583, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getHostnameCharSet().unspecified()", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 8584 | EXPECT_EQ(pool->getHostnameCharSet().get(), "[a-z]")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("pool->getHostnameCharSet().get()" , "\"[a-z]\"", pool->getHostnameCharSet().get(), "[a-z]")) ) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8584, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8585 | ||||
| 8586 | ASSERT_FALSE(pool->getHostnameCharReplacement().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pool->getHostnameCharReplacement ().unspecified()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8586, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getHostnameCharReplacement().unspecified()", "true" , "false") .c_str()) = ::testing::Message(); | |||
| 8587 | EXPECT_EQ(pool->getHostnameCharReplacement().get(), "X")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("pool->getHostnameCharReplacement().get()" , "\"X\"", pool->getHostnameCharReplacement().get(), "X")) ) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8587, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8588 | ||||
| 8589 | ASSERT_FALSE(pool->getDdnsUpdateOnRenew().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pool->getDdnsUpdateOnRenew ().unspecified()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8589, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsUpdateOnRenew().unspecified()", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 8590 | EXPECT_TRUE(pool->getDdnsUpdateOnRenew().get())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getDdnsUpdateOnRenew ().get())) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8590, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsUpdateOnRenew().get()", "false", "true") . c_str()) = ::testing::Message(); | |||
| 8591 | ||||
| 8592 | ASSERT_FALSE(pool->getDdnsTtlPercent().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pool->getDdnsTtlPercent ().unspecified()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8592, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsTtlPercent().unspecified()", "true", "false" ) .c_str()) = ::testing::Message(); | |||
| 8593 | EXPECT_EQ(pool->getDdnsTtlPercent().get(), 0.5)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("pool->getDdnsTtlPercent().get()" , "0.5", pool->getDdnsTtlPercent().get(), 0.5))) ; else :: testing::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8593 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8594 | ||||
| 8595 | ASSERT_FALSE(pool->getDdnsConflictResolutionMode().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pool->getDdnsConflictResolutionMode ().unspecified()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8595, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsConflictResolutionMode().unspecified()", "true" , "false") .c_str()) = ::testing::Message(); | |||
| 8596 | EXPECT_EQ(pool->getDdnsConflictResolutionMode().get(), "check-with-dhcid")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("pool->getDdnsConflictResolutionMode().get()" , "\"check-with-dhcid\"", pool->getDdnsConflictResolutionMode ().get(), "check-with-dhcid"))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8596, gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8597 | ||||
| 8598 | ASSERT_TRUE(pool->getDdnsTtl().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getDdnsTtl() .unspecified())) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8598, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsTtl().unspecified()", "false", "true") .c_str ()) = ::testing::Message(); | |||
| 8599 | ||||
| 8600 | ASSERT_FALSE(pool->getDdnsTtlMin().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pool->getDdnsTtlMin ().unspecified()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8600, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsTtlMin().unspecified()", "true", "false") . c_str()) = ::testing::Message(); | |||
| 8601 | EXPECT_EQ(pool->getDdnsTtlMin().get(), 200)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("pool->getDdnsTtlMin().get()" , "200", pool->getDdnsTtlMin().get(), 200))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8601 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8602 | ||||
| 8603 | ASSERT_FALSE(pool->getDdnsTtlMax().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pool->getDdnsTtlMax ().unspecified()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8603, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsTtlMax().unspecified()", "true", "false") . c_str()) = ::testing::Message(); | |||
| 8604 | EXPECT_EQ(pool->getDdnsTtlMax().get(), 500)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("pool->getDdnsTtlMax().get()" , "500", pool->getDdnsTtlMax().get(), 500))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8604 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8605 | ||||
| 8606 | // Second pool only specifies ddns-ttl. | |||
| 8607 | pool = pools.at(1); | |||
| 8608 | ASSERT_TRUE(pool)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8608 , ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool", "false", "true") .c_str()) = ::testing::Message(); | |||
| 8609 | ||||
| 8610 | ASSERT_TRUE(pool->getDdnsSendUpdates().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getDdnsSendUpdates ().unspecified())) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8610, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsSendUpdates().unspecified()", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 8611 | ASSERT_TRUE(pool->getDdnsOverrideNoUpdate().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getDdnsOverrideNoUpdate ().unspecified())) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8611, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsOverrideNoUpdate().unspecified()", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 8612 | ASSERT_TRUE(pool->getDdnsOverrideClientUpdate().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getDdnsOverrideClientUpdate ().unspecified())) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8612, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsOverrideClientUpdate().unspecified()", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 8613 | ASSERT_TRUE(pool->getDdnsReplaceClientNameMode().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getDdnsReplaceClientNameMode ().unspecified())) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8613, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsReplaceClientNameMode().unspecified()", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 8614 | ASSERT_TRUE(pool->getDdnsGeneratedPrefix().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getDdnsGeneratedPrefix ().unspecified())) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8614, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsGeneratedPrefix().unspecified()", "false", "true") .c_str()) = ::testing::Message(); | |||
| 8615 | ASSERT_TRUE(pool->getDdnsQualifyingSuffix().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getDdnsQualifyingSuffix ().unspecified())) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8615, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsQualifyingSuffix().unspecified()", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 8616 | ASSERT_TRUE(pool->getHostnameCharSet().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getHostnameCharSet ().unspecified())) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8616, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getHostnameCharSet().unspecified()", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 8617 | ASSERT_TRUE(pool->getHostnameCharReplacement().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getHostnameCharReplacement ().unspecified())) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8617, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getHostnameCharReplacement().unspecified()", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 8618 | ASSERT_TRUE(pool->getDdnsUpdateOnRenew().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getDdnsUpdateOnRenew ().unspecified())) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8618, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsUpdateOnRenew().unspecified()", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 8619 | ASSERT_TRUE(pool->getDdnsTtlPercent().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getDdnsTtlPercent ().unspecified())) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8619, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsTtlPercent().unspecified()", "false", "true" ) .c_str()) = ::testing::Message(); | |||
| 8620 | ASSERT_TRUE(pool->getDdnsConflictResolutionMode().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getDdnsConflictResolutionMode ().unspecified())) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8620, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsConflictResolutionMode().unspecified()", "false" , "true") .c_str()) = ::testing::Message(); | |||
| 8621 | ASSERT_TRUE(pool->getDdnsTtlMin().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getDdnsTtlMin ().unspecified())) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8621, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsTtlMin().unspecified()", "false", "true") . c_str()) = ::testing::Message(); | |||
| 8622 | ||||
| 8623 | ASSERT_FALSE(pool->getDdnsTtl().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(pool->getDdnsTtl ().unspecified()))) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8623, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsTtl().unspecified()", "true", "false") .c_str ()) = ::testing::Message(); | |||
| 8624 | EXPECT_EQ(pool->getDdnsTtl().get(), 300)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("pool->getDdnsTtl().get()" , "300", pool->getDdnsTtl().get(), 300))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/bin/dhcp4/tests/config_parser_unittest.cc", 8624 , gtest_ar.failure_message()) = ::testing::Message(); | |||
| 8625 | ||||
| 8626 | ASSERT_TRUE(pool->getDdnsTtlMax().unspecified())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(pool->getDdnsTtlMax ().unspecified())) ; else return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/bin/dhcp4/tests/config_parser_unittest.cc" , 8626, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "pool->getDdnsTtlMax().unspecified()", "false", "true") . c_str()) = ::testing::Message(); | |||
| 8627 | } | |||
| 8628 | ||||
| 8629 | } // namespace |
| 1 | // Components for manipulating sequences of characters -*- C++ -*- |
| 2 | |
| 3 | // Copyright (C) 1997-2025 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 __cplusplus201703L > 202302L |
| 60 | # include <charconv> |
| 61 | #endif |
| 62 | |
| 63 | |
| 64 | #if ! _GLIBCXX_USE_CXX11_ABI1 |
| 65 | # include "cow_string.h" |
| 66 | #else |
| 67 | |
| 68 | namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default"))) |
| 69 | { |
| 70 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 71 | _GLIBCXX_BEGIN_NAMESPACE_CXX11namespace __cxx11 { |
| 72 | |
| 73 | /** |
| 74 | * @class basic_string basic_string.h <string> |
| 75 | * @brief Managing sequences of characters and character-like objects. |
| 76 | * |
| 77 | * @ingroup strings |
| 78 | * @ingroup sequences |
| 79 | * @headerfile string |
| 80 | * @since C++98 |
| 81 | * |
| 82 | * @tparam _CharT Type of character |
| 83 | * @tparam _Traits Traits for character type, defaults to |
| 84 | * char_traits<_CharT>. |
| 85 | * @tparam _Alloc Allocator type, defaults to allocator<_CharT>. |
| 86 | * |
| 87 | * Meets the requirements of a <a href="tables.html#65">container</a>, a |
| 88 | * <a href="tables.html#66">reversible container</a>, and a |
| 89 | * <a href="tables.html#67">sequence</a>. Of the |
| 90 | * <a href="tables.html#68">optional sequence requirements</a>, only |
| 91 | * @c push_back, @c at, and @c %array access are supported. |
| 92 | */ |
| 93 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 94 | class basic_string |
| 95 | { |
| 96 | #if __cplusplus201703L >= 202002L |
| 97 | static_assert(is_trivially_copyable_v<_CharT> |
| 98 | && is_trivially_default_constructible_v<_CharT> |
| 99 | && is_standard_layout_v<_CharT>); |
| 100 | static_assert(is_same_v<_CharT, typename _Traits::char_type>); |
| 101 | static_assert(is_same_v<_CharT, typename _Alloc::value_type>); |
| 102 | using _Char_alloc_type = _Alloc; |
| 103 | #else |
| 104 | typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template |
| 105 | rebind<_CharT>::other _Char_alloc_type; |
| 106 | #endif |
| 107 | |
| 108 | typedef __gnu_cxx::__alloc_traits<_Char_alloc_type> _Alloc_traits; |
| 109 | |
| 110 | // Types: |
| 111 | public: |
| 112 | typedef _Traits traits_type; |
| 113 | typedef typename _Traits::char_type value_type; |
| 114 | typedef _Char_alloc_type allocator_type; |
| 115 | typedef typename _Alloc_traits::size_type size_type; |
| 116 | typedef typename _Alloc_traits::difference_type difference_type; |
| 117 | typedef typename _Alloc_traits::reference reference; |
| 118 | typedef typename _Alloc_traits::const_reference const_reference; |
| 119 | typedef typename _Alloc_traits::pointer pointer; |
| 120 | typedef typename _Alloc_traits::const_pointer const_pointer; |
| 121 | typedef __gnu_cxx::__normal_iterator<pointer, basic_string> iterator; |
| 122 | typedef __gnu_cxx::__normal_iterator<const_pointer, basic_string> |
| 123 | const_iterator; |
| 124 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 125 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 126 | |
| 127 | /// Value returned by various member functions when they fail. |
| 128 | static const size_type npos = static_cast<size_type>(-1); |
| 129 | |
| 130 | protected: |
| 131 | // type used for positions in insert, erase etc. |
| 132 | #if __cplusplus201703L < 201103L |
| 133 | typedef iterator __const_iterator; |
| 134 | #else |
| 135 | typedef const_iterator __const_iterator; |
| 136 | #endif |
| 137 | |
| 138 | private: |
| 139 | static _GLIBCXX20_CONSTEXPR pointer |
| 140 | _S_allocate(_Char_alloc_type& __a, size_type __n) |
| 141 | { |
| 142 | pointer __p = _Alloc_traits::allocate(__a, __n); |
| 143 | #if __glibcxx_constexpr_string201611L >= 201907L |
| 144 | // std::char_traits begins the lifetime of characters, |
| 145 | // but custom traits might not, so do it here. |
| 146 | if constexpr (!is_same_v<_Traits, char_traits<_CharT>>) |
| 147 | if (std::__is_constant_evaluated()) |
| 148 | // Begin the lifetime of characters in allocated storage. |
| 149 | for (size_type __i = 0; __i < __n; ++__i) |
| 150 | std::construct_at(__builtin_addressof(__p[__i])); |
| 151 | #endif |
| 152 | return __p; |
| 153 | } |
| 154 | |
| 155 | #ifdef __glibcxx_string_view201803L // >= C++17 |
| 156 | // A helper type for avoiding boiler-plate. |
| 157 | typedef basic_string_view<_CharT, _Traits> __sv_type; |
| 158 | |
| 159 | template<typename _Tp, typename _Res> |
| 160 | using _If_sv = enable_if_t< |
| 161 | __and_<is_convertible<const _Tp&, __sv_type>, |
| 162 | __not_<is_convertible<const _Tp*, const basic_string*>>, |
| 163 | __not_<is_convertible<const _Tp&, const _CharT*>>>::value, |
| 164 | _Res>; |
| 165 | |
| 166 | // Allows an implicit conversion to __sv_type. |
| 167 | _GLIBCXX20_CONSTEXPR |
| 168 | static __sv_type |
| 169 | _S_to_string_view(__sv_type __svt) noexcept |
| 170 | { return __svt; } |
| 171 | |
| 172 | // Wraps a string_view by explicit conversion and thus |
| 173 | // allows to add an internal constructor that does not |
| 174 | // participate in overload resolution when a string_view |
| 175 | // is provided. |
| 176 | struct __sv_wrapper |
| 177 | { |
| 178 | _GLIBCXX20_CONSTEXPR explicit |
| 179 | __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { } |
| 180 | |
| 181 | __sv_type _M_sv; |
| 182 | }; |
| 183 | |
| 184 | /** |
| 185 | * @brief Only internally used: Construct string from a string view |
| 186 | * wrapper. |
| 187 | * @param __svw string view wrapper. |
| 188 | * @param __a Allocator to use. |
| 189 | */ |
| 190 | _GLIBCXX20_CONSTEXPR |
| 191 | explicit |
| 192 | basic_string(__sv_wrapper __svw, const _Alloc& __a) |
| 193 | : basic_string(__svw._M_sv.data(), __svw._M_sv.size(), __a) { } |
| 194 | #endif |
| 195 | |
| 196 | // Use empty-base optimization: http://www.cantrip.org/emptyopt.html |
| 197 | struct _Alloc_hider : allocator_type // TODO check __is_final |
| 198 | { |
| 199 | #if __cplusplus201703L < 201103L |
| 200 | _Alloc_hider(pointer __dat, const _Alloc& __a = _Alloc()) |
| 201 | : allocator_type(__a), _M_p(__dat) { } |
| 202 | #else |
| 203 | _GLIBCXX20_CONSTEXPR |
| 204 | _Alloc_hider(pointer __dat, const _Alloc& __a) |
| 205 | : allocator_type(__a), _M_p(__dat) { } |
| 206 | |
| 207 | _GLIBCXX20_CONSTEXPR |
| 208 | _Alloc_hider(pointer __dat, _Alloc&& __a = _Alloc()) |
| 209 | : allocator_type(std::move(__a)), _M_p(__dat) { } |
| 210 | #endif |
| 211 | |
| 212 | pointer _M_p; // The actual data. |
| 213 | }; |
| 214 | |
| 215 | _Alloc_hider _M_dataplus; |
| 216 | size_type _M_string_length; |
| 217 | |
| 218 | enum { _S_local_capacity = 15 / sizeof(_CharT) }; |
| 219 | |
| 220 | union |
| 221 | { |
| 222 | _CharT _M_local_buf[_S_local_capacity + 1]; |
| 223 | size_type _M_allocated_capacity; |
| 224 | }; |
| 225 | |
| 226 | _GLIBCXX20_CONSTEXPR |
| 227 | void |
| 228 | _M_data(pointer __p) |
| 229 | { _M_dataplus._M_p = __p; } |
| 230 | |
| 231 | _GLIBCXX20_CONSTEXPR |
| 232 | void |
| 233 | _M_length(size_type __length) |
| 234 | { _M_string_length = __length; } |
| 235 | |
| 236 | _GLIBCXX20_CONSTEXPR |
| 237 | pointer |
| 238 | _M_data() const |
| 239 | { return _M_dataplus._M_p; } |
| 240 | |
| 241 | _GLIBCXX20_CONSTEXPR |
| 242 | pointer |
| 243 | _M_local_data() |
| 244 | { |
| 245 | #if __cplusplus201703L >= 201103L |
| 246 | return std::pointer_traits<pointer>::pointer_to(*_M_local_buf); |
| 247 | #else |
| 248 | return pointer(_M_local_buf); |
| 249 | #endif |
| 250 | } |
| 251 | |
| 252 | _GLIBCXX20_CONSTEXPR |
| 253 | const_pointer |
| 254 | _M_local_data() const |
| 255 | { |
| 256 | #if __cplusplus201703L >= 201103L |
| 257 | return std::pointer_traits<const_pointer>::pointer_to(*_M_local_buf); |
| 258 | #else |
| 259 | return const_pointer(_M_local_buf); |
| 260 | #endif |
| 261 | } |
| 262 | |
| 263 | _GLIBCXX20_CONSTEXPR |
| 264 | void |
| 265 | _M_capacity(size_type __capacity) |
| 266 | { _M_allocated_capacity = __capacity; } |
| 267 | |
| 268 | _GLIBCXX20_CONSTEXPR |
| 269 | void |
| 270 | _M_set_length(size_type __n) |
| 271 | { |
| 272 | _M_length(__n); |
| 273 | traits_type::assign(_M_data()[__n], _CharT()); |
| 274 | } |
| 275 | |
| 276 | _GLIBCXX20_CONSTEXPR |
| 277 | bool |
| 278 | _M_is_local() const |
| 279 | { |
| 280 | if (_M_data() == _M_local_data()) |
| 281 | { |
| 282 | if (_M_string_length > _S_local_capacity) |
| 283 | __builtin_unreachable(); |
| 284 | return true; |
| 285 | } |
| 286 | return false; |
| 287 | } |
| 288 | |
| 289 | // Create & Destroy |
| 290 | _GLIBCXX20_CONSTEXPR |
| 291 | pointer |
| 292 | _M_create(size_type&, size_type); |
| 293 | |
| 294 | _GLIBCXX20_CONSTEXPR |
| 295 | void |
| 296 | _M_dispose() |
| 297 | { |
| 298 | if (!_M_is_local()) |
| 299 | _M_destroy(_M_allocated_capacity); |
| 300 | } |
| 301 | |
| 302 | _GLIBCXX20_CONSTEXPR |
| 303 | void |
| 304 | _M_destroy(size_type __size) throw() |
| 305 | { _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size + 1); } |
| 306 | |
| 307 | #if __cplusplus201703L < 201103L || defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS |
| 308 | // _M_construct_aux is used to implement the 21.3.1 para 15 which |
| 309 | // requires special behaviour if _InIterator is an integral type |
| 310 | template<typename _InIterator> |
| 311 | void |
| 312 | _M_construct_aux(_InIterator __beg, _InIterator __end, |
| 313 | std::__false_type) |
| 314 | { |
| 315 | typedef typename iterator_traits<_InIterator>::iterator_category _Tag; |
| 316 | _M_construct(__beg, __end, _Tag()); |
| 317 | } |
| 318 | |
| 319 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
| 320 | // 438. Ambiguity in the "do the right thing" clause |
| 321 | template<typename _Integer> |
| 322 | void |
| 323 | _M_construct_aux(_Integer __beg, _Integer __end, std::__true_type) |
| 324 | { _M_construct_aux_2(static_cast<size_type>(__beg), __end); } |
| 325 | |
| 326 | void |
| 327 | _M_construct_aux_2(size_type __req, _CharT __c) |
| 328 | { _M_construct(__req, __c); } |
| 329 | #endif |
| 330 | |
| 331 | // For Input Iterators, used in istreambuf_iterators, etc. |
| 332 | template<typename _InIterator> |
| 333 | _GLIBCXX20_CONSTEXPR |
| 334 | void |
| 335 | _M_construct(_InIterator __beg, _InIterator __end, |
| 336 | std::input_iterator_tag); |
| 337 | |
| 338 | // For forward_iterators up to random_access_iterators, used for |
| 339 | // string::iterator, _CharT*, etc. |
| 340 | template<typename _FwdIterator> |
| 341 | _GLIBCXX20_CONSTEXPR |
| 342 | void |
| 343 | _M_construct(_FwdIterator __beg, _FwdIterator __end, |
| 344 | std::forward_iterator_tag); |
| 345 | |
| 346 | _GLIBCXX20_CONSTEXPR |
| 347 | void |
| 348 | _M_construct(size_type __req, _CharT __c); |
| 349 | |
| 350 | // Construct using block of memory of known size. |
| 351 | // If _Terminated is true assume that source is already 0 terminated. |
| 352 | template<bool _Terminated> |
| 353 | _GLIBCXX20_CONSTEXPR |
| 354 | void |
| 355 | _M_construct(const _CharT *__c, size_type __n); |
| 356 | |
| 357 | _GLIBCXX20_CONSTEXPR |
| 358 | allocator_type& |
| 359 | _M_get_allocator() |
| 360 | { return _M_dataplus; } |
| 361 | |
| 362 | _GLIBCXX20_CONSTEXPR |
| 363 | const allocator_type& |
| 364 | _M_get_allocator() const |
| 365 | { return _M_dataplus; } |
| 366 | |
| 367 | // Ensure that _M_local_buf is the active member of the union. |
| 368 | __attribute__((__always_inline__)) |
| 369 | _GLIBCXX14_CONSTEXPRconstexpr |
| 370 | void |
| 371 | _M_init_local_buf() _GLIBCXX_NOEXCEPTnoexcept |
| 372 | { |
| 373 | #if __glibcxx_is_constant_evaluated |
| 374 | if (std::is_constant_evaluated()) |
| 375 | for (size_type __i = 0; __i <= _S_local_capacity; ++__i) |
| 376 | _M_local_buf[__i] = _CharT(); |
| 377 | #endif |
| 378 | } |
| 379 | |
| 380 | __attribute__((__always_inline__)) |
| 381 | _GLIBCXX14_CONSTEXPRconstexpr |
| 382 | pointer |
| 383 | _M_use_local_data() _GLIBCXX_NOEXCEPTnoexcept |
| 384 | { |
| 385 | #if __cpp_lib_is_constant_evaluated |
| 386 | _M_init_local_buf(); |
| 387 | #endif |
| 388 | return _M_local_data(); |
| 389 | } |
| 390 | |
| 391 | private: |
| 392 | |
| 393 | #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST |
| 394 | // The explicit instantiations in misc-inst.cc require this due to |
| 395 | // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64063 |
| 396 | template<typename _Tp, bool _Requires = |
| 397 | !__are_same<_Tp, _CharT*>::__value |
| 398 | && !__are_same<_Tp, const _CharT*>::__value |
| 399 | && !__are_same<_Tp, iterator>::__value |
| 400 | && !__are_same<_Tp, const_iterator>::__value> |
| 401 | struct __enable_if_not_native_iterator |
| 402 | { typedef basic_string& __type; }; |
| 403 | template<typename _Tp> |
| 404 | struct __enable_if_not_native_iterator<_Tp, false> { }; |
| 405 | #endif |
| 406 | |
| 407 | _GLIBCXX20_CONSTEXPR |
| 408 | size_type |
| 409 | _M_check(size_type __pos, const char* __s) const |
| 410 | { |
| 411 | if (__pos > this->size()) |
| 412 | __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > "("%s: __pos (which is %zu) > " "this->size() (which is %zu)" ) |
| 413 | "this->size() (which is %zu)")("%s: __pos (which is %zu) > " "this->size() (which is %zu)" ), |
| 414 | __s, __pos, this->size()); |
| 415 | return __pos; |
| 416 | } |
| 417 | |
| 418 | _GLIBCXX20_CONSTEXPR |
| 419 | void |
| 420 | _M_check_length(size_type __n1, size_type __n2, const char* __s) const |
| 421 | { |
| 422 | if (this->max_size() - (this->size() - __n1) < __n2) |
| 423 | __throw_length_error(__N(__s)(__s)); |
| 424 | } |
| 425 | |
| 426 | |
| 427 | // NB: _M_limit doesn't check for a bad __pos value. |
| 428 | _GLIBCXX20_CONSTEXPR |
| 429 | size_type |
| 430 | _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPTnoexcept |
| 431 | { |
| 432 | const bool __testoff = __off < this->size() - __pos; |
| 433 | return __testoff ? __off : this->size() - __pos; |
| 434 | } |
| 435 | |
| 436 | // True if _Rep and source do not overlap. |
| 437 | bool |
| 438 | _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPTnoexcept |
| 439 | { |
| 440 | return (less<const _CharT*>()(__s, _M_data()) |
| 441 | || less<const _CharT*>()(_M_data() + this->size(), __s)); |
| 442 | } |
| 443 | |
| 444 | // When __n = 1 way faster than the general multichar |
| 445 | // traits_type::copy/move/assign. |
| 446 | _GLIBCXX20_CONSTEXPR |
| 447 | static void |
| 448 | _S_copy(_CharT* __d, const _CharT* __s, size_type __n) |
| 449 | { |
| 450 | if (__n == 1) |
| 451 | traits_type::assign(*__d, *__s); |
| 452 | else |
| 453 | traits_type::copy(__d, __s, __n); |
| 454 | } |
| 455 | |
| 456 | _GLIBCXX20_CONSTEXPR |
| 457 | static void |
| 458 | _S_move(_CharT* __d, const _CharT* __s, size_type __n) |
| 459 | { |
| 460 | if (__n == 1) |
| 461 | traits_type::assign(*__d, *__s); |
| 462 | else |
| 463 | traits_type::move(__d, __s, __n); |
| 464 | } |
| 465 | |
| 466 | _GLIBCXX20_CONSTEXPR |
| 467 | static void |
| 468 | _S_assign(_CharT* __d, size_type __n, _CharT __c) |
| 469 | { |
| 470 | if (__n == 1) |
| 471 | traits_type::assign(*__d, __c); |
| 472 | else |
| 473 | traits_type::assign(__d, __n, __c); |
| 474 | } |
| 475 | |
| 476 | #pragma GCC diagnostic push |
| 477 | #pragma GCC diagnostic ignored "-Wc++17-extensions" |
| 478 | // _S_copy_chars is a separate template to permit specialization |
| 479 | // to optimize for the common case of pointers as iterators. |
| 480 | template<class _Iterator> |
| 481 | _GLIBCXX20_CONSTEXPR |
| 482 | static void |
| 483 | _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2) |
| 484 | { |
| 485 | #if __cplusplus201703L >= 201103L |
| 486 | using _IterBase = decltype(std::__niter_base(__k1)); |
| 487 | if constexpr (__or_<is_same<_IterBase, _CharT*>, |
| 488 | is_same<_IterBase, const _CharT*>>::value) |
| 489 | _S_copy(__p, std::__niter_base(__k1), __k2 - __k1); |
| 490 | #if __cpp_lib_concepts |
| 491 | else if constexpr (requires { |
| 492 | requires contiguous_iterator<_Iterator>; |
| 493 | { std::to_address(__k1) } |
| 494 | -> convertible_to<const _CharT*>; |
| 495 | }) |
| 496 | { |
| 497 | const auto __d = __k2 - __k1; |
| 498 | (void) (__k1 + __d); // See P3349R1 |
| 499 | _S_copy(__p, std::to_address(__k1), static_cast<size_type>(__d)); |
| 500 | } |
| 501 | #endif |
| 502 | else |
| 503 | #endif |
| 504 | for (; __k1 != __k2; ++__k1, (void)++__p) |
| 505 | traits_type::assign(*__p, static_cast<_CharT>(*__k1)); |
| 506 | } |
| 507 | #pragma GCC diagnostic pop |
| 508 | |
| 509 | #if __cplusplus201703L < 201103L || defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS |
| 510 | static void |
| 511 | _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) |
| 512 | { _S_copy_chars(__p, __k1.base(), __k2.base()); } |
| 513 | |
| 514 | static void |
| 515 | _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2) |
| 516 | { _S_copy_chars(__p, __k1.base(), __k2.base()); } |
| 517 | |
| 518 | static void |
| 519 | _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) |
| 520 | { _S_copy(__p, __k1, __k2 - __k1); } |
| 521 | |
| 522 | static void |
| 523 | _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2) |
| 524 | { _S_copy(__p, __k1, __k2 - __k1); } |
| 525 | #endif |
| 526 | |
| 527 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 528 | // pre: __n == ranges::distance(__rg). __p+[0,__n) is a valid range. |
| 529 | template<typename _Rg> |
| 530 | static constexpr void |
| 531 | _S_copy_range(pointer __p, _Rg&& __rg, size_type __n) |
| 532 | { |
| 533 | if constexpr (requires { |
| 534 | requires ranges::contiguous_range<_Rg>; |
| 535 | { ranges::data(std::forward<_Rg>(__rg)) } |
| 536 | -> convertible_to<const _CharT*>; |
| 537 | }) |
| 538 | _S_copy(__p, ranges::data(std::forward<_Rg>(__rg)), __n); |
| 539 | else |
| 540 | { |
| 541 | auto __first = ranges::begin(__rg); |
| 542 | const auto __last = ranges::end(__rg); |
| 543 | for (; __first != __last; ++__first) |
| 544 | traits_type::assign(*__p++, static_cast<_CharT>(*__first)); |
| 545 | } |
| 546 | } |
| 547 | #endif |
| 548 | |
| 549 | _GLIBCXX20_CONSTEXPR |
| 550 | static int |
| 551 | _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPTnoexcept |
| 552 | { |
| 553 | const difference_type __d = difference_type(__n1 - __n2); |
| 554 | |
| 555 | if (__d > __gnu_cxx::__numeric_traits<int>::__max) |
| 556 | return __gnu_cxx::__numeric_traits<int>::__max; |
| 557 | else if (__d < __gnu_cxx::__numeric_traits<int>::__min) |
| 558 | return __gnu_cxx::__numeric_traits<int>::__min; |
| 559 | else |
| 560 | return int(__d); |
| 561 | } |
| 562 | |
| 563 | _GLIBCXX20_CONSTEXPR |
| 564 | void |
| 565 | _M_assign(const basic_string&); |
| 566 | |
| 567 | _GLIBCXX20_CONSTEXPR |
| 568 | void |
| 569 | _M_mutate(size_type __pos, size_type __len1, const _CharT* __s, |
| 570 | size_type __len2); |
| 571 | |
| 572 | _GLIBCXX20_CONSTEXPR |
| 573 | void |
| 574 | _M_erase(size_type __pos, size_type __n); |
| 575 | |
| 576 | public: |
| 577 | // Construct/copy/destroy: |
| 578 | // NB: We overload ctors in some cases instead of using default |
| 579 | // arguments, per 17.4.4.4 para. 2 item 2. |
| 580 | |
| 581 | /** |
| 582 | * @brief Default constructor creates an empty string. |
| 583 | */ |
| 584 | _GLIBCXX20_CONSTEXPR |
| 585 | basic_string() |
| 586 | _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible<_Alloc>::value)noexcept(is_nothrow_default_constructible<_Alloc>::value ) |
| 587 | #if __cpp_concepts && __glibcxx_type_trait_variable_templates201510L |
| 588 | requires is_default_constructible_v<_Alloc> |
| 589 | #endif |
| 590 | : _M_dataplus(_M_local_data()) |
| 591 | { |
| 592 | _M_init_local_buf(); |
| 593 | _M_set_length(0); |
| 594 | } |
| 595 | |
| 596 | /** |
| 597 | * @brief Construct an empty string using allocator @a a. |
| 598 | */ |
| 599 | _GLIBCXX20_CONSTEXPR |
| 600 | explicit |
| 601 | basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPTnoexcept |
| 602 | : _M_dataplus(_M_local_data(), __a) |
| 603 | { |
| 604 | _M_init_local_buf(); |
| 605 | _M_set_length(0); |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * @brief Construct string with copy of value of @a __str. |
| 610 | * @param __str Source string. |
| 611 | */ |
| 612 | _GLIBCXX20_CONSTEXPR |
| 613 | basic_string(const basic_string& __str) |
| 614 | : _M_dataplus(_M_local_data(), |
| 615 | _Alloc_traits::_S_select_on_copy(__str._M_get_allocator())) |
| 616 | { |
| 617 | _M_construct<true>(__str._M_data(), __str.length()); |
| 618 | } |
| 619 | |
| 620 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
| 621 | // 2583. no way to supply an allocator for basic_string(str, pos) |
| 622 | /** |
| 623 | * @brief Construct string as copy of a substring. |
| 624 | * @param __str Source string. |
| 625 | * @param __pos Index of first character to copy from. |
| 626 | * @param __a Allocator to use. |
| 627 | */ |
| 628 | _GLIBCXX20_CONSTEXPR |
| 629 | basic_string(const basic_string& __str, size_type __pos, |
| 630 | const _Alloc& __a = _Alloc()) |
| 631 | : _M_dataplus(_M_local_data(), __a) |
| 632 | { |
| 633 | const _CharT* __start = __str._M_data() |
| 634 | + __str._M_check(__pos, "basic_string::basic_string"); |
| 635 | _M_construct(__start, __start + __str._M_limit(__pos, npos), |
| 636 | std::forward_iterator_tag()); |
| 637 | } |
| 638 | |
| 639 | /** |
| 640 | * @brief Construct string as copy of a substring. |
| 641 | * @param __str Source string. |
| 642 | * @param __pos Index of first character to copy from. |
| 643 | * @param __n Number of characters to copy. |
| 644 | */ |
| 645 | _GLIBCXX20_CONSTEXPR |
| 646 | basic_string(const basic_string& __str, size_type __pos, |
| 647 | size_type __n) |
| 648 | : _M_dataplus(_M_local_data()) |
| 649 | { |
| 650 | const _CharT* __start = __str._M_data() |
| 651 | + __str._M_check(__pos, "basic_string::basic_string"); |
| 652 | _M_construct(__start, __start + __str._M_limit(__pos, __n), |
| 653 | std::forward_iterator_tag()); |
| 654 | } |
| 655 | |
| 656 | /** |
| 657 | * @brief Construct string as copy of a substring. |
| 658 | * @param __str Source string. |
| 659 | * @param __pos Index of first character to copy from. |
| 660 | * @param __n Number of characters to copy. |
| 661 | * @param __a Allocator to use. |
| 662 | */ |
| 663 | _GLIBCXX20_CONSTEXPR |
| 664 | basic_string(const basic_string& __str, size_type __pos, |
| 665 | size_type __n, const _Alloc& __a) |
| 666 | : _M_dataplus(_M_local_data(), __a) |
| 667 | { |
| 668 | const _CharT* __start |
| 669 | = __str._M_data() + __str._M_check(__pos, "string::string"); |
| 670 | _M_construct(__start, __start + __str._M_limit(__pos, __n), |
| 671 | std::forward_iterator_tag()); |
| 672 | } |
| 673 | |
| 674 | /** |
| 675 | * @brief Construct string initialized by a character %array. |
| 676 | * @param __s Source character %array. |
| 677 | * @param __n Number of characters to copy. |
| 678 | * @param __a Allocator to use (default is default allocator). |
| 679 | * |
| 680 | * NB: @a __s must have at least @a __n characters, '\\0' |
| 681 | * has no special meaning. |
| 682 | */ |
| 683 | _GLIBCXX20_CONSTEXPR |
| 684 | basic_string(const _CharT* __s, size_type __n, |
| 685 | const _Alloc& __a = _Alloc()) |
| 686 | : _M_dataplus(_M_local_data(), __a) |
| 687 | { |
| 688 | // NB: Not required, but considered best practice. |
| 689 | if (__s == 0 && __n > 0) |
| 690 | std::__throw_logic_error(__N("basic_string: "("basic_string: " "construction from null is not valid") |
| 691 | "construction from null is not valid")("basic_string: " "construction from null is not valid")); |
| 692 | _M_construct(__s, __s + __n, std::forward_iterator_tag()); |
| 693 | } |
| 694 | |
| 695 | /** |
| 696 | * @brief Construct string as copy of a C string. |
| 697 | * @param __s Source C string. |
| 698 | * @param __a Allocator to use (default is default allocator). |
| 699 | */ |
| 700 | #if __cpp_deduction_guides201703L && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS |
| 701 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
| 702 | // 3076. basic_string CTAD ambiguity |
| 703 | template<typename = _RequireAllocator<_Alloc>> |
| 704 | #endif |
| 705 | _GLIBCXX20_CONSTEXPR |
| 706 | basic_string(const _CharT* __s, const _Alloc& __a = _Alloc()) |
| 707 | : _M_dataplus(_M_local_data(), __a) |
| 708 | { |
| 709 | // NB: Not required, but considered best practice. |
| 710 | if (__s == 0) |
| 711 | std::__throw_logic_error(__N("basic_string: "("basic_string: " "construction from null is not valid") |
| 712 | "construction from null is not valid")("basic_string: " "construction from null is not valid")); |
| 713 | const _CharT* __end = __s + traits_type::length(__s); |
| 714 | _M_construct(__s, __end, forward_iterator_tag()); |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * @brief Construct string as multiple characters. |
| 719 | * @param __n Number of characters. |
| 720 | * @param __c Character to use. |
| 721 | * @param __a Allocator to use (default is default allocator). |
| 722 | */ |
| 723 | #if __cpp_deduction_guides201703L && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS |
| 724 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
| 725 | // 3076. basic_string CTAD ambiguity |
| 726 | template<typename = _RequireAllocator<_Alloc>> |
| 727 | #endif |
| 728 | _GLIBCXX20_CONSTEXPR |
| 729 | basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()) |
| 730 | : _M_dataplus(_M_local_data(), __a) |
| 731 | { _M_construct(__n, __c); } |
| 732 | |
| 733 | #if __cplusplus201703L >= 201103L |
| 734 | /** |
| 735 | * @brief Move construct string. |
| 736 | * @param __str Source string. |
| 737 | * |
| 738 | * The newly-created string contains the exact contents of @a __str. |
| 739 | * @a __str is a valid, but unspecified string. |
| 740 | */ |
| 741 | _GLIBCXX20_CONSTEXPR |
| 742 | basic_string(basic_string&& __str) noexcept |
| 743 | : _M_dataplus(_M_local_data(), std::move(__str._M_get_allocator())) |
| 744 | { |
| 745 | if (__str._M_is_local()) |
| 746 | { |
| 747 | _M_init_local_buf(); |
| 748 | traits_type::copy(_M_local_buf, __str._M_local_buf, |
| 749 | __str.length() + 1); |
| 750 | } |
| 751 | else |
| 752 | { |
| 753 | _M_data(__str._M_data()); |
| 754 | _M_capacity(__str._M_allocated_capacity); |
| 755 | } |
| 756 | |
| 757 | // Must use _M_length() here not _M_set_length() because |
| 758 | // basic_stringbuf relies on writing into unallocated capacity so |
| 759 | // we mess up the contents if we put a '\0' in the string. |
| 760 | _M_length(__str.length()); |
| 761 | __str._M_data(__str._M_use_local_data()); |
| 762 | __str._M_set_length(0); |
| 763 | } |
| 764 | |
| 765 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 766 | /** |
| 767 | * @brief Construct a string from a range. |
| 768 | * @since C++23 |
| 769 | */ |
| 770 | template<__detail::__container_compatible_range<_CharT> _Rg> |
| 771 | constexpr |
| 772 | basic_string(from_range_t, _Rg&& __rg, const _Alloc& __a = _Alloc()) |
| 773 | : basic_string(__a) |
| 774 | { |
| 775 | if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>) |
| 776 | { |
| 777 | const auto __n = static_cast<size_type>(ranges::distance(__rg)); |
| 778 | reserve(__n); |
| 779 | _S_copy_range(_M_data(), std::forward<_Rg>(__rg), __n); |
| 780 | _M_set_length(__n); |
| 781 | } |
| 782 | else |
| 783 | { |
| 784 | auto __first = ranges::begin(__rg); |
| 785 | const auto __last = ranges::end(__rg); |
| 786 | for (; __first != __last; ++__first) |
| 787 | push_back(*__first); |
| 788 | } |
| 789 | } |
| 790 | #endif |
| 791 | |
| 792 | /** |
| 793 | * @brief Construct string from an initializer %list. |
| 794 | * @param __l std::initializer_list of characters. |
| 795 | * @param __a Allocator to use (default is default allocator). |
| 796 | */ |
| 797 | _GLIBCXX20_CONSTEXPR |
| 798 | basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc()) |
| 799 | : _M_dataplus(_M_local_data(), __a) |
| 800 | { _M_construct(__l.begin(), __l.end(), std::forward_iterator_tag()); } |
| 801 | |
| 802 | _GLIBCXX20_CONSTEXPR |
| 803 | basic_string(const basic_string& __str, const _Alloc& __a) |
| 804 | : _M_dataplus(_M_local_data(), __a) |
| 805 | { _M_construct(__str.begin(), __str.end(), std::forward_iterator_tag()); } |
| 806 | |
| 807 | _GLIBCXX20_CONSTEXPR |
| 808 | basic_string(basic_string&& __str, const _Alloc& __a) |
| 809 | noexcept(_Alloc_traits::_S_always_equal()) |
| 810 | : _M_dataplus(_M_local_data(), __a) |
| 811 | { |
| 812 | if (__str._M_is_local()) |
| 813 | { |
| 814 | _M_init_local_buf(); |
| 815 | traits_type::copy(_M_local_buf, __str._M_local_buf, |
| 816 | __str.length() + 1); |
| 817 | _M_length(__str.length()); |
| 818 | __str._M_set_length(0); |
| 819 | } |
| 820 | else if (_Alloc_traits::_S_always_equal() |
| 821 | || __str.get_allocator() == __a) |
| 822 | { |
| 823 | _M_data(__str._M_data()); |
| 824 | _M_length(__str.length()); |
| 825 | _M_capacity(__str._M_allocated_capacity); |
| 826 | __str._M_data(__str._M_use_local_data()); |
| 827 | __str._M_set_length(0); |
| 828 | } |
| 829 | else |
| 830 | _M_construct(__str.begin(), __str.end(), std::forward_iterator_tag()); |
| 831 | } |
| 832 | #endif // C++11 |
| 833 | |
| 834 | #if __cplusplus201703L >= 202100L |
| 835 | basic_string(nullptr_t) = delete; |
| 836 | basic_string& operator=(nullptr_t) = delete; |
| 837 | #endif // C++23 |
| 838 | |
| 839 | /** |
| 840 | * @brief Construct string as copy of a range. |
| 841 | * @param __beg Start of range. |
| 842 | * @param __end End of range. |
| 843 | * @param __a Allocator to use (default is default allocator). |
| 844 | */ |
| 845 | #if __cplusplus201703L >= 201103L |
| 846 | template<typename _InputIterator, |
| 847 | typename = std::_RequireInputIter<_InputIterator>> |
| 848 | #else |
| 849 | template<typename _InputIterator> |
| 850 | #endif |
| 851 | _GLIBCXX20_CONSTEXPR |
| 852 | basic_string(_InputIterator __beg, _InputIterator __end, |
| 853 | const _Alloc& __a = _Alloc()) |
| 854 | : _M_dataplus(_M_local_data(), __a), _M_string_length(0) |
| 855 | { |
| 856 | #if __cplusplus201703L >= 201103L |
| 857 | _M_construct(__beg, __end, std::__iterator_category(__beg)); |
| 858 | #else |
| 859 | typedef typename std::__is_integer<_InputIterator>::__type _Integral; |
| 860 | _M_construct_aux(__beg, __end, _Integral()); |
| 861 | #endif |
| 862 | } |
| 863 | |
| 864 | #ifdef __glibcxx_string_view201803L // >= C++17 |
| 865 | /** |
| 866 | * @brief Construct string from a substring of a string_view. |
| 867 | * @param __t Source object convertible to string view. |
| 868 | * @param __pos The index of the first character to copy from __t. |
| 869 | * @param __n The number of characters to copy from __t. |
| 870 | * @param __a Allocator to use. |
| 871 | */ |
| 872 | template<typename _Tp, |
| 873 | typename = enable_if_t<is_convertible_v<const _Tp&, __sv_type>>> |
| 874 | _GLIBCXX20_CONSTEXPR |
| 875 | basic_string(const _Tp& __t, size_type __pos, size_type __n, |
| 876 | const _Alloc& __a = _Alloc()) |
| 877 | : basic_string(_S_to_string_view(__t).substr(__pos, __n), __a) { } |
| 878 | |
| 879 | /** |
| 880 | * @brief Construct string from a string_view. |
| 881 | * @param __t Source object convertible to string view. |
| 882 | * @param __a Allocator to use (default is default allocator). |
| 883 | */ |
| 884 | template<typename _Tp, typename = _If_sv<_Tp, void>> |
| 885 | _GLIBCXX20_CONSTEXPR |
| 886 | explicit |
| 887 | basic_string(const _Tp& __t, const _Alloc& __a = _Alloc()) |
| 888 | : basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { } |
| 889 | #endif // C++17 |
| 890 | |
| 891 | /** |
| 892 | * @brief Destroy the string instance. |
| 893 | */ |
| 894 | _GLIBCXX20_CONSTEXPR |
| 895 | ~basic_string() |
| 896 | { _M_dispose(); } |
| 897 | |
| 898 | /** |
| 899 | * @brief Assign the value of @a str to this string. |
| 900 | * @param __str Source string. |
| 901 | */ |
| 902 | _GLIBCXX20_CONSTEXPR |
| 903 | basic_string& |
| 904 | operator=(const basic_string& __str) |
| 905 | { |
| 906 | return this->assign(__str); |
| 907 | } |
| 908 | |
| 909 | /** |
| 910 | * @brief Copy contents of @a s into this string. |
| 911 | * @param __s Source null-terminated string. |
| 912 | */ |
| 913 | _GLIBCXX20_CONSTEXPR |
| 914 | basic_string& |
| 915 | operator=(const _CharT* __s) |
| 916 | { return this->assign(__s); } |
| 917 | |
| 918 | /** |
| 919 | * @brief Set value to string of length 1. |
| 920 | * @param __c Source character. |
| 921 | * |
| 922 | * Assigning to a character makes this string length 1 and |
| 923 | * (*this)[0] == @a c. |
| 924 | */ |
| 925 | _GLIBCXX20_CONSTEXPR |
| 926 | basic_string& |
| 927 | operator=(_CharT __c) |
| 928 | { |
| 929 | this->assign(1, __c); |
| 930 | return *this; |
| 931 | } |
| 932 | |
| 933 | #if __cplusplus201703L >= 201103L |
| 934 | /** |
| 935 | * @brief Move assign the value of @a str to this string. |
| 936 | * @param __str Source string. |
| 937 | * |
| 938 | * The contents of @a str are moved into this string (without copying). |
| 939 | * @a str is a valid, but unspecified string. |
| 940 | */ |
| 941 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
| 942 | // 2063. Contradictory requirements for string move assignment |
| 943 | _GLIBCXX20_CONSTEXPR |
| 944 | basic_string& |
| 945 | operator=(basic_string&& __str) |
| 946 | noexcept(_Alloc_traits::_S_nothrow_move()) |
| 947 | { |
| 948 | const bool __equal_allocs = _Alloc_traits::_S_always_equal() |
| 949 | || _M_get_allocator() == __str._M_get_allocator(); |
| 950 | if (!_M_is_local() && _Alloc_traits::_S_propagate_on_move_assign() |
| 951 | && !__equal_allocs) |
| 952 | { |
| 953 | // Destroy existing storage before replacing allocator. |
| 954 | _M_destroy(_M_allocated_capacity); |
| 955 | _M_data(_M_local_data()); |
| 956 | _M_set_length(0); |
| 957 | } |
| 958 | // Replace allocator if POCMA is true. |
| 959 | std::__alloc_on_move(_M_get_allocator(), __str._M_get_allocator()); |
| 960 | |
| 961 | if (__str._M_is_local()) |
| 962 | { |
| 963 | // We've always got room for a short string, just copy it |
| 964 | // (unless this is a self-move, because that would violate the |
| 965 | // char_traits::copy precondition that the ranges don't overlap). |
| 966 | if (__builtin_expect(std::__addressof(__str) != this, true)) |
| 967 | { |
| 968 | if (__str.size()) |
| 969 | this->_S_copy(_M_data(), __str._M_data(), __str.size()); |
| 970 | _M_set_length(__str.size()); |
| 971 | } |
| 972 | } |
| 973 | else if (_Alloc_traits::_S_propagate_on_move_assign() || __equal_allocs) |
| 974 | { |
| 975 | // Just move the allocated pointer, our allocator can free it. |
| 976 | pointer __data = nullptr; |
| 977 | size_type __capacity; |
| 978 | if (!_M_is_local()) |
| 979 | { |
| 980 | if (__equal_allocs) |
| 981 | { |
| 982 | // __str can reuse our existing storage. |
| 983 | __data = _M_data(); |
| 984 | __capacity = _M_allocated_capacity; |
| 985 | } |
| 986 | else // __str can't use it, so free it. |
| 987 | _M_destroy(_M_allocated_capacity); |
| 988 | } |
| 989 | |
| 990 | _M_data(__str._M_data()); |
| 991 | _M_length(__str.length()); |
| 992 | _M_capacity(__str._M_allocated_capacity); |
| 993 | if (__data) |
| 994 | { |
| 995 | __str._M_data(__data); |
| 996 | __str._M_capacity(__capacity); |
| 997 | } |
| 998 | else |
| 999 | __str._M_data(__str._M_use_local_data()); |
| 1000 | } |
| 1001 | else // Need to do a deep copy |
| 1002 | _M_assign(__str); |
| 1003 | __str.clear(); |
| 1004 | return *this; |
| 1005 | } |
| 1006 | |
| 1007 | /** |
| 1008 | * @brief Set value to string constructed from initializer %list. |
| 1009 | * @param __l std::initializer_list. |
| 1010 | */ |
| 1011 | _GLIBCXX20_CONSTEXPR |
| 1012 | basic_string& |
| 1013 | operator=(initializer_list<_CharT> __l) |
| 1014 | { |
| 1015 | this->assign(__l.begin(), __l.size()); |
| 1016 | return *this; |
| 1017 | } |
| 1018 | #endif // C++11 |
| 1019 | |
| 1020 | #ifdef __glibcxx_string_view201803L // >= C++17 |
| 1021 | /** |
| 1022 | * @brief Set value to string constructed from a string_view. |
| 1023 | * @param __svt An object convertible to string_view. |
| 1024 | */ |
| 1025 | template<typename _Tp> |
| 1026 | _GLIBCXX20_CONSTEXPR |
| 1027 | _If_sv<_Tp, basic_string&> |
| 1028 | operator=(const _Tp& __svt) |
| 1029 | { return this->assign(__svt); } |
| 1030 | |
| 1031 | /** |
| 1032 | * @brief Convert to a string_view. |
| 1033 | * @return A string_view. |
| 1034 | */ |
| 1035 | _GLIBCXX20_CONSTEXPR |
| 1036 | operator __sv_type() const noexcept |
| 1037 | { return __sv_type(data(), size()); } |
| 1038 | #endif // C++17 |
| 1039 | |
| 1040 | // Iterators: |
| 1041 | /** |
| 1042 | * Returns a read/write iterator that points to the first character in |
| 1043 | * the %string. |
| 1044 | */ |
| 1045 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1046 | iterator |
| 1047 | begin() _GLIBCXX_NOEXCEPTnoexcept |
| 1048 | { return iterator(_M_data()); } |
| 1049 | |
| 1050 | /** |
| 1051 | * Returns a read-only (constant) iterator that points to the first |
| 1052 | * character in the %string. |
| 1053 | */ |
| 1054 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1055 | const_iterator |
| 1056 | begin() const _GLIBCXX_NOEXCEPTnoexcept |
| 1057 | { return const_iterator(_M_data()); } |
| 1058 | |
| 1059 | /** |
| 1060 | * Returns a read/write iterator that points one past the last |
| 1061 | * character in the %string. |
| 1062 | */ |
| 1063 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1064 | iterator |
| 1065 | end() _GLIBCXX_NOEXCEPTnoexcept |
| 1066 | { return iterator(_M_data() + this->size()); } |
| 1067 | |
| 1068 | /** |
| 1069 | * Returns a read-only (constant) iterator that points one past the |
| 1070 | * last character in the %string. |
| 1071 | */ |
| 1072 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1073 | const_iterator |
| 1074 | end() const _GLIBCXX_NOEXCEPTnoexcept |
| 1075 | { return const_iterator(_M_data() + this->size()); } |
| 1076 | |
| 1077 | /** |
| 1078 | * Returns a read/write reverse iterator that points to the last |
| 1079 | * character in the %string. Iteration is done in reverse element |
| 1080 | * order. |
| 1081 | */ |
| 1082 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1083 | reverse_iterator |
| 1084 | rbegin() _GLIBCXX_NOEXCEPTnoexcept |
| 1085 | { return reverse_iterator(this->end()); } |
| 1086 | |
| 1087 | /** |
| 1088 | * Returns a read-only (constant) reverse iterator that points |
| 1089 | * to the last character in the %string. Iteration is done in |
| 1090 | * reverse element order. |
| 1091 | */ |
| 1092 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1093 | const_reverse_iterator |
| 1094 | rbegin() const _GLIBCXX_NOEXCEPTnoexcept |
| 1095 | { return const_reverse_iterator(this->end()); } |
| 1096 | |
| 1097 | /** |
| 1098 | * Returns a read/write reverse iterator that points to one before the |
| 1099 | * first character in the %string. Iteration is done in reverse |
| 1100 | * element order. |
| 1101 | */ |
| 1102 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1103 | reverse_iterator |
| 1104 | rend() _GLIBCXX_NOEXCEPTnoexcept |
| 1105 | { return reverse_iterator(this->begin()); } |
| 1106 | |
| 1107 | /** |
| 1108 | * Returns a read-only (constant) reverse iterator that points |
| 1109 | * to one before the first character in the %string. Iteration |
| 1110 | * is done in reverse element order. |
| 1111 | */ |
| 1112 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1113 | const_reverse_iterator |
| 1114 | rend() const _GLIBCXX_NOEXCEPTnoexcept |
| 1115 | { return const_reverse_iterator(this->begin()); } |
| 1116 | |
| 1117 | #if __cplusplus201703L >= 201103L |
| 1118 | /** |
| 1119 | * Returns a read-only (constant) iterator that points to the first |
| 1120 | * character in the %string. |
| 1121 | */ |
| 1122 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1123 | const_iterator |
| 1124 | cbegin() const noexcept |
| 1125 | { return const_iterator(this->_M_data()); } |
| 1126 | |
| 1127 | /** |
| 1128 | * Returns a read-only (constant) iterator that points one past the |
| 1129 | * last character in the %string. |
| 1130 | */ |
| 1131 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1132 | const_iterator |
| 1133 | cend() const noexcept |
| 1134 | { return const_iterator(this->_M_data() + this->size()); } |
| 1135 | |
| 1136 | /** |
| 1137 | * Returns a read-only (constant) reverse iterator that points |
| 1138 | * to the last character in the %string. Iteration is done in |
| 1139 | * reverse element order. |
| 1140 | */ |
| 1141 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1142 | const_reverse_iterator |
| 1143 | crbegin() const noexcept |
| 1144 | { return const_reverse_iterator(this->end()); } |
| 1145 | |
| 1146 | /** |
| 1147 | * Returns a read-only (constant) reverse iterator that points |
| 1148 | * to one before the first character in the %string. Iteration |
| 1149 | * is done in reverse element order. |
| 1150 | */ |
| 1151 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1152 | const_reverse_iterator |
| 1153 | crend() const noexcept |
| 1154 | { return const_reverse_iterator(this->begin()); } |
| 1155 | #endif |
| 1156 | |
| 1157 | public: |
| 1158 | // Capacity: |
| 1159 | /// Returns the number of characters in the string, not including any |
| 1160 | /// null-termination. |
| 1161 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1162 | size_type |
| 1163 | size() const _GLIBCXX_NOEXCEPTnoexcept |
| 1164 | { |
| 1165 | size_type __sz = _M_string_length; |
| 1166 | if (__sz > max_size ()) |
| 1167 | __builtin_unreachable (); |
| 1168 | return __sz; |
| 1169 | } |
| 1170 | |
| 1171 | /// Returns the number of characters in the string, not including any |
| 1172 | /// null-termination. |
| 1173 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1174 | size_type |
| 1175 | length() const _GLIBCXX_NOEXCEPTnoexcept |
| 1176 | { return size(); } |
| 1177 | |
| 1178 | /// Returns the size() of the largest possible %string. |
| 1179 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1180 | size_type |
| 1181 | max_size() const _GLIBCXX_NOEXCEPTnoexcept |
| 1182 | { |
| 1183 | const size_t __diffmax |
| 1184 | = __gnu_cxx::__numeric_traits<ptrdiff_t>::__max / sizeof(_CharT); |
| 1185 | const size_t __allocmax = _Alloc_traits::max_size(_M_get_allocator()); |
| 1186 | return (std::min)(__diffmax, __allocmax) - 1; |
| 1187 | } |
| 1188 | |
| 1189 | /** |
| 1190 | * @brief Resizes the %string to the specified number of characters. |
| 1191 | * @param __n Number of characters the %string should contain. |
| 1192 | * @param __c Character to fill any new elements. |
| 1193 | * |
| 1194 | * This function will %resize the %string to the specified |
| 1195 | * number of characters. If the number is smaller than the |
| 1196 | * %string's current size the %string is truncated, otherwise |
| 1197 | * the %string is extended and new elements are %set to @a __c. |
| 1198 | */ |
| 1199 | _GLIBCXX20_CONSTEXPR |
| 1200 | void |
| 1201 | resize(size_type __n, _CharT __c); |
| 1202 | |
| 1203 | /** |
| 1204 | * @brief Resizes the %string to the specified number of characters. |
| 1205 | * @param __n Number of characters the %string should contain. |
| 1206 | * |
| 1207 | * This function will resize the %string to the specified length. If |
| 1208 | * the new size is smaller than the %string's current size the %string |
| 1209 | * is truncated, otherwise the %string is extended and new characters |
| 1210 | * are default-constructed. For basic types such as char, this means |
| 1211 | * setting them to 0. |
| 1212 | */ |
| 1213 | _GLIBCXX20_CONSTEXPR |
| 1214 | void |
| 1215 | resize(size_type __n) |
| 1216 | { this->resize(__n, _CharT()); } |
| 1217 | |
| 1218 | #if __cplusplus201703L >= 201103L |
| 1219 | #pragma GCC diagnostic push |
| 1220 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
| 1221 | /// A non-binding request to reduce capacity() to size(). |
| 1222 | _GLIBCXX20_CONSTEXPR |
| 1223 | void |
| 1224 | shrink_to_fit() noexcept |
| 1225 | { reserve(); } |
| 1226 | #pragma GCC diagnostic pop |
| 1227 | #endif |
| 1228 | |
| 1229 | #ifdef __glibcxx_string_resize_and_overwrite // C++ >= 23 |
| 1230 | /** Resize the string and call a function to fill it. |
| 1231 | * |
| 1232 | * @param __n The maximum size requested. |
| 1233 | * @param __op A callable object that writes characters to the string. |
| 1234 | * |
| 1235 | * This is a low-level function that is easy to misuse, be careful. |
| 1236 | * |
| 1237 | * Calling `str.resize_and_overwrite(n, op)` will reserve at least `n` |
| 1238 | * characters in `str`, evaluate `n2 = std::move(op)(str.data(), n)`, |
| 1239 | * and finally set the string length to `n2` (adding a null terminator |
| 1240 | * at the end). The function object `op` is allowed to write to the |
| 1241 | * extra capacity added by the initial reserve operation, which is not |
| 1242 | * allowed if you just call `str.reserve(n)` yourself. |
| 1243 | * |
| 1244 | * This can be used to efficiently fill a `string` buffer without the |
| 1245 | * overhead of zero-initializing characters that will be overwritten |
| 1246 | * anyway. |
| 1247 | * |
| 1248 | * The callable `op` must not access the string directly (only through |
| 1249 | * the pointer passed as its first argument), must not write more than |
| 1250 | * `n` characters to the string, must return a value no greater than `n`, |
| 1251 | * and must ensure that all characters up to the returned length are |
| 1252 | * valid after it returns (i.e. there must be no uninitialized values |
| 1253 | * left in the string after the call, because accessing them would |
| 1254 | * have undefined behaviour). If `op` exits by throwing an exception |
| 1255 | * the behaviour is undefined. |
| 1256 | * |
| 1257 | * @since C++23 |
| 1258 | */ |
| 1259 | template<typename _Operation> |
| 1260 | constexpr void |
| 1261 | resize_and_overwrite(size_type __n, _Operation __op); |
| 1262 | #endif |
| 1263 | |
| 1264 | #if __cplusplus201703L >= 201103L |
| 1265 | /// Non-standard version of resize_and_overwrite for C++11 and above. |
| 1266 | template<typename _Operation> |
| 1267 | _GLIBCXX20_CONSTEXPR void |
| 1268 | __resize_and_overwrite(size_type __n, _Operation __op); |
| 1269 | #endif |
| 1270 | |
| 1271 | /** |
| 1272 | * Returns the total number of characters that the %string can hold |
| 1273 | * before needing to allocate more memory. |
| 1274 | */ |
| 1275 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1276 | size_type |
| 1277 | capacity() const _GLIBCXX_NOEXCEPTnoexcept |
| 1278 | { |
| 1279 | size_t __sz = _M_is_local() ? size_type(_S_local_capacity) |
| 1280 | : _M_allocated_capacity; |
| 1281 | if (__sz < _S_local_capacity || __sz > max_size ()) |
| 1282 | __builtin_unreachable (); |
| 1283 | return __sz; |
| 1284 | } |
| 1285 | |
| 1286 | /** |
| 1287 | * @brief Attempt to preallocate enough memory for specified number of |
| 1288 | * characters. |
| 1289 | * @param __res_arg Number of characters required. |
| 1290 | * @throw std::length_error If @a __res_arg exceeds @c max_size(). |
| 1291 | * |
| 1292 | * This function attempts to reserve enough memory for the |
| 1293 | * %string to hold the specified number of characters. If the |
| 1294 | * number requested is more than max_size(), length_error is |
| 1295 | * thrown. |
| 1296 | * |
| 1297 | * The advantage of this function is that if optimal code is a |
| 1298 | * necessity and the user can determine the string length that will be |
| 1299 | * required, the user can reserve the memory in %advance, and thus |
| 1300 | * prevent a possible reallocation of memory and copying of %string |
| 1301 | * data. |
| 1302 | */ |
| 1303 | _GLIBCXX20_CONSTEXPR |
| 1304 | void |
| 1305 | reserve(size_type __res_arg); |
| 1306 | |
| 1307 | /** |
| 1308 | * Equivalent to shrink_to_fit(). |
| 1309 | */ |
| 1310 | #if __cplusplus201703L > 201703L |
| 1311 | [[deprecated("use shrink_to_fit() instead")]] |
| 1312 | #endif |
| 1313 | _GLIBCXX20_CONSTEXPR |
| 1314 | void |
| 1315 | reserve(); |
| 1316 | |
| 1317 | /** |
| 1318 | * Erases the string, making it empty. |
| 1319 | */ |
| 1320 | _GLIBCXX20_CONSTEXPR |
| 1321 | void |
| 1322 | clear() _GLIBCXX_NOEXCEPTnoexcept |
| 1323 | { _M_set_length(0); } |
| 1324 | |
| 1325 | /** |
| 1326 | * Returns true if the %string is empty. Equivalent to |
| 1327 | * <code>*this == ""</code>. |
| 1328 | */ |
| 1329 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1330 | bool |
| 1331 | empty() const _GLIBCXX_NOEXCEPTnoexcept |
| 1332 | { return _M_string_length == 0; } |
| 1333 | |
| 1334 | // Element access: |
| 1335 | /** |
| 1336 | * @brief Subscript access to the data contained in the %string. |
| 1337 | * @param __pos The index of the character to access. |
| 1338 | * @return Read-only (constant) reference to the character. |
| 1339 | * |
| 1340 | * This operator allows for easy, array-style, data access. |
| 1341 | * Note that data access with this operator is unchecked and |
| 1342 | * out_of_range lookups are not defined. (For checked lookups |
| 1343 | * see at().) |
| 1344 | */ |
| 1345 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1346 | const_reference |
| 1347 | operator[] (size_type __pos) const _GLIBCXX_NOEXCEPTnoexcept |
| 1348 | { |
| 1349 | __glibcxx_assert(__pos <= size())do { if (__builtin_expect(!bool(__pos <= size()), false)) std ::__glibcxx_assert_fail("/usr/bin/../lib/gcc/x86_64-redhat-linux/15/../../../../include/c++/15/bits/basic_string.h" , 1349, __PRETTY_FUNCTION__, "__pos <= size()"); } while ( false); |
| 1350 | return _M_data()[__pos]; |
| 1351 | } |
| 1352 | |
| 1353 | /** |
| 1354 | * @brief Subscript access to the data contained in the %string. |
| 1355 | * @param __pos The index of the character to access. |
| 1356 | * @return Read/write reference to the character. |
| 1357 | * |
| 1358 | * This operator allows for easy, array-style, data access. |
| 1359 | * Note that data access with this operator is unchecked and |
| 1360 | * out_of_range lookups are not defined. (For checked lookups |
| 1361 | * see at().) |
| 1362 | */ |
| 1363 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1364 | reference |
| 1365 | operator[](size_type __pos) |
| 1366 | { |
| 1367 | // Allow pos == size() both in C++98 mode, as v3 extension, |
| 1368 | // and in C++11 mode. |
| 1369 | __glibcxx_assert(__pos <= size())do { if (__builtin_expect(!bool(__pos <= size()), false)) std ::__glibcxx_assert_fail("/usr/bin/../lib/gcc/x86_64-redhat-linux/15/../../../../include/c++/15/bits/basic_string.h" , 1369, __PRETTY_FUNCTION__, "__pos <= size()"); } while ( false); |
| 1370 | // In pedantic mode be strict in C++98 mode. |
| 1371 | _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos < size()); |
| 1372 | return _M_data()[__pos]; |
| 1373 | } |
| 1374 | |
| 1375 | /** |
| 1376 | * @brief Provides access to the data contained in the %string. |
| 1377 | * @param __n The index of the character to access. |
| 1378 | * @return Read-only (const) reference to the character. |
| 1379 | * @throw std::out_of_range If @a n is an invalid index. |
| 1380 | * |
| 1381 | * This function provides for safer data access. The parameter is |
| 1382 | * first checked that it is in the range of the string. The function |
| 1383 | * throws out_of_range if the check fails. |
| 1384 | */ |
| 1385 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1386 | const_reference |
| 1387 | at(size_type __n) const |
| 1388 | { |
| 1389 | if (__n >= this->size()) |
| 1390 | __throw_out_of_range_fmt(__N("basic_string::at: __n "("basic_string::at: __n " "(which is %zu) >= this->size() " "(which is %zu)") |
| 1391 | "(which is %zu) >= this->size() "("basic_string::at: __n " "(which is %zu) >= this->size() " "(which is %zu)") |
| 1392 | "(which is %zu)")("basic_string::at: __n " "(which is %zu) >= this->size() " "(which is %zu)"), |
| 1393 | __n, this->size()); |
| 1394 | return _M_data()[__n]; |
| 1395 | } |
| 1396 | |
| 1397 | /** |
| 1398 | * @brief Provides access to the data contained in the %string. |
| 1399 | * @param __n The index of the character to access. |
| 1400 | * @return Read/write reference to the character. |
| 1401 | * @throw std::out_of_range If @a n is an invalid index. |
| 1402 | * |
| 1403 | * This function provides for safer data access. The parameter is |
| 1404 | * first checked that it is in the range of the string. The function |
| 1405 | * throws out_of_range if the check fails. |
| 1406 | */ |
| 1407 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1408 | reference |
| 1409 | at(size_type __n) |
| 1410 | { |
| 1411 | if (__n >= size()) |
| 1412 | __throw_out_of_range_fmt(__N("basic_string::at: __n "("basic_string::at: __n " "(which is %zu) >= this->size() " "(which is %zu)") |
| 1413 | "(which is %zu) >= this->size() "("basic_string::at: __n " "(which is %zu) >= this->size() " "(which is %zu)") |
| 1414 | "(which is %zu)")("basic_string::at: __n " "(which is %zu) >= this->size() " "(which is %zu)"), |
| 1415 | __n, this->size()); |
| 1416 | return _M_data()[__n]; |
| 1417 | } |
| 1418 | |
| 1419 | #if __cplusplus201703L >= 201103L |
| 1420 | /** |
| 1421 | * Returns a read/write reference to the data at the first |
| 1422 | * element of the %string. |
| 1423 | */ |
| 1424 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1425 | reference |
| 1426 | front() noexcept |
| 1427 | { |
| 1428 | __glibcxx_assert(!empty())do { if (__builtin_expect(!bool(!empty()), false)) std::__glibcxx_assert_fail ("/usr/bin/../lib/gcc/x86_64-redhat-linux/15/../../../../include/c++/15/bits/basic_string.h" , 1428, __PRETTY_FUNCTION__, "!empty()"); } while (false); |
| 1429 | return operator[](0); |
| 1430 | } |
| 1431 | |
| 1432 | /** |
| 1433 | * Returns a read-only (constant) reference to the data at the first |
| 1434 | * element of the %string. |
| 1435 | */ |
| 1436 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1437 | const_reference |
| 1438 | front() const noexcept |
| 1439 | { |
| 1440 | __glibcxx_assert(!empty())do { if (__builtin_expect(!bool(!empty()), false)) std::__glibcxx_assert_fail ("/usr/bin/../lib/gcc/x86_64-redhat-linux/15/../../../../include/c++/15/bits/basic_string.h" , 1440, __PRETTY_FUNCTION__, "!empty()"); } while (false); |
| 1441 | return operator[](0); |
| 1442 | } |
| 1443 | |
| 1444 | /** |
| 1445 | * Returns a read/write reference to the data at the last |
| 1446 | * element of the %string. |
| 1447 | */ |
| 1448 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1449 | reference |
| 1450 | back() 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/15/../../../../include/c++/15/bits/basic_string.h" , 1452, __PRETTY_FUNCTION__, "!empty()"); } while (false); |
| 1453 | return operator[](this->size() - 1); |
| 1454 | } |
| 1455 | |
| 1456 | /** |
| 1457 | * Returns a read-only (constant) reference to the data at the |
| 1458 | * last element of the %string. |
| 1459 | */ |
| 1460 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 1461 | const_reference |
| 1462 | back() 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/15/../../../../include/c++/15/bits/basic_string.h" , 1464, __PRETTY_FUNCTION__, "!empty()"); } while (false); |
| 1465 | return operator[](this->size() - 1); |
| 1466 | } |
| 1467 | #endif |
| 1468 | |
| 1469 | // Modifiers: |
| 1470 | /** |
| 1471 | * @brief Append a string to this string. |
| 1472 | * @param __str The string to append. |
| 1473 | * @return Reference to this string. |
| 1474 | */ |
| 1475 | _GLIBCXX20_CONSTEXPR |
| 1476 | basic_string& |
| 1477 | operator+=(const basic_string& __str) |
| 1478 | { return this->append(__str); } |
| 1479 | |
| 1480 | /** |
| 1481 | * @brief Append a C string. |
| 1482 | * @param __s The C string to append. |
| 1483 | * @return Reference to this string. |
| 1484 | */ |
| 1485 | _GLIBCXX20_CONSTEXPR |
| 1486 | basic_string& |
| 1487 | operator+=(const _CharT* __s) |
| 1488 | { return this->append(__s); } |
| 1489 | |
| 1490 | /** |
| 1491 | * @brief Append a character. |
| 1492 | * @param __c The character to append. |
| 1493 | * @return Reference to this string. |
| 1494 | */ |
| 1495 | _GLIBCXX20_CONSTEXPR |
| 1496 | basic_string& |
| 1497 | operator+=(_CharT __c) |
| 1498 | { |
| 1499 | this->push_back(__c); |
| 1500 | return *this; |
| 1501 | } |
| 1502 | |
| 1503 | #if __cplusplus201703L >= 201103L |
| 1504 | /** |
| 1505 | * @brief Append an initializer_list of characters. |
| 1506 | * @param __l The initializer_list of characters to be appended. |
| 1507 | * @return Reference to this string. |
| 1508 | */ |
| 1509 | _GLIBCXX20_CONSTEXPR |
| 1510 | basic_string& |
| 1511 | operator+=(initializer_list<_CharT> __l) |
| 1512 | { return this->append(__l.begin(), __l.size()); } |
| 1513 | #endif // C++11 |
| 1514 | |
| 1515 | #ifdef __glibcxx_string_view201803L // >= C++17 |
| 1516 | /** |
| 1517 | * @brief Append a string_view. |
| 1518 | * @param __svt An object convertible to string_view to be appended. |
| 1519 | * @return Reference to this string. |
| 1520 | */ |
| 1521 | template<typename _Tp> |
| 1522 | _GLIBCXX20_CONSTEXPR |
| 1523 | _If_sv<_Tp, basic_string&> |
| 1524 | operator+=(const _Tp& __svt) |
| 1525 | { return this->append(__svt); } |
| 1526 | #endif // C++17 |
| 1527 | |
| 1528 | /** |
| 1529 | * @brief Append a string to this string. |
| 1530 | * @param __str The string to append. |
| 1531 | * @return Reference to this string. |
| 1532 | */ |
| 1533 | _GLIBCXX20_CONSTEXPR |
| 1534 | basic_string& |
| 1535 | append(const basic_string& __str) |
| 1536 | { return this->append(__str._M_data(), __str.size()); } |
| 1537 | |
| 1538 | /** |
| 1539 | * @brief Append a substring. |
| 1540 | * @param __str The string to append. |
| 1541 | * @param __pos Index of the first character of str to append. |
| 1542 | * @param __n The number of characters to append. |
| 1543 | * @return Reference to this string. |
| 1544 | * @throw std::out_of_range if @a __pos is not a valid index. |
| 1545 | * |
| 1546 | * This function appends @a __n characters from @a __str |
| 1547 | * starting at @a __pos to this string. If @a __n is is larger |
| 1548 | * than the number of available characters in @a __str, the |
| 1549 | * remainder of @a __str is appended. |
| 1550 | */ |
| 1551 | _GLIBCXX20_CONSTEXPR |
| 1552 | basic_string& |
| 1553 | append(const basic_string& __str, size_type __pos, size_type __n = npos) |
| 1554 | { return this->append(__str._M_data() |
| 1555 | + __str._M_check(__pos, "basic_string::append"), |
| 1556 | __str._M_limit(__pos, __n)); } |
| 1557 | |
| 1558 | /** |
| 1559 | * @brief Append a C substring. |
| 1560 | * @param __s The C string to append. |
| 1561 | * @param __n The number of characters to append. |
| 1562 | * @return Reference to this string. |
| 1563 | */ |
| 1564 | _GLIBCXX20_CONSTEXPR |
| 1565 | basic_string& |
| 1566 | append(const _CharT* __s, size_type __n) |
| 1567 | { |
| 1568 | __glibcxx_requires_string_len(__s, __n); |
| 1569 | _M_check_length(size_type(0), __n, "basic_string::append"); |
| 1570 | return _M_append(__s, __n); |
| 1571 | } |
| 1572 | |
| 1573 | /** |
| 1574 | * @brief Append a C string. |
| 1575 | * @param __s The C string to append. |
| 1576 | * @return Reference to this string. |
| 1577 | */ |
| 1578 | _GLIBCXX20_CONSTEXPR |
| 1579 | basic_string& |
| 1580 | append(const _CharT* __s) |
| 1581 | { |
| 1582 | __glibcxx_requires_string(__s); |
| 1583 | const size_type __n = traits_type::length(__s); |
| 1584 | _M_check_length(size_type(0), __n, "basic_string::append"); |
| 1585 | return _M_append(__s, __n); |
| 1586 | } |
| 1587 | |
| 1588 | /** |
| 1589 | * @brief Append multiple characters. |
| 1590 | * @param __n The number of characters to append. |
| 1591 | * @param __c The character to use. |
| 1592 | * @return Reference to this string. |
| 1593 | * |
| 1594 | * Appends __n copies of __c to this string. |
| 1595 | */ |
| 1596 | _GLIBCXX20_CONSTEXPR |
| 1597 | basic_string& |
| 1598 | append(size_type __n, _CharT __c) |
| 1599 | { return _M_replace_aux(this->size(), size_type(0), __n, __c); } |
| 1600 | |
| 1601 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 1602 | /** |
| 1603 | * @brief Append a range to the string. |
| 1604 | * @param __rg A range of values that are convertible to `value_type`. |
| 1605 | * @since C++23 |
| 1606 | * |
| 1607 | * The range `__rg` is allowed to overlap with `*this`. |
| 1608 | */ |
| 1609 | template<__detail::__container_compatible_range<_CharT> _Rg> |
| 1610 | constexpr basic_string& |
| 1611 | append_range(_Rg&& __rg) |
| 1612 | { |
| 1613 | // N.B. __rg may overlap with *this, so we must copy from __rg before |
| 1614 | // existing elements or iterators referring to *this are invalidated. |
| 1615 | // e.g. in s.append_range(views::concat(s, str)), rg overlaps s. |
| 1616 | if constexpr (ranges::forward_range<_Rg> || ranges::sized_range<_Rg>) |
| 1617 | { |
| 1618 | const auto __len = size_type(ranges::distance(__rg)); |
| 1619 | |
| 1620 | // Don't care if this addition wraps around, we check it below: |
| 1621 | const size_type __newlen = size() + __len; |
| 1622 | |
| 1623 | if ((capacity() - size()) >= __len) |
| 1624 | _S_copy_range(_M_data() + size(), std::forward<_Rg>(__rg), |
| 1625 | __len); |
| 1626 | else |
| 1627 | { |
| 1628 | _M_check_length(0, __len, "basic_string::append_range"); |
| 1629 | basic_string __s(_M_get_allocator()); |
| 1630 | __s.reserve(__newlen); |
| 1631 | _S_copy_range(__s._M_data() + size(), std::forward<_Rg>(__rg), |
| 1632 | __len); |
| 1633 | _S_copy(__s._M_data(), _M_data(), size()); |
| 1634 | if (!_M_is_local()) |
| 1635 | _M_destroy(_M_allocated_capacity); |
| 1636 | _M_data(__s._M_data()); |
| 1637 | _M_capacity(__s._M_allocated_capacity); |
| 1638 | __s._M_data(__s._M_local_data()); |
| 1639 | __s._M_length(0); |
| 1640 | } |
| 1641 | _M_set_length(__newlen); // adds null-terminator |
| 1642 | } |
| 1643 | else |
| 1644 | { |
| 1645 | basic_string __s(from_range, std::forward<_Rg>(__rg), |
| 1646 | _M_get_allocator()); |
| 1647 | append(__s); |
| 1648 | } |
| 1649 | return *this; |
| 1650 | } |
| 1651 | #endif |
| 1652 | |
| 1653 | #if __cplusplus201703L >= 201103L |
| 1654 | /** |
| 1655 | * @brief Append an initializer_list of characters. |
| 1656 | * @param __l The initializer_list of characters to append. |
| 1657 | * @return Reference to this string. |
| 1658 | */ |
| 1659 | _GLIBCXX20_CONSTEXPR |
| 1660 | basic_string& |
| 1661 | append(initializer_list<_CharT> __l) |
| 1662 | { return this->append(__l.begin(), __l.size()); } |
| 1663 | #endif // C++11 |
| 1664 | |
| 1665 | /** |
| 1666 | * @brief Append a range of characters. |
| 1667 | * @param __first Iterator referencing the first character to append. |
| 1668 | * @param __last Iterator marking the end of the range. |
| 1669 | * @return Reference to this string. |
| 1670 | * |
| 1671 | * Appends characters in the range [__first,__last) to this string. |
| 1672 | */ |
| 1673 | #if __cplusplus201703L >= 201103L |
| 1674 | template<class _InputIterator, |
| 1675 | typename = std::_RequireInputIter<_InputIterator>> |
| 1676 | _GLIBCXX20_CONSTEXPR |
| 1677 | #else |
| 1678 | template<class _InputIterator> |
| 1679 | #endif |
| 1680 | basic_string& |
| 1681 | append(_InputIterator __first, _InputIterator __last) |
| 1682 | { return this->replace(end(), end(), __first, __last); } |
| 1683 | |
| 1684 | #ifdef __glibcxx_string_view201803L |
| 1685 | /** |
| 1686 | * @brief Append a string_view. |
| 1687 | * @param __svt An object convertible to string_view to be appended. |
| 1688 | * @return Reference to this string. |
| 1689 | */ |
| 1690 | template<typename _Tp> |
| 1691 | _GLIBCXX20_CONSTEXPR |
| 1692 | _If_sv<_Tp, basic_string&> |
| 1693 | append(const _Tp& __svt) |
| 1694 | { |
| 1695 | __sv_type __sv = __svt; |
| 1696 | return this->append(__sv.data(), __sv.size()); |
| 1697 | } |
| 1698 | |
| 1699 | /** |
| 1700 | * @brief Append a range of characters from a string_view. |
| 1701 | * @param __svt An object convertible to string_view to be appended from. |
| 1702 | * @param __pos The position in the string_view to append from. |
| 1703 | * @param __n The number of characters to append from the string_view. |
| 1704 | * @return Reference to this string. |
| 1705 | */ |
| 1706 | template<typename _Tp> |
| 1707 | _GLIBCXX20_CONSTEXPR |
| 1708 | _If_sv<_Tp, basic_string&> |
| 1709 | append(const _Tp& __svt, size_type __pos, size_type __n = npos) |
| 1710 | { |
| 1711 | __sv_type __sv = __svt; |
| 1712 | return _M_append(__sv.data() |
| 1713 | + std::__sv_check(__sv.size(), __pos, "basic_string::append"), |
| 1714 | std::__sv_limit(__sv.size(), __pos, __n)); |
| 1715 | } |
| 1716 | #endif // C++17 |
| 1717 | |
| 1718 | /** |
| 1719 | * @brief Append a single character. |
| 1720 | * @param __c Character to append. |
| 1721 | */ |
| 1722 | _GLIBCXX20_CONSTEXPR |
| 1723 | void |
| 1724 | push_back(_CharT __c) |
| 1725 | { |
| 1726 | const size_type __size = this->size(); |
| 1727 | if (__size + 1 > this->capacity()) |
| 1728 | this->_M_mutate(__size, size_type(0), 0, size_type(1)); |
| 1729 | traits_type::assign(this->_M_data()[__size], __c); |
| 1730 | this->_M_set_length(__size + 1); |
| 1731 | } |
| 1732 | |
| 1733 | /** |
| 1734 | * @brief Set value to contents of another string. |
| 1735 | * @param __str Source string to use. |
| 1736 | * @return Reference to this string. |
| 1737 | */ |
| 1738 | _GLIBCXX20_CONSTEXPR |
| 1739 | basic_string& |
| 1740 | assign(const basic_string& __str) |
| 1741 | { |
| 1742 | #if __cplusplus201703L >= 201103L |
| 1743 | if (_Alloc_traits::_S_propagate_on_copy_assign()) |
| 1744 | { |
| 1745 | if (!_Alloc_traits::_S_always_equal() && !_M_is_local() |
| 1746 | && _M_get_allocator() != __str._M_get_allocator()) |
| 1747 | { |
| 1748 | // Propagating allocator cannot free existing storage so must |
| 1749 | // deallocate it before replacing current allocator. |
| 1750 | if (__str.size() <= _S_local_capacity) |
| 1751 | { |
| 1752 | _M_destroy(_M_allocated_capacity); |
| 1753 | _M_data(_M_use_local_data()); |
| 1754 | _M_set_length(0); |
| 1755 | } |
| 1756 | else |
| 1757 | { |
| 1758 | const auto __len = __str.size(); |
| 1759 | auto __alloc = __str._M_get_allocator(); |
| 1760 | // If this allocation throws there are no effects: |
| 1761 | auto __ptr = _S_allocate(__alloc, __len + 1); |
| 1762 | _M_destroy(_M_allocated_capacity); |
| 1763 | _M_data(__ptr); |
| 1764 | _M_capacity(__len); |
| 1765 | _M_set_length(__len); |
| 1766 | } |
| 1767 | } |
| 1768 | std::__alloc_on_copy(_M_get_allocator(), __str._M_get_allocator()); |
| 1769 | } |
| 1770 | #endif |
| 1771 | this->_M_assign(__str); |
| 1772 | return *this; |
| 1773 | } |
| 1774 | |
| 1775 | #if __cplusplus201703L >= 201103L |
| 1776 | /** |
| 1777 | * @brief Set value to contents of another string. |
| 1778 | * @param __str Source string to use. |
| 1779 | * @return Reference to this string. |
| 1780 | * |
| 1781 | * This function sets this string to the exact contents of @a __str. |
| 1782 | * @a __str is a valid, but unspecified string. |
| 1783 | */ |
| 1784 | _GLIBCXX20_CONSTEXPR |
| 1785 | basic_string& |
| 1786 | assign(basic_string&& __str) |
| 1787 | noexcept(_Alloc_traits::_S_nothrow_move()) |
| 1788 | { |
| 1789 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
| 1790 | // 2063. Contradictory requirements for string move assignment |
| 1791 | return *this = std::move(__str); |
| 1792 | } |
| 1793 | #endif // C++11 |
| 1794 | |
| 1795 | /** |
| 1796 | * @brief Set value to a substring of a string. |
| 1797 | * @param __str The string to use. |
| 1798 | * @param __pos Index of the first character of str. |
| 1799 | * @param __n Number of characters to use. |
| 1800 | * @return Reference to this string. |
| 1801 | * @throw std::out_of_range if @a pos is not a valid index. |
| 1802 | * |
| 1803 | * This function sets this string to the substring of @a __str |
| 1804 | * consisting of @a __n characters at @a __pos. If @a __n is |
| 1805 | * is larger than the number of available characters in @a |
| 1806 | * __str, the remainder of @a __str is used. |
| 1807 | */ |
| 1808 | _GLIBCXX20_CONSTEXPR |
| 1809 | basic_string& |
| 1810 | assign(const basic_string& __str, size_type __pos, size_type __n = npos) |
| 1811 | { return _M_replace(size_type(0), this->size(), __str._M_data() |
| 1812 | + __str._M_check(__pos, "basic_string::assign"), |
| 1813 | __str._M_limit(__pos, __n)); } |
| 1814 | |
| 1815 | /** |
| 1816 | * @brief Set value to a C substring. |
| 1817 | * @param __s The C string to use. |
| 1818 | * @param __n Number of characters to use. |
| 1819 | * @return Reference to this string. |
| 1820 | * |
| 1821 | * This function sets the value of this string to the first @a __n |
| 1822 | * characters of @a __s. If @a __n is is larger than the number of |
| 1823 | * available characters in @a __s, the remainder of @a __s is used. |
| 1824 | */ |
| 1825 | _GLIBCXX20_CONSTEXPR |
| 1826 | basic_string& |
| 1827 | assign(const _CharT* __s, size_type __n) |
| 1828 | { |
| 1829 | __glibcxx_requires_string_len(__s, __n); |
| 1830 | return _M_replace(size_type(0), this->size(), __s, __n); |
| 1831 | } |
| 1832 | |
| 1833 | /** |
| 1834 | * @brief Set value to contents of a C string. |
| 1835 | * @param __s The C string to use. |
| 1836 | * @return Reference to this string. |
| 1837 | * |
| 1838 | * This function sets the value of this string to the value of @a __s. |
| 1839 | * The data is copied, so there is no dependence on @a __s once the |
| 1840 | * function returns. |
| 1841 | */ |
| 1842 | _GLIBCXX20_CONSTEXPR |
| 1843 | basic_string& |
| 1844 | assign(const _CharT* __s) |
| 1845 | { |
| 1846 | __glibcxx_requires_string(__s); |
| 1847 | return _M_replace(size_type(0), this->size(), __s, |
| 1848 | traits_type::length(__s)); |
| 1849 | } |
| 1850 | |
| 1851 | /** |
| 1852 | * @brief Set value to multiple characters. |
| 1853 | * @param __n Length of the resulting string. |
| 1854 | * @param __c The character to use. |
| 1855 | * @return Reference to this string. |
| 1856 | * |
| 1857 | * This function sets the value of this string to @a __n copies of |
| 1858 | * character @a __c. |
| 1859 | */ |
| 1860 | _GLIBCXX20_CONSTEXPR |
| 1861 | basic_string& |
| 1862 | assign(size_type __n, _CharT __c) |
| 1863 | { return _M_replace_aux(size_type(0), this->size(), __n, __c); } |
| 1864 | |
| 1865 | /** |
| 1866 | * @brief Set value to a range of characters. |
| 1867 | * @param __first Iterator referencing the first character to append. |
| 1868 | * @param __last Iterator marking the end of the range. |
| 1869 | * @return Reference to this string. |
| 1870 | * |
| 1871 | * Sets value of string to characters in the range [__first,__last). |
| 1872 | */ |
| 1873 | #if __cplusplus201703L >= 201103L |
| 1874 | #pragma GCC diagnostic push |
| 1875 | #pragma GCC diagnostic ignored "-Wc++17-extensions" |
| 1876 | template<class _InputIterator, |
| 1877 | typename = std::_RequireInputIter<_InputIterator>> |
| 1878 | _GLIBCXX20_CONSTEXPR |
| 1879 | basic_string& |
| 1880 | assign(_InputIterator __first, _InputIterator __last) |
| 1881 | { |
| 1882 | using _IterTraits = iterator_traits<_InputIterator>; |
| 1883 | if constexpr (is_pointer<decltype(std::__niter_base(__first))>::value |
| 1884 | && is_same<typename _IterTraits::value_type, |
| 1885 | _CharT>::value) |
| 1886 | { |
| 1887 | __glibcxx_requires_valid_range(__first, __last); |
| 1888 | return _M_replace(size_type(0), size(), |
| 1889 | std::__niter_base(__first), __last - __first); |
| 1890 | } |
| 1891 | #if __cplusplus201703L >= 202002L |
| 1892 | else if constexpr (contiguous_iterator<_InputIterator> |
| 1893 | && is_same_v<iter_value_t<_InputIterator>, |
| 1894 | _CharT>) |
| 1895 | { |
| 1896 | __glibcxx_requires_valid_range(__first, __last); |
| 1897 | return _M_replace(size_type(0), size(), |
| 1898 | std::to_address(__first), __last - __first); |
| 1899 | } |
| 1900 | #endif |
| 1901 | else |
| 1902 | return *this = basic_string(__first, __last, get_allocator()); |
| 1903 | } |
| 1904 | #pragma GCC diagnostic pop |
| 1905 | #else |
| 1906 | template<class _InputIterator> |
| 1907 | basic_string& |
| 1908 | assign(_InputIterator __first, _InputIterator __last) |
| 1909 | { return this->replace(begin(), end(), __first, __last); } |
| 1910 | #endif |
| 1911 | |
| 1912 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 1913 | /** |
| 1914 | * @brief Assign a range to the string. |
| 1915 | * @param __rg A range of values that are convertible to `value_type`. |
| 1916 | * @since C++23 |
| 1917 | * |
| 1918 | * The range `__rg` is allowed to overlap with `*this`. |
| 1919 | */ |
| 1920 | template<__detail::__container_compatible_range<_CharT> _Rg> |
| 1921 | constexpr basic_string& |
| 1922 | assign_range(_Rg&& __rg) |
| 1923 | { |
| 1924 | basic_string __s(from_range, std::forward<_Rg>(__rg), |
| 1925 | _M_get_allocator()); |
| 1926 | assign(std::move(__s)); |
| 1927 | return *this; |
| 1928 | } |
| 1929 | #endif |
| 1930 | |
| 1931 | #if __cplusplus201703L >= 201103L |
| 1932 | /** |
| 1933 | * @brief Set value to an initializer_list of characters. |
| 1934 | * @param __l The initializer_list of characters to assign. |
| 1935 | * @return Reference to this string. |
| 1936 | */ |
| 1937 | _GLIBCXX20_CONSTEXPR |
| 1938 | basic_string& |
| 1939 | assign(initializer_list<_CharT> __l) |
| 1940 | { |
| 1941 | // The initializer_list array cannot alias the characters in *this |
| 1942 | // so we don't need to use replace to that case. |
| 1943 | const size_type __n = __l.size(); |
| 1944 | if (__n > capacity()) |
| 1945 | *this = basic_string(__l.begin(), __l.end(), get_allocator()); |
| 1946 | else |
| 1947 | { |
| 1948 | if (__n) |
| 1949 | _S_copy(_M_data(), __l.begin(), __n); |
| 1950 | _M_set_length(__n); |
| 1951 | } |
| 1952 | return *this; |
| 1953 | } |
| 1954 | #endif // C++11 |
| 1955 | |
| 1956 | #ifdef __glibcxx_string_view201803L // >= C++17 |
| 1957 | /** |
| 1958 | * @brief Set value from a string_view. |
| 1959 | * @param __svt The source object convertible to string_view. |
| 1960 | * @return Reference to this string. |
| 1961 | */ |
| 1962 | template<typename _Tp> |
| 1963 | _GLIBCXX20_CONSTEXPR |
| 1964 | _If_sv<_Tp, basic_string&> |
| 1965 | assign(const _Tp& __svt) |
| 1966 | { |
| 1967 | __sv_type __sv = __svt; |
| 1968 | return this->assign(__sv.data(), __sv.size()); |
| 1969 | } |
| 1970 | |
| 1971 | /** |
| 1972 | * @brief Set value from a range of characters in a string_view. |
| 1973 | * @param __svt The source object convertible to string_view. |
| 1974 | * @param __pos The position in the string_view to assign from. |
| 1975 | * @param __n The number of characters to assign. |
| 1976 | * @return Reference to this string. |
| 1977 | */ |
| 1978 | template<typename _Tp> |
| 1979 | _GLIBCXX20_CONSTEXPR |
| 1980 | _If_sv<_Tp, basic_string&> |
| 1981 | assign(const _Tp& __svt, size_type __pos, size_type __n = npos) |
| 1982 | { |
| 1983 | __sv_type __sv = __svt; |
| 1984 | return _M_replace(size_type(0), this->size(), |
| 1985 | __sv.data() |
| 1986 | + std::__sv_check(__sv.size(), __pos, "basic_string::assign"), |
| 1987 | std::__sv_limit(__sv.size(), __pos, __n)); |
| 1988 | } |
| 1989 | #endif // C++17 |
| 1990 | |
| 1991 | #if __cplusplus201703L >= 201103L |
| 1992 | /** |
| 1993 | * @brief Insert multiple characters. |
| 1994 | * @param __p Const_iterator referencing location in string to |
| 1995 | * insert at. |
| 1996 | * @param __n Number of characters to insert |
| 1997 | * @param __c The character to insert. |
| 1998 | * @return Iterator referencing the first inserted char. |
| 1999 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2000 | * |
| 2001 | * Inserts @a __n copies of character @a __c starting at the |
| 2002 | * position referenced by iterator @a __p. If adding |
| 2003 | * characters causes the length to exceed max_size(), |
| 2004 | * length_error is thrown. The value of the string doesn't |
| 2005 | * change if an error is thrown. |
| 2006 | */ |
| 2007 | _GLIBCXX20_CONSTEXPR |
| 2008 | iterator |
| 2009 | insert(const_iterator __p, size_type __n, _CharT __c) |
| 2010 | { |
| 2011 | _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); |
| 2012 | const size_type __pos = __p - begin(); |
| 2013 | this->replace(__p, __p, __n, __c); |
| 2014 | return iterator(this->_M_data() + __pos); |
| 2015 | } |
| 2016 | #else |
| 2017 | /** |
| 2018 | * @brief Insert multiple characters. |
| 2019 | * @param __p Iterator referencing location in string to insert at. |
| 2020 | * @param __n Number of characters to insert |
| 2021 | * @param __c The character to insert. |
| 2022 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2023 | * |
| 2024 | * Inserts @a __n copies of character @a __c starting at the |
| 2025 | * position referenced by iterator @a __p. If adding |
| 2026 | * characters causes the length to exceed max_size(), |
| 2027 | * length_error is thrown. The value of the string doesn't |
| 2028 | * change if an error is thrown. |
| 2029 | */ |
| 2030 | void |
| 2031 | insert(iterator __p, size_type __n, _CharT __c) |
| 2032 | { this->replace(__p, __p, __n, __c); } |
| 2033 | #endif |
| 2034 | |
| 2035 | #if __cplusplus201703L >= 201103L |
| 2036 | /** |
| 2037 | * @brief Insert a range of characters. |
| 2038 | * @param __p Const_iterator referencing location in string to |
| 2039 | * insert at. |
| 2040 | * @param __beg Start of range. |
| 2041 | * @param __end End of range. |
| 2042 | * @return Iterator referencing the first inserted char. |
| 2043 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2044 | * |
| 2045 | * Inserts characters in range [beg,end). If adding characters |
| 2046 | * causes the length to exceed max_size(), length_error is |
| 2047 | * thrown. The value of the string doesn't change if an error |
| 2048 | * is thrown. |
| 2049 | */ |
| 2050 | template<class _InputIterator, |
| 2051 | typename = std::_RequireInputIter<_InputIterator>> |
| 2052 | _GLIBCXX20_CONSTEXPR |
| 2053 | iterator |
| 2054 | insert(const_iterator __p, _InputIterator __beg, _InputIterator __end) |
| 2055 | { |
| 2056 | _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); |
| 2057 | const size_type __pos = __p - begin(); |
| 2058 | this->replace(__p, __p, __beg, __end); |
| 2059 | return iterator(this->_M_data() + __pos); |
| 2060 | } |
| 2061 | #else |
| 2062 | /** |
| 2063 | * @brief Insert a range of characters. |
| 2064 | * @param __p Iterator referencing location in string to insert at. |
| 2065 | * @param __beg Start of range. |
| 2066 | * @param __end End of range. |
| 2067 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2068 | * |
| 2069 | * Inserts characters in range [__beg,__end). If adding |
| 2070 | * characters causes the length to exceed max_size(), |
| 2071 | * length_error is thrown. The value of the string doesn't |
| 2072 | * change if an error is thrown. |
| 2073 | */ |
| 2074 | template<class _InputIterator> |
| 2075 | void |
| 2076 | insert(iterator __p, _InputIterator __beg, _InputIterator __end) |
| 2077 | { this->replace(__p, __p, __beg, __end); } |
| 2078 | #endif |
| 2079 | |
| 2080 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 2081 | /** |
| 2082 | * @brief Insert a range into the string. |
| 2083 | * @param __rg A range of values that are convertible to `value_type`. |
| 2084 | * @since C++23 |
| 2085 | * |
| 2086 | * The range `__rg` is allowed to overlap with `*this`. |
| 2087 | */ |
| 2088 | template<__detail::__container_compatible_range<_CharT> _Rg> |
| 2089 | constexpr iterator |
| 2090 | insert_range(const_iterator __p, _Rg&& __rg) |
| 2091 | { |
| 2092 | auto __pos = __p - cbegin(); |
| 2093 | |
| 2094 | if constexpr (ranges::forward_range<_Rg>) |
| 2095 | if (ranges::empty(__rg)) |
| 2096 | return begin() + __pos; |
| 2097 | |
| 2098 | |
| 2099 | if (__p == cend()) |
| 2100 | append_range(std::forward<_Rg>(__rg)); |
| 2101 | else |
| 2102 | { |
| 2103 | basic_string __s(from_range, std::forward<_Rg>(__rg), |
| 2104 | _M_get_allocator()); |
| 2105 | insert(__pos, __s); |
| 2106 | } |
| 2107 | return begin() + __pos; |
| 2108 | } |
| 2109 | #endif |
| 2110 | |
| 2111 | #if __cplusplus201703L >= 201103L |
| 2112 | /** |
| 2113 | * @brief Insert an initializer_list of characters. |
| 2114 | * @param __p Iterator referencing location in string to insert at. |
| 2115 | * @param __l The initializer_list of characters to insert. |
| 2116 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2117 | */ |
| 2118 | _GLIBCXX20_CONSTEXPR |
| 2119 | iterator |
| 2120 | insert(const_iterator __p, initializer_list<_CharT> __l) |
| 2121 | { return this->insert(__p, __l.begin(), __l.end()); } |
| 2122 | |
| 2123 | #ifdef _GLIBCXX_DEFINING_STRING_INSTANTIATIONS |
| 2124 | // See PR libstdc++/83328 |
| 2125 | void |
| 2126 | insert(iterator __p, initializer_list<_CharT> __l) |
| 2127 | { |
| 2128 | _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); |
| 2129 | this->insert(__p - begin(), __l.begin(), __l.size()); |
| 2130 | } |
| 2131 | #endif |
| 2132 | #endif // C++11 |
| 2133 | |
| 2134 | /** |
| 2135 | * @brief Insert value of a string. |
| 2136 | * @param __pos1 Position in string to insert at. |
| 2137 | * @param __str The string to insert. |
| 2138 | * @return Reference to this string. |
| 2139 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2140 | * |
| 2141 | * Inserts value of @a __str starting at @a __pos1. If adding |
| 2142 | * characters causes the length to exceed max_size(), |
| 2143 | * length_error is thrown. The value of the string doesn't |
| 2144 | * change if an error is thrown. |
| 2145 | */ |
| 2146 | _GLIBCXX20_CONSTEXPR |
| 2147 | basic_string& |
| 2148 | insert(size_type __pos1, const basic_string& __str) |
| 2149 | { return this->replace(__pos1, size_type(0), |
| 2150 | __str._M_data(), __str.size()); } |
| 2151 | |
| 2152 | /** |
| 2153 | * @brief Insert a substring. |
| 2154 | * @param __pos1 Position in string to insert at. |
| 2155 | * @param __str The string to insert. |
| 2156 | * @param __pos2 Start of characters in str to insert. |
| 2157 | * @param __n Number of characters to insert. |
| 2158 | * @return Reference to this string. |
| 2159 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2160 | * @throw std::out_of_range If @a pos1 > size() or |
| 2161 | * @a __pos2 > @a str.size(). |
| 2162 | * |
| 2163 | * Starting at @a pos1, insert @a __n character of @a __str |
| 2164 | * beginning with @a __pos2. If adding characters causes the |
| 2165 | * length to exceed max_size(), length_error is thrown. If @a |
| 2166 | * __pos1 is beyond the end of this string or @a __pos2 is |
| 2167 | * beyond the end of @a __str, out_of_range is thrown. The |
| 2168 | * value of the string doesn't change if an error is thrown. |
| 2169 | */ |
| 2170 | _GLIBCXX20_CONSTEXPR |
| 2171 | basic_string& |
| 2172 | insert(size_type __pos1, const basic_string& __str, |
| 2173 | size_type __pos2, size_type __n = npos) |
| 2174 | { return this->replace(__pos1, size_type(0), __str._M_data() |
| 2175 | + __str._M_check(__pos2, "basic_string::insert"), |
| 2176 | __str._M_limit(__pos2, __n)); } |
| 2177 | |
| 2178 | /** |
| 2179 | * @brief Insert a C substring. |
| 2180 | * @param __pos Position in string to insert at. |
| 2181 | * @param __s The C string to insert. |
| 2182 | * @param __n The number of characters to insert. |
| 2183 | * @return Reference to this string. |
| 2184 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2185 | * @throw std::out_of_range If @a __pos is beyond the end of this |
| 2186 | * string. |
| 2187 | * |
| 2188 | * Inserts the first @a __n characters of @a __s starting at @a |
| 2189 | * __pos. If adding characters causes the length to exceed |
| 2190 | * max_size(), length_error is thrown. If @a __pos is beyond |
| 2191 | * end(), out_of_range is thrown. The value of the string |
| 2192 | * doesn't change if an error is thrown. |
| 2193 | */ |
| 2194 | _GLIBCXX20_CONSTEXPR |
| 2195 | basic_string& |
| 2196 | insert(size_type __pos, const _CharT* __s, size_type __n) |
| 2197 | { return this->replace(__pos, size_type(0), __s, __n); } |
| 2198 | |
| 2199 | /** |
| 2200 | * @brief Insert a C string. |
| 2201 | * @param __pos Position in string to insert at. |
| 2202 | * @param __s The C string to insert. |
| 2203 | * @return Reference to this string. |
| 2204 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2205 | * @throw std::out_of_range If @a pos is beyond the end of this |
| 2206 | * string. |
| 2207 | * |
| 2208 | * Inserts the first @a n characters of @a __s starting at @a __pos. If |
| 2209 | * adding characters causes the length to exceed max_size(), |
| 2210 | * length_error is thrown. If @a __pos is beyond end(), out_of_range is |
| 2211 | * thrown. The value of the string doesn't change if an error is |
| 2212 | * thrown. |
| 2213 | */ |
| 2214 | _GLIBCXX20_CONSTEXPR |
| 2215 | basic_string& |
| 2216 | insert(size_type __pos, const _CharT* __s) |
| 2217 | { |
| 2218 | __glibcxx_requires_string(__s); |
| 2219 | return this->replace(__pos, size_type(0), __s, |
| 2220 | traits_type::length(__s)); |
| 2221 | } |
| 2222 | |
| 2223 | /** |
| 2224 | * @brief Insert multiple characters. |
| 2225 | * @param __pos Index in string to insert at. |
| 2226 | * @param __n Number of characters to insert |
| 2227 | * @param __c The character to insert. |
| 2228 | * @return Reference to this string. |
| 2229 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2230 | * @throw std::out_of_range If @a __pos is beyond the end of this |
| 2231 | * string. |
| 2232 | * |
| 2233 | * Inserts @a __n copies of character @a __c starting at index |
| 2234 | * @a __pos. If adding characters causes the length to exceed |
| 2235 | * max_size(), length_error is thrown. If @a __pos > length(), |
| 2236 | * out_of_range is thrown. The value of the string doesn't |
| 2237 | * change if an error is thrown. |
| 2238 | */ |
| 2239 | _GLIBCXX20_CONSTEXPR |
| 2240 | basic_string& |
| 2241 | insert(size_type __pos, size_type __n, _CharT __c) |
| 2242 | { return _M_replace_aux(_M_check(__pos, "basic_string::insert"), |
| 2243 | size_type(0), __n, __c); } |
| 2244 | |
| 2245 | /** |
| 2246 | * @brief Insert one character. |
| 2247 | * @param __p Iterator referencing position in string to insert at. |
| 2248 | * @param __c The character to insert. |
| 2249 | * @return Iterator referencing newly inserted char. |
| 2250 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2251 | * |
| 2252 | * Inserts character @a __c at position referenced by @a __p. |
| 2253 | * If adding character causes the length to exceed max_size(), |
| 2254 | * length_error is thrown. If @a __p is beyond end of string, |
| 2255 | * out_of_range is thrown. The value of the string doesn't |
| 2256 | * change if an error is thrown. |
| 2257 | */ |
| 2258 | _GLIBCXX20_CONSTEXPR |
| 2259 | iterator |
| 2260 | insert(__const_iterator __p, _CharT __c) |
| 2261 | { |
| 2262 | _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); |
| 2263 | const size_type __pos = __p - begin(); |
| 2264 | _M_replace_aux(__pos, size_type(0), size_type(1), __c); |
| 2265 | return iterator(_M_data() + __pos); |
| 2266 | } |
| 2267 | |
| 2268 | #ifdef __glibcxx_string_view201803L // >= C++17 |
| 2269 | /** |
| 2270 | * @brief Insert a string_view. |
| 2271 | * @param __pos Position in string to insert at. |
| 2272 | * @param __svt The object convertible to string_view to insert. |
| 2273 | * @return Reference to this string. |
| 2274 | */ |
| 2275 | template<typename _Tp> |
| 2276 | _GLIBCXX20_CONSTEXPR |
| 2277 | _If_sv<_Tp, basic_string&> |
| 2278 | insert(size_type __pos, const _Tp& __svt) |
| 2279 | { |
| 2280 | __sv_type __sv = __svt; |
| 2281 | return this->insert(__pos, __sv.data(), __sv.size()); |
| 2282 | } |
| 2283 | |
| 2284 | /** |
| 2285 | * @brief Insert a string_view. |
| 2286 | * @param __pos1 Position in string to insert at. |
| 2287 | * @param __svt The object convertible to string_view to insert from. |
| 2288 | * @param __pos2 Start of characters in str to insert. |
| 2289 | * @param __n The number of characters to insert. |
| 2290 | * @return Reference to this string. |
| 2291 | */ |
| 2292 | template<typename _Tp> |
| 2293 | _GLIBCXX20_CONSTEXPR |
| 2294 | _If_sv<_Tp, basic_string&> |
| 2295 | insert(size_type __pos1, const _Tp& __svt, |
| 2296 | size_type __pos2, size_type __n = npos) |
| 2297 | { |
| 2298 | __sv_type __sv = __svt; |
| 2299 | return this->replace(__pos1, size_type(0), |
| 2300 | __sv.data() |
| 2301 | + std::__sv_check(__sv.size(), __pos2, "basic_string::insert"), |
| 2302 | std::__sv_limit(__sv.size(), __pos2, __n)); |
| 2303 | } |
| 2304 | #endif // C++17 |
| 2305 | |
| 2306 | /** |
| 2307 | * @brief Remove characters. |
| 2308 | * @param __pos Index of first character to remove (default 0). |
| 2309 | * @param __n Number of characters to remove (default remainder). |
| 2310 | * @return Reference to this string. |
| 2311 | * @throw std::out_of_range If @a pos is beyond the end of this |
| 2312 | * string. |
| 2313 | * |
| 2314 | * Removes @a __n characters from this string starting at @a |
| 2315 | * __pos. The length of the string is reduced by @a __n. If |
| 2316 | * there are < @a __n characters to remove, the remainder of |
| 2317 | * the string is truncated. If @a __p is beyond end of string, |
| 2318 | * out_of_range is thrown. The value of the string doesn't |
| 2319 | * change if an error is thrown. |
| 2320 | */ |
| 2321 | _GLIBCXX20_CONSTEXPR |
| 2322 | basic_string& |
| 2323 | erase(size_type __pos = 0, size_type __n = npos) |
| 2324 | { |
| 2325 | _M_check(__pos, "basic_string::erase"); |
| 2326 | if (__n == npos) |
| 2327 | this->_M_set_length(__pos); |
| 2328 | else if (__n != 0) |
| 2329 | this->_M_erase(__pos, _M_limit(__pos, __n)); |
| 2330 | return *this; |
| 2331 | } |
| 2332 | |
| 2333 | /** |
| 2334 | * @brief Remove one character. |
| 2335 | * @param __position Iterator referencing the character to remove. |
| 2336 | * @return iterator referencing same location after removal. |
| 2337 | * |
| 2338 | * Removes the character at @a __position from this string. The value |
| 2339 | * of the string doesn't change if an error is thrown. |
| 2340 | */ |
| 2341 | _GLIBCXX20_CONSTEXPR |
| 2342 | iterator |
| 2343 | erase(__const_iterator __position) |
| 2344 | { |
| 2345 | _GLIBCXX_DEBUG_PEDASSERT(__position >= begin() |
| 2346 | && __position < end()); |
| 2347 | const size_type __pos = __position - begin(); |
| 2348 | this->_M_erase(__pos, size_type(1)); |
| 2349 | return iterator(_M_data() + __pos); |
| 2350 | } |
| 2351 | |
| 2352 | /** |
| 2353 | * @brief Remove a range of characters. |
| 2354 | * @param __first Iterator referencing the first character to remove. |
| 2355 | * @param __last Iterator referencing the end of the range. |
| 2356 | * @return Iterator referencing location of first after removal. |
| 2357 | * |
| 2358 | * Removes the characters in the range [first,last) from this string. |
| 2359 | * The value of the string doesn't change if an error is thrown. |
| 2360 | */ |
| 2361 | _GLIBCXX20_CONSTEXPR |
| 2362 | iterator |
| 2363 | erase(__const_iterator __first, __const_iterator __last) |
| 2364 | { |
| 2365 | _GLIBCXX_DEBUG_PEDASSERT(__first >= begin() && __first <= __last |
| 2366 | && __last <= end()); |
| 2367 | const size_type __pos = __first - begin(); |
| 2368 | if (__last == end()) |
| 2369 | this->_M_set_length(__pos); |
| 2370 | else |
| 2371 | this->_M_erase(__pos, __last - __first); |
| 2372 | return iterator(this->_M_data() + __pos); |
| 2373 | } |
| 2374 | |
| 2375 | #if __cplusplus201703L >= 201103L |
| 2376 | /** |
| 2377 | * @brief Remove the last character. |
| 2378 | * |
| 2379 | * The string must be non-empty. |
| 2380 | */ |
| 2381 | _GLIBCXX20_CONSTEXPR |
| 2382 | void |
| 2383 | pop_back() noexcept |
| 2384 | { |
| 2385 | __glibcxx_assert(!empty())do { if (__builtin_expect(!bool(!empty()), false)) std::__glibcxx_assert_fail ("/usr/bin/../lib/gcc/x86_64-redhat-linux/15/../../../../include/c++/15/bits/basic_string.h" , 2385, __PRETTY_FUNCTION__, "!empty()"); } while (false); |
| 2386 | _M_erase(size() - 1, 1); |
| 2387 | } |
| 2388 | #endif // C++11 |
| 2389 | |
| 2390 | /** |
| 2391 | * @brief Replace characters with value from another string. |
| 2392 | * @param __pos Index of first character to replace. |
| 2393 | * @param __n Number of characters to be replaced. |
| 2394 | * @param __str String to insert. |
| 2395 | * @return Reference to this string. |
| 2396 | * @throw std::out_of_range If @a pos is beyond the end of this |
| 2397 | * string. |
| 2398 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2399 | * |
| 2400 | * Removes the characters in the range [__pos,__pos+__n) from |
| 2401 | * this string. In place, the value of @a __str is inserted. |
| 2402 | * If @a __pos is beyond end of string, out_of_range is thrown. |
| 2403 | * If the length of the result exceeds max_size(), length_error |
| 2404 | * is thrown. The value of the string doesn't change if an |
| 2405 | * error is thrown. |
| 2406 | */ |
| 2407 | _GLIBCXX20_CONSTEXPR |
| 2408 | basic_string& |
| 2409 | replace(size_type __pos, size_type __n, const basic_string& __str) |
| 2410 | { return this->replace(__pos, __n, __str._M_data(), __str.size()); } |
| 2411 | |
| 2412 | /** |
| 2413 | * @brief Replace characters with value from another string. |
| 2414 | * @param __pos1 Index of first character to replace. |
| 2415 | * @param __n1 Number of characters to be replaced. |
| 2416 | * @param __str String to insert. |
| 2417 | * @param __pos2 Index of first character of str to use. |
| 2418 | * @param __n2 Number of characters from str to use. |
| 2419 | * @return Reference to this string. |
| 2420 | * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 > |
| 2421 | * __str.size(). |
| 2422 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2423 | * |
| 2424 | * Removes the characters in the range [__pos1,__pos1 + n) from this |
| 2425 | * string. In place, the value of @a __str is inserted. If @a __pos is |
| 2426 | * beyond end of string, out_of_range is thrown. If the length of the |
| 2427 | * result exceeds max_size(), length_error is thrown. The value of the |
| 2428 | * string doesn't change if an error is thrown. |
| 2429 | */ |
| 2430 | _GLIBCXX20_CONSTEXPR |
| 2431 | basic_string& |
| 2432 | replace(size_type __pos1, size_type __n1, const basic_string& __str, |
| 2433 | size_type __pos2, size_type __n2 = npos) |
| 2434 | { return this->replace(__pos1, __n1, __str._M_data() |
| 2435 | + __str._M_check(__pos2, "basic_string::replace"), |
| 2436 | __str._M_limit(__pos2, __n2)); } |
| 2437 | |
| 2438 | /** |
| 2439 | * @brief Replace characters with value of a C substring. |
| 2440 | * @param __pos Index of first character to replace. |
| 2441 | * @param __n1 Number of characters to be replaced. |
| 2442 | * @param __s C string to insert. |
| 2443 | * @param __n2 Number of characters from @a s to use. |
| 2444 | * @return Reference to this string. |
| 2445 | * @throw std::out_of_range If @a pos1 > size(). |
| 2446 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2447 | * |
| 2448 | * Removes the characters in the range [__pos,__pos + __n1) |
| 2449 | * from this string. In place, the first @a __n2 characters of |
| 2450 | * @a __s are inserted, or all of @a __s if @a __n2 is too large. If |
| 2451 | * @a __pos is beyond end of string, out_of_range is thrown. If |
| 2452 | * the length of result exceeds max_size(), length_error is |
| 2453 | * thrown. The value of the string doesn't change if an error |
| 2454 | * is thrown. |
| 2455 | */ |
| 2456 | _GLIBCXX20_CONSTEXPR |
| 2457 | basic_string& |
| 2458 | replace(size_type __pos, size_type __n1, const _CharT* __s, |
| 2459 | size_type __n2) |
| 2460 | { |
| 2461 | __glibcxx_requires_string_len(__s, __n2); |
| 2462 | return _M_replace(_M_check(__pos, "basic_string::replace"), |
| 2463 | _M_limit(__pos, __n1), __s, __n2); |
| 2464 | } |
| 2465 | |
| 2466 | /** |
| 2467 | * @brief Replace characters with value of a C string. |
| 2468 | * @param __pos Index of first character to replace. |
| 2469 | * @param __n1 Number of characters to be replaced. |
| 2470 | * @param __s C string to insert. |
| 2471 | * @return Reference to this string. |
| 2472 | * @throw std::out_of_range If @a pos > size(). |
| 2473 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2474 | * |
| 2475 | * Removes the characters in the range [__pos,__pos + __n1) |
| 2476 | * from this string. In place, the characters of @a __s are |
| 2477 | * inserted. If @a __pos is beyond end of string, out_of_range |
| 2478 | * is thrown. If the length of result exceeds max_size(), |
| 2479 | * length_error is thrown. The value of the string doesn't |
| 2480 | * change if an error is thrown. |
| 2481 | */ |
| 2482 | _GLIBCXX20_CONSTEXPR |
| 2483 | basic_string& |
| 2484 | replace(size_type __pos, size_type __n1, const _CharT* __s) |
| 2485 | { |
| 2486 | __glibcxx_requires_string(__s); |
| 2487 | return this->replace(__pos, __n1, __s, traits_type::length(__s)); |
| 2488 | } |
| 2489 | |
| 2490 | /** |
| 2491 | * @brief Replace characters with multiple characters. |
| 2492 | * @param __pos Index of first character to replace. |
| 2493 | * @param __n1 Number of characters to be replaced. |
| 2494 | * @param __n2 Number of characters to insert. |
| 2495 | * @param __c Character to insert. |
| 2496 | * @return Reference to this string. |
| 2497 | * @throw std::out_of_range If @a __pos > size(). |
| 2498 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2499 | * |
| 2500 | * Removes the characters in the range [pos,pos + n1) from this |
| 2501 | * string. In place, @a __n2 copies of @a __c are inserted. |
| 2502 | * If @a __pos is beyond end of string, out_of_range is thrown. |
| 2503 | * If the length of result exceeds max_size(), length_error is |
| 2504 | * thrown. The value of the string doesn't change if an error |
| 2505 | * is thrown. |
| 2506 | */ |
| 2507 | _GLIBCXX20_CONSTEXPR |
| 2508 | basic_string& |
| 2509 | replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) |
| 2510 | { return _M_replace_aux(_M_check(__pos, "basic_string::replace"), |
| 2511 | _M_limit(__pos, __n1), __n2, __c); } |
| 2512 | |
| 2513 | /** |
| 2514 | * @brief Replace range of characters with string. |
| 2515 | * @param __i1 Iterator referencing start of range to replace. |
| 2516 | * @param __i2 Iterator referencing end of range to replace. |
| 2517 | * @param __str String value to insert. |
| 2518 | * @return Reference to this string. |
| 2519 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2520 | * |
| 2521 | * Removes the characters in the range [__i1,__i2). In place, |
| 2522 | * the value of @a __str is inserted. If the length of result |
| 2523 | * exceeds max_size(), length_error is thrown. The value of |
| 2524 | * the string doesn't change if an error is thrown. |
| 2525 | */ |
| 2526 | _GLIBCXX20_CONSTEXPR |
| 2527 | basic_string& |
| 2528 | replace(__const_iterator __i1, __const_iterator __i2, |
| 2529 | const basic_string& __str) |
| 2530 | { return this->replace(__i1, __i2, __str._M_data(), __str.size()); } |
| 2531 | |
| 2532 | /** |
| 2533 | * @brief Replace range of characters with C substring. |
| 2534 | * @param __i1 Iterator referencing start of range to replace. |
| 2535 | * @param __i2 Iterator referencing end of range to replace. |
| 2536 | * @param __s C string value to insert. |
| 2537 | * @param __n Number of characters from s to insert. |
| 2538 | * @return Reference to this string. |
| 2539 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2540 | * |
| 2541 | * Removes the characters in the range [__i1,__i2). In place, |
| 2542 | * the first @a __n characters of @a __s are inserted. If the |
| 2543 | * length of result exceeds max_size(), length_error is thrown. |
| 2544 | * The value of the string doesn't change if an error is |
| 2545 | * thrown. |
| 2546 | */ |
| 2547 | _GLIBCXX20_CONSTEXPR |
| 2548 | basic_string& |
| 2549 | replace(__const_iterator __i1, __const_iterator __i2, |
| 2550 | const _CharT* __s, size_type __n) |
| 2551 | { |
| 2552 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
| 2553 | && __i2 <= end()); |
| 2554 | return this->replace(__i1 - begin(), __i2 - __i1, __s, __n); |
| 2555 | } |
| 2556 | |
| 2557 | /** |
| 2558 | * @brief Replace range of characters with C string. |
| 2559 | * @param __i1 Iterator referencing start of range to replace. |
| 2560 | * @param __i2 Iterator referencing end of range to replace. |
| 2561 | * @param __s C string value 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 characters of @a __s are inserted. If the length of |
| 2567 | * result exceeds max_size(), length_error is thrown. The |
| 2568 | * value of the string doesn't change if an error is thrown. |
| 2569 | */ |
| 2570 | _GLIBCXX20_CONSTEXPR |
| 2571 | basic_string& |
| 2572 | replace(__const_iterator __i1, __const_iterator __i2, const _CharT* __s) |
| 2573 | { |
| 2574 | __glibcxx_requires_string(__s); |
| 2575 | return this->replace(__i1, __i2, __s, traits_type::length(__s)); |
| 2576 | } |
| 2577 | |
| 2578 | /** |
| 2579 | * @brief Replace range of characters with multiple characters |
| 2580 | * @param __i1 Iterator referencing start of range to replace. |
| 2581 | * @param __i2 Iterator referencing end of range to replace. |
| 2582 | * @param __n Number of characters to insert. |
| 2583 | * @param __c Character to insert. |
| 2584 | * @return Reference to this string. |
| 2585 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2586 | * |
| 2587 | * Removes the characters in the range [__i1,__i2). In place, |
| 2588 | * @a __n copies of @a __c are inserted. If the length of |
| 2589 | * result exceeds max_size(), length_error is thrown. The |
| 2590 | * value of the string doesn't change if an error is thrown. |
| 2591 | */ |
| 2592 | _GLIBCXX20_CONSTEXPR |
| 2593 | basic_string& |
| 2594 | replace(__const_iterator __i1, __const_iterator __i2, size_type __n, |
| 2595 | _CharT __c) |
| 2596 | { |
| 2597 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
| 2598 | && __i2 <= end()); |
| 2599 | return _M_replace_aux(__i1 - begin(), __i2 - __i1, __n, __c); |
| 2600 | } |
| 2601 | |
| 2602 | /** |
| 2603 | * @brief Replace range of characters with range. |
| 2604 | * @param __i1 Iterator referencing start of range to replace. |
| 2605 | * @param __i2 Iterator referencing end of range to replace. |
| 2606 | * @param __k1 Iterator referencing start of range to insert. |
| 2607 | * @param __k2 Iterator referencing end of range 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 | * characters in the range [__k1,__k2) are inserted. If the |
| 2613 | * length of result exceeds max_size(), length_error is thrown. |
| 2614 | * The value of the string doesn't change if an error is |
| 2615 | * thrown. |
| 2616 | */ |
| 2617 | #if __cplusplus201703L >= 201103L |
| 2618 | template<class _InputIterator, |
| 2619 | typename = std::_RequireInputIter<_InputIterator>> |
| 2620 | _GLIBCXX20_CONSTEXPR |
| 2621 | basic_string& |
| 2622 | replace(const_iterator __i1, const_iterator __i2, |
| 2623 | _InputIterator __k1, _InputIterator __k2) |
| 2624 | { |
| 2625 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
| 2626 | && __i2 <= end()); |
| 2627 | __glibcxx_requires_valid_range(__k1, __k2); |
| 2628 | return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, |
| 2629 | std::__false_type()); |
| 2630 | } |
| 2631 | #else |
| 2632 | template<class _InputIterator> |
| 2633 | #ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST |
| 2634 | typename __enable_if_not_native_iterator<_InputIterator>::__type |
| 2635 | #else |
| 2636 | basic_string& |
| 2637 | #endif |
| 2638 | replace(iterator __i1, iterator __i2, |
| 2639 | _InputIterator __k1, _InputIterator __k2) |
| 2640 | { |
| 2641 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
| 2642 | && __i2 <= end()); |
| 2643 | __glibcxx_requires_valid_range(__k1, __k2); |
| 2644 | typedef typename std::__is_integer<_InputIterator>::__type _Integral; |
| 2645 | return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral()); |
| 2646 | } |
| 2647 | #endif |
| 2648 | |
| 2649 | // Specializations for the common case of pointer and iterator: |
| 2650 | // useful to avoid the overhead of temporary buffering in _M_replace. |
| 2651 | _GLIBCXX20_CONSTEXPR |
| 2652 | basic_string& |
| 2653 | replace(__const_iterator __i1, __const_iterator __i2, |
| 2654 | _CharT* __k1, _CharT* __k2) |
| 2655 | { |
| 2656 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
| 2657 | && __i2 <= end()); |
| 2658 | __glibcxx_requires_valid_range(__k1, __k2); |
| 2659 | return this->replace(__i1 - begin(), __i2 - __i1, |
| 2660 | __k1, __k2 - __k1); |
| 2661 | } |
| 2662 | |
| 2663 | _GLIBCXX20_CONSTEXPR |
| 2664 | basic_string& |
| 2665 | replace(__const_iterator __i1, __const_iterator __i2, |
| 2666 | const _CharT* __k1, const _CharT* __k2) |
| 2667 | { |
| 2668 | _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 |
| 2669 | && __i2 <= end()); |
| 2670 | __glibcxx_requires_valid_range(__k1, __k2); |
| 2671 | return this->replace(__i1 - begin(), __i2 - __i1, |
| 2672 | __k1, __k2 - __k1); |
| 2673 | } |
| 2674 | |
| 2675 | _GLIBCXX20_CONSTEXPR |
| 2676 | basic_string& |
| 2677 | replace(__const_iterator __i1, __const_iterator __i2, |
| 2678 | iterator __k1, iterator __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.base(), __k2 - __k1); |
| 2685 | } |
| 2686 | |
| 2687 | _GLIBCXX20_CONSTEXPR |
| 2688 | basic_string& |
| 2689 | replace(__const_iterator __i1, __const_iterator __i2, |
| 2690 | const_iterator __k1, const_iterator __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.base(), __k2 - __k1); |
| 2697 | } |
| 2698 | |
| 2699 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 2700 | /** |
| 2701 | * @brief Replace part of the string with a range. |
| 2702 | * @param __rg A range of values that are convertible to `value_type`. |
| 2703 | * @since C++23 |
| 2704 | * |
| 2705 | * The range `__rg` is allowed to overlap with `*this`. |
| 2706 | */ |
| 2707 | template<__detail::__container_compatible_range<_CharT> _Rg> |
| 2708 | constexpr basic_string& |
| 2709 | replace_with_range(const_iterator __i1, const_iterator __i2, _Rg&& __rg) |
| 2710 | { |
| 2711 | if (__i1 == cend()) |
| 2712 | append_range(std::forward<_Rg>(__rg)); |
| 2713 | else |
| 2714 | { |
| 2715 | basic_string __s(from_range, std::forward<_Rg>(__rg), |
| 2716 | _M_get_allocator()); |
| 2717 | replace(__i1, __i2, __s); |
| 2718 | } |
| 2719 | return *this; |
| 2720 | } |
| 2721 | #endif |
| 2722 | |
| 2723 | #if __cplusplus201703L >= 201103L |
| 2724 | /** |
| 2725 | * @brief Replace range of characters with initializer_list. |
| 2726 | * @param __i1 Iterator referencing start of range to replace. |
| 2727 | * @param __i2 Iterator referencing end of range to replace. |
| 2728 | * @param __l The initializer_list of characters to insert. |
| 2729 | * @return Reference to this string. |
| 2730 | * @throw std::length_error If new length exceeds @c max_size(). |
| 2731 | * |
| 2732 | * Removes the characters in the range [__i1,__i2). In place, |
| 2733 | * characters in the range [__k1,__k2) are inserted. If the |
| 2734 | * length of result exceeds max_size(), length_error is thrown. |
| 2735 | * The value of the string doesn't change if an error is |
| 2736 | * thrown. |
| 2737 | */ |
| 2738 | _GLIBCXX20_CONSTEXPR |
| 2739 | basic_string& replace(const_iterator __i1, const_iterator __i2, |
| 2740 | initializer_list<_CharT> __l) |
| 2741 | { return this->replace(__i1, __i2, __l.begin(), __l.size()); } |
| 2742 | #endif // C++11 |
| 2743 | |
| 2744 | #ifdef __glibcxx_string_view201803L // >= C++17 |
| 2745 | /** |
| 2746 | * @brief Replace range of characters with string_view. |
| 2747 | * @param __pos The position to replace at. |
| 2748 | * @param __n The number of characters to replace. |
| 2749 | * @param __svt The object convertible to string_view to insert. |
| 2750 | * @return Reference to this string. |
| 2751 | */ |
| 2752 | template<typename _Tp> |
| 2753 | _GLIBCXX20_CONSTEXPR |
| 2754 | _If_sv<_Tp, basic_string&> |
| 2755 | replace(size_type __pos, size_type __n, const _Tp& __svt) |
| 2756 | { |
| 2757 | __sv_type __sv = __svt; |
| 2758 | return this->replace(__pos, __n, __sv.data(), __sv.size()); |
| 2759 | } |
| 2760 | |
| 2761 | /** |
| 2762 | * @brief Replace range of characters with string_view. |
| 2763 | * @param __pos1 The position to replace at. |
| 2764 | * @param __n1 The number of characters to replace. |
| 2765 | * @param __svt The object convertible to string_view to insert from. |
| 2766 | * @param __pos2 The position in the string_view to insert from. |
| 2767 | * @param __n2 The number of characters to insert. |
| 2768 | * @return Reference to this string. |
| 2769 | */ |
| 2770 | template<typename _Tp> |
| 2771 | _GLIBCXX20_CONSTEXPR |
| 2772 | _If_sv<_Tp, basic_string&> |
| 2773 | replace(size_type __pos1, size_type __n1, const _Tp& __svt, |
| 2774 | size_type __pos2, size_type __n2 = npos) |
| 2775 | { |
| 2776 | __sv_type __sv = __svt; |
| 2777 | return this->replace(__pos1, __n1, |
| 2778 | __sv.data() |
| 2779 | + std::__sv_check(__sv.size(), __pos2, "basic_string::replace"), |
| 2780 | std::__sv_limit(__sv.size(), __pos2, __n2)); |
| 2781 | } |
| 2782 | |
| 2783 | /** |
| 2784 | * @brief Replace range of characters with string_view. |
| 2785 | * @param __i1 An iterator referencing the start position |
| 2786 | to replace at. |
| 2787 | * @param __i2 An iterator referencing the end position |
| 2788 | for the replace. |
| 2789 | * @param __svt The object convertible to string_view to insert from. |
| 2790 | * @return Reference to this string. |
| 2791 | */ |
| 2792 | template<typename _Tp> |
| 2793 | _GLIBCXX20_CONSTEXPR |
| 2794 | _If_sv<_Tp, basic_string&> |
| 2795 | replace(const_iterator __i1, const_iterator __i2, const _Tp& __svt) |
| 2796 | { |
| 2797 | __sv_type __sv = __svt; |
| 2798 | return this->replace(__i1 - begin(), __i2 - __i1, __sv); |
| 2799 | } |
| 2800 | #endif // C++17 |
| 2801 | |
| 2802 | private: |
| 2803 | template<class _Integer> |
| 2804 | _GLIBCXX20_CONSTEXPR |
| 2805 | basic_string& |
| 2806 | _M_replace_dispatch(const_iterator __i1, const_iterator __i2, |
| 2807 | _Integer __n, _Integer __val, __true_type) |
| 2808 | { return _M_replace_aux(__i1 - begin(), __i2 - __i1, __n, __val); } |
| 2809 | |
| 2810 | template<class _InputIterator> |
| 2811 | _GLIBCXX20_CONSTEXPR |
| 2812 | basic_string& |
| 2813 | _M_replace_dispatch(const_iterator __i1, const_iterator __i2, |
| 2814 | _InputIterator __k1, _InputIterator __k2, |
| 2815 | __false_type); |
| 2816 | |
| 2817 | _GLIBCXX20_CONSTEXPR |
| 2818 | basic_string& |
| 2819 | _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, |
| 2820 | _CharT __c); |
| 2821 | |
| 2822 | __attribute__((__noinline__, __noclone__, __cold__)) void |
| 2823 | _M_replace_cold(pointer __p, size_type __len1, const _CharT* __s, |
| 2824 | const size_type __len2, const size_type __how_much); |
| 2825 | |
| 2826 | _GLIBCXX20_CONSTEXPR |
| 2827 | basic_string& |
| 2828 | _M_replace(size_type __pos, size_type __len1, const _CharT* __s, |
| 2829 | const size_type __len2); |
| 2830 | |
| 2831 | _GLIBCXX20_CONSTEXPR |
| 2832 | basic_string& |
| 2833 | _M_append(const _CharT* __s, size_type __n); |
| 2834 | |
| 2835 | public: |
| 2836 | |
| 2837 | /** |
| 2838 | * @brief Copy substring into C string. |
| 2839 | * @param __s C string to copy value into. |
| 2840 | * @param __n Number of characters to copy. |
| 2841 | * @param __pos Index of first character to copy. |
| 2842 | * @return Number of characters actually copied |
| 2843 | * @throw std::out_of_range If __pos > size(). |
| 2844 | * |
| 2845 | * Copies up to @a __n characters starting at @a __pos into the |
| 2846 | * C string @a __s. If @a __pos is %greater than size(), |
| 2847 | * out_of_range is thrown. |
| 2848 | */ |
| 2849 | _GLIBCXX20_CONSTEXPR |
| 2850 | size_type |
| 2851 | copy(_CharT* __s, size_type __n, size_type __pos = 0) const; |
| 2852 | |
| 2853 | /** |
| 2854 | * @brief Swap contents with another string. |
| 2855 | * @param __s String to swap with. |
| 2856 | * |
| 2857 | * Exchanges the contents of this string with that of @a __s in constant |
| 2858 | * time. |
| 2859 | */ |
| 2860 | _GLIBCXX20_CONSTEXPR |
| 2861 | void |
| 2862 | swap(basic_string& __s) _GLIBCXX_NOEXCEPTnoexcept; |
| 2863 | |
| 2864 | // String operations: |
| 2865 | /** |
| 2866 | * @brief Return const pointer to null-terminated contents. |
| 2867 | * |
| 2868 | * This is a handle to internal data. Do not modify or dire things may |
| 2869 | * happen. |
| 2870 | */ |
| 2871 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 2872 | const _CharT* |
| 2873 | c_str() const _GLIBCXX_NOEXCEPTnoexcept |
| 2874 | { return _M_data(); } |
| 2875 | |
| 2876 | /** |
| 2877 | * @brief Return const pointer to contents. |
| 2878 | * |
| 2879 | * This is a pointer to internal data. It is undefined to modify |
| 2880 | * the contents through the returned pointer. To get a pointer that |
| 2881 | * allows modifying the contents use @c &str[0] instead, |
| 2882 | * (or in C++17 the non-const @c str.data() overload). |
| 2883 | */ |
| 2884 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 2885 | const _CharT* |
| 2886 | data() const _GLIBCXX_NOEXCEPTnoexcept |
| 2887 | { return _M_data(); } |
| 2888 | |
| 2889 | #if __cplusplus201703L >= 201703L |
| 2890 | /** |
| 2891 | * @brief Return non-const pointer to contents. |
| 2892 | * |
| 2893 | * This is a pointer to the character sequence held by the string. |
| 2894 | * Modifying the characters in the sequence is allowed. |
| 2895 | */ |
| 2896 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 2897 | _CharT* |
| 2898 | data() noexcept |
| 2899 | { return _M_data(); } |
| 2900 | #endif |
| 2901 | |
| 2902 | /** |
| 2903 | * @brief Return copy of allocator used to construct this string. |
| 2904 | */ |
| 2905 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 2906 | allocator_type |
| 2907 | get_allocator() const _GLIBCXX_NOEXCEPTnoexcept |
| 2908 | { return _M_get_allocator(); } |
| 2909 | |
| 2910 | /** |
| 2911 | * @brief Find position of a C substring. |
| 2912 | * @param __s C string to locate. |
| 2913 | * @param __pos Index of character to search from. |
| 2914 | * @param __n Number of characters from @a s to search for. |
| 2915 | * @return Index of start of first occurrence. |
| 2916 | * |
| 2917 | * Starting from @a __pos, searches forward for the first @a |
| 2918 | * __n characters in @a __s within this string. If found, |
| 2919 | * returns the index where it begins. If not found, returns |
| 2920 | * npos. |
| 2921 | */ |
| 2922 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 2923 | size_type |
| 2924 | find(const _CharT* __s, size_type __pos, size_type __n) const |
| 2925 | _GLIBCXX_NOEXCEPTnoexcept; |
| 2926 | |
| 2927 | /** |
| 2928 | * @brief Find position of a string. |
| 2929 | * @param __str String to locate. |
| 2930 | * @param __pos Index of character to search from (default 0). |
| 2931 | * @return Index of start of first occurrence. |
| 2932 | * |
| 2933 | * Starting from @a __pos, searches forward for value of @a __str within |
| 2934 | * this string. If found, returns the index where it begins. If not |
| 2935 | * found, returns npos. |
| 2936 | */ |
| 2937 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 2938 | size_type |
| 2939 | find(const basic_string& __str, size_type __pos = 0) const |
| 2940 | _GLIBCXX_NOEXCEPTnoexcept |
| 2941 | { return this->find(__str.data(), __pos, __str.size()); } |
| 2942 | |
| 2943 | #ifdef __glibcxx_string_view201803L // >= C++17 |
| 2944 | /** |
| 2945 | * @brief Find position of a string_view. |
| 2946 | * @param __svt The object convertible to string_view to locate. |
| 2947 | * @param __pos Index of character to search from (default 0). |
| 2948 | * @return Index of start of first occurrence. |
| 2949 | */ |
| 2950 | template<typename _Tp> |
| 2951 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 2952 | _If_sv<_Tp, size_type> |
| 2953 | find(const _Tp& __svt, size_type __pos = 0) const |
| 2954 | noexcept(is_same<_Tp, __sv_type>::value) |
| 2955 | { |
| 2956 | __sv_type __sv = __svt; |
| 2957 | return this->find(__sv.data(), __pos, __sv.size()); |
| 2958 | } |
| 2959 | #endif // C++17 |
| 2960 | |
| 2961 | /** |
| 2962 | * @brief Find position of a C string. |
| 2963 | * @param __s C string to locate. |
| 2964 | * @param __pos Index of character to search from (default 0). |
| 2965 | * @return Index of start of first occurrence. |
| 2966 | * |
| 2967 | * Starting from @a __pos, searches forward for the value of @a |
| 2968 | * __s within this string. If found, returns the index where |
| 2969 | * it begins. If not found, returns npos. |
| 2970 | */ |
| 2971 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 2972 | size_type |
| 2973 | find(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPTnoexcept |
| 2974 | { |
| 2975 | __glibcxx_requires_string(__s); |
| 2976 | return this->find(__s, __pos, traits_type::length(__s)); |
| 2977 | } |
| 2978 | |
| 2979 | /** |
| 2980 | * @brief Find position of a character. |
| 2981 | * @param __c Character to locate. |
| 2982 | * @param __pos Index of character to search from (default 0). |
| 2983 | * @return Index of first occurrence. |
| 2984 | * |
| 2985 | * Starting from @a __pos, searches forward for @a __c within |
| 2986 | * this string. If found, returns the index where it was |
| 2987 | * found. If not found, returns npos. |
| 2988 | */ |
| 2989 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 2990 | size_type |
| 2991 | find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPTnoexcept; |
| 2992 | |
| 2993 | /** |
| 2994 | * @brief Find last position of a string. |
| 2995 | * @param __str String to locate. |
| 2996 | * @param __pos Index of character to search back from (default end). |
| 2997 | * @return Index of start of last occurrence. |
| 2998 | * |
| 2999 | * Starting from @a __pos, searches backward for value of @a |
| 3000 | * __str within this string. If found, returns the index where |
| 3001 | * it begins. If not found, returns npos. |
| 3002 | */ |
| 3003 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3004 | size_type |
| 3005 | rfind(const basic_string& __str, size_type __pos = npos) const |
| 3006 | _GLIBCXX_NOEXCEPTnoexcept |
| 3007 | { return this->rfind(__str.data(), __pos, __str.size()); } |
| 3008 | |
| 3009 | #ifdef __glibcxx_string_view201803L // >= C++17 |
| 3010 | /** |
| 3011 | * @brief Find last position of a string_view. |
| 3012 | * @param __svt The object convertible to string_view to locate. |
| 3013 | * @param __pos Index of character to search back from (default end). |
| 3014 | * @return Index of start of last occurrence. |
| 3015 | */ |
| 3016 | template<typename _Tp> |
| 3017 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3018 | _If_sv<_Tp, size_type> |
| 3019 | rfind(const _Tp& __svt, size_type __pos = npos) const |
| 3020 | noexcept(is_same<_Tp, __sv_type>::value) |
| 3021 | { |
| 3022 | __sv_type __sv = __svt; |
| 3023 | return this->rfind(__sv.data(), __pos, __sv.size()); |
| 3024 | } |
| 3025 | #endif // C++17 |
| 3026 | |
| 3027 | /** |
| 3028 | * @brief Find last position of a C substring. |
| 3029 | * @param __s C string to locate. |
| 3030 | * @param __pos Index of character to search back from. |
| 3031 | * @param __n Number of characters from s to search for. |
| 3032 | * @return Index of start of last occurrence. |
| 3033 | * |
| 3034 | * Starting from @a __pos, searches backward for the first @a |
| 3035 | * __n characters in @a __s within this string. If found, |
| 3036 | * returns the index where it begins. If not found, returns |
| 3037 | * npos. |
| 3038 | */ |
| 3039 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3040 | size_type |
| 3041 | rfind(const _CharT* __s, size_type __pos, size_type __n) const |
| 3042 | _GLIBCXX_NOEXCEPTnoexcept; |
| 3043 | |
| 3044 | /** |
| 3045 | * @brief Find last position of a C string. |
| 3046 | * @param __s C string to locate. |
| 3047 | * @param __pos Index of character to start search at (default end). |
| 3048 | * @return Index of start of last occurrence. |
| 3049 | * |
| 3050 | * Starting from @a __pos, searches backward for the value of |
| 3051 | * @a __s within this string. If found, returns the index |
| 3052 | * where it begins. If not found, returns npos. |
| 3053 | */ |
| 3054 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3055 | size_type |
| 3056 | rfind(const _CharT* __s, size_type __pos = npos) const |
| 3057 | { |
| 3058 | __glibcxx_requires_string(__s); |
| 3059 | return this->rfind(__s, __pos, traits_type::length(__s)); |
| 3060 | } |
| 3061 | |
| 3062 | /** |
| 3063 | * @brief Find last position of a character. |
| 3064 | * @param __c Character to locate. |
| 3065 | * @param __pos Index of character to search back from (default end). |
| 3066 | * @return Index of last occurrence. |
| 3067 | * |
| 3068 | * Starting from @a __pos, searches backward for @a __c within |
| 3069 | * this string. If found, returns the index where it was |
| 3070 | * found. If not found, returns npos. |
| 3071 | */ |
| 3072 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3073 | size_type |
| 3074 | rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPTnoexcept; |
| 3075 | |
| 3076 | /** |
| 3077 | * @brief Find position of a character of string. |
| 3078 | * @param __str String containing characters to locate. |
| 3079 | * @param __pos Index of character to search from (default 0). |
| 3080 | * @return Index of first occurrence. |
| 3081 | * |
| 3082 | * Starting from @a __pos, searches forward for one of the |
| 3083 | * characters of @a __str within this string. If found, |
| 3084 | * returns the index where it was found. If not found, returns |
| 3085 | * npos. |
| 3086 | */ |
| 3087 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3088 | size_type |
| 3089 | find_first_of(const basic_string& __str, size_type __pos = 0) const |
| 3090 | _GLIBCXX_NOEXCEPTnoexcept |
| 3091 | { return this->find_first_of(__str.data(), __pos, __str.size()); } |
| 3092 | |
| 3093 | #ifdef __glibcxx_string_view201803L // >= C++17 |
| 3094 | /** |
| 3095 | * @brief Find position of a character of a string_view. |
| 3096 | * @param __svt An object convertible to string_view containing |
| 3097 | * characters to locate. |
| 3098 | * @param __pos Index of character to search from (default 0). |
| 3099 | * @return Index of first occurrence. |
| 3100 | */ |
| 3101 | template<typename _Tp> |
| 3102 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3103 | _If_sv<_Tp, size_type> |
| 3104 | find_first_of(const _Tp& __svt, size_type __pos = 0) const |
| 3105 | noexcept(is_same<_Tp, __sv_type>::value) |
| 3106 | { |
| 3107 | __sv_type __sv = __svt; |
| 3108 | return this->find_first_of(__sv.data(), __pos, __sv.size()); |
| 3109 | } |
| 3110 | #endif // C++17 |
| 3111 | |
| 3112 | /** |
| 3113 | * @brief Find position of a character of C substring. |
| 3114 | * @param __s String containing characters to locate. |
| 3115 | * @param __pos Index of character to search from. |
| 3116 | * @param __n Number of characters from s to search for. |
| 3117 | * @return Index of first occurrence. |
| 3118 | * |
| 3119 | * Starting from @a __pos, searches forward for one of the |
| 3120 | * first @a __n characters of @a __s within this string. If |
| 3121 | * found, returns the index where it was found. If not found, |
| 3122 | * returns npos. |
| 3123 | */ |
| 3124 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3125 | size_type |
| 3126 | find_first_of(const _CharT* __s, size_type __pos, size_type __n) const |
| 3127 | _GLIBCXX_NOEXCEPTnoexcept; |
| 3128 | |
| 3129 | /** |
| 3130 | * @brief Find position of a character of C string. |
| 3131 | * @param __s String containing characters to locate. |
| 3132 | * @param __pos Index of character to search from (default 0). |
| 3133 | * @return Index of first occurrence. |
| 3134 | * |
| 3135 | * Starting from @a __pos, searches forward for one of the |
| 3136 | * characters of @a __s within this string. If found, returns |
| 3137 | * the index where it was found. If not found, returns npos. |
| 3138 | */ |
| 3139 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3140 | size_type |
| 3141 | find_first_of(const _CharT* __s, size_type __pos = 0) const |
| 3142 | _GLIBCXX_NOEXCEPTnoexcept |
| 3143 | { |
| 3144 | __glibcxx_requires_string(__s); |
| 3145 | return this->find_first_of(__s, __pos, traits_type::length(__s)); |
| 3146 | } |
| 3147 | |
| 3148 | /** |
| 3149 | * @brief Find position of a character. |
| 3150 | * @param __c Character to locate. |
| 3151 | * @param __pos Index of character to search from (default 0). |
| 3152 | * @return Index of first occurrence. |
| 3153 | * |
| 3154 | * Starting from @a __pos, searches forward for the character |
| 3155 | * @a __c within this string. If found, returns the index |
| 3156 | * where it was found. If not found, returns npos. |
| 3157 | * |
| 3158 | * Note: equivalent to find(__c, __pos). |
| 3159 | */ |
| 3160 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3161 | size_type |
| 3162 | find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPTnoexcept |
| 3163 | { return this->find(__c, __pos); } |
| 3164 | |
| 3165 | /** |
| 3166 | * @brief Find last position of a character of string. |
| 3167 | * @param __str String containing characters to locate. |
| 3168 | * @param __pos Index of character to search back from (default end). |
| 3169 | * @return Index of last occurrence. |
| 3170 | * |
| 3171 | * Starting from @a __pos, searches backward for one of the |
| 3172 | * characters of @a __str within this string. If found, |
| 3173 | * returns the index where it was found. If not found, returns |
| 3174 | * npos. |
| 3175 | */ |
| 3176 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3177 | size_type |
| 3178 | find_last_of(const basic_string& __str, size_type __pos = npos) const |
| 3179 | _GLIBCXX_NOEXCEPTnoexcept |
| 3180 | { return this->find_last_of(__str.data(), __pos, __str.size()); } |
| 3181 | |
| 3182 | #ifdef __glibcxx_string_view201803L // >= C++17 |
| 3183 | /** |
| 3184 | * @brief Find last position of a character of string. |
| 3185 | * @param __svt An object convertible to string_view containing |
| 3186 | * characters to locate. |
| 3187 | * @param __pos Index of character to search back from (default end). |
| 3188 | * @return Index of last occurrence. |
| 3189 | */ |
| 3190 | template<typename _Tp> |
| 3191 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3192 | _If_sv<_Tp, size_type> |
| 3193 | find_last_of(const _Tp& __svt, size_type __pos = npos) const |
| 3194 | noexcept(is_same<_Tp, __sv_type>::value) |
| 3195 | { |
| 3196 | __sv_type __sv = __svt; |
| 3197 | return this->find_last_of(__sv.data(), __pos, __sv.size()); |
| 3198 | } |
| 3199 | #endif // C++17 |
| 3200 | |
| 3201 | /** |
| 3202 | * @brief Find last position of a character of C substring. |
| 3203 | * @param __s C string containing characters to locate. |
| 3204 | * @param __pos Index of character to search back from. |
| 3205 | * @param __n Number of characters from s to search for. |
| 3206 | * @return Index of last occurrence. |
| 3207 | * |
| 3208 | * Starting from @a __pos, searches backward for one of the |
| 3209 | * first @a __n characters of @a __s within this string. If |
| 3210 | * found, returns the index where it was found. If not found, |
| 3211 | * returns npos. |
| 3212 | */ |
| 3213 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3214 | size_type |
| 3215 | find_last_of(const _CharT* __s, size_type __pos, size_type __n) const |
| 3216 | _GLIBCXX_NOEXCEPTnoexcept; |
| 3217 | |
| 3218 | /** |
| 3219 | * @brief Find last position of a character of C string. |
| 3220 | * @param __s C string containing characters to locate. |
| 3221 | * @param __pos Index of character to search back from (default end). |
| 3222 | * @return Index of last occurrence. |
| 3223 | * |
| 3224 | * Starting from @a __pos, searches backward for one of the |
| 3225 | * characters of @a __s within this string. If found, returns |
| 3226 | * the index where it was found. If not found, returns npos. |
| 3227 | */ |
| 3228 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3229 | size_type |
| 3230 | find_last_of(const _CharT* __s, size_type __pos = npos) const |
| 3231 | _GLIBCXX_NOEXCEPTnoexcept |
| 3232 | { |
| 3233 | __glibcxx_requires_string(__s); |
| 3234 | return this->find_last_of(__s, __pos, traits_type::length(__s)); |
| 3235 | } |
| 3236 | |
| 3237 | /** |
| 3238 | * @brief Find last position of a character. |
| 3239 | * @param __c Character to locate. |
| 3240 | * @param __pos Index of character to search back from (default end). |
| 3241 | * @return Index of last occurrence. |
| 3242 | * |
| 3243 | * Starting from @a __pos, searches backward for @a __c within |
| 3244 | * this string. If found, returns the index where it was |
| 3245 | * found. If not found, returns npos. |
| 3246 | * |
| 3247 | * Note: equivalent to rfind(__c, __pos). |
| 3248 | */ |
| 3249 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3250 | size_type |
| 3251 | find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPTnoexcept |
| 3252 | { return this->rfind(__c, __pos); } |
| 3253 | |
| 3254 | /** |
| 3255 | * @brief Find position of a character not in string. |
| 3256 | * @param __str String containing characters to avoid. |
| 3257 | * @param __pos Index of character to search from (default 0). |
| 3258 | * @return Index of first occurrence. |
| 3259 | * |
| 3260 | * Starting from @a __pos, searches forward for a character not contained |
| 3261 | * in @a __str within this string. If found, returns the index where it |
| 3262 | * was found. If not found, returns npos. |
| 3263 | */ |
| 3264 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3265 | size_type |
| 3266 | find_first_not_of(const basic_string& __str, size_type __pos = 0) const |
| 3267 | _GLIBCXX_NOEXCEPTnoexcept |
| 3268 | { return this->find_first_not_of(__str.data(), __pos, __str.size()); } |
| 3269 | |
| 3270 | #ifdef __glibcxx_string_view201803L // >= C++17 |
| 3271 | /** |
| 3272 | * @brief Find position of a character not in a string_view. |
| 3273 | * @param __svt A object convertible to string_view containing |
| 3274 | * characters to avoid. |
| 3275 | * @param __pos Index of character to search from (default 0). |
| 3276 | * @return Index of first occurrence. |
| 3277 | */ |
| 3278 | template<typename _Tp> |
| 3279 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3280 | _If_sv<_Tp, size_type> |
| 3281 | find_first_not_of(const _Tp& __svt, size_type __pos = 0) const |
| 3282 | noexcept(is_same<_Tp, __sv_type>::value) |
| 3283 | { |
| 3284 | __sv_type __sv = __svt; |
| 3285 | return this->find_first_not_of(__sv.data(), __pos, __sv.size()); |
| 3286 | } |
| 3287 | #endif // C++17 |
| 3288 | |
| 3289 | /** |
| 3290 | * @brief Find position of a character not in C substring. |
| 3291 | * @param __s C string containing characters to avoid. |
| 3292 | * @param __pos Index of character to search from. |
| 3293 | * @param __n Number of characters from __s to consider. |
| 3294 | * @return Index of first occurrence. |
| 3295 | * |
| 3296 | * Starting from @a __pos, searches forward for a character not |
| 3297 | * contained in the first @a __n characters of @a __s within |
| 3298 | * this string. If found, returns the index where it was |
| 3299 | * found. If not found, returns npos. |
| 3300 | */ |
| 3301 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3302 | size_type |
| 3303 | find_first_not_of(const _CharT* __s, size_type __pos, |
| 3304 | size_type __n) const _GLIBCXX_NOEXCEPTnoexcept; |
| 3305 | |
| 3306 | /** |
| 3307 | * @brief Find position of a character not in C string. |
| 3308 | * @param __s C string containing characters to avoid. |
| 3309 | * @param __pos Index of character to search from (default 0). |
| 3310 | * @return Index of first occurrence. |
| 3311 | * |
| 3312 | * Starting from @a __pos, searches forward for a character not |
| 3313 | * contained in @a __s within this string. If found, returns |
| 3314 | * the index where it was found. If not found, returns npos. |
| 3315 | */ |
| 3316 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3317 | size_type |
| 3318 | find_first_not_of(const _CharT* __s, size_type __pos = 0) const |
| 3319 | _GLIBCXX_NOEXCEPTnoexcept |
| 3320 | { |
| 3321 | __glibcxx_requires_string(__s); |
| 3322 | return this->find_first_not_of(__s, __pos, traits_type::length(__s)); |
| 3323 | } |
| 3324 | |
| 3325 | /** |
| 3326 | * @brief Find position of a different character. |
| 3327 | * @param __c Character to avoid. |
| 3328 | * @param __pos Index of character to search from (default 0). |
| 3329 | * @return Index of first occurrence. |
| 3330 | * |
| 3331 | * Starting from @a __pos, searches forward for a character |
| 3332 | * other than @a __c within this string. If found, returns the |
| 3333 | * index where it was found. If not found, returns npos. |
| 3334 | */ |
| 3335 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3336 | size_type |
| 3337 | find_first_not_of(_CharT __c, size_type __pos = 0) const |
| 3338 | _GLIBCXX_NOEXCEPTnoexcept; |
| 3339 | |
| 3340 | /** |
| 3341 | * @brief Find last position of a character not in string. |
| 3342 | * @param __str String containing characters to avoid. |
| 3343 | * @param __pos Index of character to search back from (default end). |
| 3344 | * @return Index of last occurrence. |
| 3345 | * |
| 3346 | * Starting from @a __pos, searches backward for a character |
| 3347 | * not contained in @a __str within this string. If found, |
| 3348 | * returns the index where it was found. If not found, returns |
| 3349 | * npos. |
| 3350 | */ |
| 3351 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3352 | size_type |
| 3353 | find_last_not_of(const basic_string& __str, size_type __pos = npos) const |
| 3354 | _GLIBCXX_NOEXCEPTnoexcept |
| 3355 | { return this->find_last_not_of(__str.data(), __pos, __str.size()); } |
| 3356 | |
| 3357 | #ifdef __glibcxx_string_view201803L // >= C++17 |
| 3358 | /** |
| 3359 | * @brief Find last position of a character not in a string_view. |
| 3360 | * @param __svt An object convertible to string_view containing |
| 3361 | * characters to avoid. |
| 3362 | * @param __pos Index of character to search back from (default end). |
| 3363 | * @return Index of last occurrence. |
| 3364 | */ |
| 3365 | template<typename _Tp> |
| 3366 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3367 | _If_sv<_Tp, size_type> |
| 3368 | find_last_not_of(const _Tp& __svt, size_type __pos = npos) const |
| 3369 | noexcept(is_same<_Tp, __sv_type>::value) |
| 3370 | { |
| 3371 | __sv_type __sv = __svt; |
| 3372 | return this->find_last_not_of(__sv.data(), __pos, __sv.size()); |
| 3373 | } |
| 3374 | #endif // C++17 |
| 3375 | |
| 3376 | /** |
| 3377 | * @brief Find last position of a character not in C substring. |
| 3378 | * @param __s C string containing characters to avoid. |
| 3379 | * @param __pos Index of character to search back from. |
| 3380 | * @param __n Number of characters from s to consider. |
| 3381 | * @return Index of last occurrence. |
| 3382 | * |
| 3383 | * Starting from @a __pos, searches backward for a character not |
| 3384 | * contained in the first @a __n characters of @a __s within this string. |
| 3385 | * If found, returns the index where it was found. If not found, |
| 3386 | * returns npos. |
| 3387 | */ |
| 3388 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3389 | size_type |
| 3390 | find_last_not_of(const _CharT* __s, size_type __pos, |
| 3391 | size_type __n) const _GLIBCXX_NOEXCEPTnoexcept; |
| 3392 | /** |
| 3393 | * @brief Find last position of a character not in C string. |
| 3394 | * @param __s C string containing characters to avoid. |
| 3395 | * @param __pos Index of character to search back from (default end). |
| 3396 | * @return Index of last occurrence. |
| 3397 | * |
| 3398 | * Starting from @a __pos, searches backward for a character |
| 3399 | * not contained in @a __s within this string. If found, |
| 3400 | * returns the index where it was found. If not found, returns |
| 3401 | * npos. |
| 3402 | */ |
| 3403 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3404 | size_type |
| 3405 | find_last_not_of(const _CharT* __s, size_type __pos = npos) const |
| 3406 | _GLIBCXX_NOEXCEPTnoexcept |
| 3407 | { |
| 3408 | __glibcxx_requires_string(__s); |
| 3409 | return this->find_last_not_of(__s, __pos, traits_type::length(__s)); |
| 3410 | } |
| 3411 | |
| 3412 | /** |
| 3413 | * @brief Find last position of a different character. |
| 3414 | * @param __c Character to avoid. |
| 3415 | * @param __pos Index of character to search back from (default end). |
| 3416 | * @return Index of last occurrence. |
| 3417 | * |
| 3418 | * Starting from @a __pos, searches backward for a character other than |
| 3419 | * @a __c within this string. If found, returns the index where it was |
| 3420 | * found. If not found, returns npos. |
| 3421 | */ |
| 3422 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3423 | size_type |
| 3424 | find_last_not_of(_CharT __c, size_type __pos = npos) const |
| 3425 | _GLIBCXX_NOEXCEPTnoexcept; |
| 3426 | |
| 3427 | /** |
| 3428 | * @brief Get a substring. |
| 3429 | * @param __pos Index of first character (default 0). |
| 3430 | * @param __n Number of characters in substring (default remainder). |
| 3431 | * @return The new string. |
| 3432 | * @throw std::out_of_range If __pos > size(). |
| 3433 | * |
| 3434 | * Construct and return a new string using the @a __n |
| 3435 | * characters starting at @a __pos. If the string is too |
| 3436 | * short, use the remainder of the characters. If @a __pos is |
| 3437 | * beyond the end of the string, out_of_range is thrown. |
| 3438 | */ |
| 3439 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3440 | basic_string |
| 3441 | substr(size_type __pos = 0, size_type __n = npos) const |
| 3442 | { return basic_string(*this, |
| 3443 | _M_check(__pos, "basic_string::substr"), __n); } |
| 3444 | |
| 3445 | /** |
| 3446 | * @brief Compare to a string. |
| 3447 | * @param __str String to compare against. |
| 3448 | * @return Integer < 0, 0, or > 0. |
| 3449 | * |
| 3450 | * Returns an integer < 0 if this string is ordered before @a |
| 3451 | * __str, 0 if their values are equivalent, or > 0 if this |
| 3452 | * string is ordered after @a __str. Determines the effective |
| 3453 | * length rlen of the strings to compare as the smallest of |
| 3454 | * size() and str.size(). The function then compares the two |
| 3455 | * strings by calling traits::compare(data(), str.data(),rlen). |
| 3456 | * If the result of the comparison is nonzero returns it, |
| 3457 | * otherwise the shorter one is ordered first. |
| 3458 | */ |
| 3459 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3460 | int |
| 3461 | compare(const basic_string& __str) const |
| 3462 | { |
| 3463 | const size_type __size = this->size(); |
| 3464 | const size_type __osize = __str.size(); |
| 3465 | const size_type __len = std::min(__size, __osize); |
| 3466 | |
| 3467 | int __r = traits_type::compare(_M_data(), __str.data(), __len); |
| 3468 | if (!__r) |
| 3469 | __r = _S_compare(__size, __osize); |
| 3470 | return __r; |
| 3471 | } |
| 3472 | |
| 3473 | #ifdef __glibcxx_string_view201803L // >= C++17 |
| 3474 | /** |
| 3475 | * @brief Compare to a string_view. |
| 3476 | * @param __svt An object convertible to string_view to compare against. |
| 3477 | * @return Integer < 0, 0, or > 0. |
| 3478 | */ |
| 3479 | template<typename _Tp> |
| 3480 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3481 | _If_sv<_Tp, int> |
| 3482 | compare(const _Tp& __svt) const |
| 3483 | noexcept(is_same<_Tp, __sv_type>::value) |
| 3484 | { |
| 3485 | __sv_type __sv = __svt; |
| 3486 | const size_type __size = this->size(); |
| 3487 | const size_type __osize = __sv.size(); |
| 3488 | const size_type __len = std::min(__size, __osize); |
| 3489 | |
| 3490 | int __r = traits_type::compare(_M_data(), __sv.data(), __len); |
| 3491 | if (!__r) |
| 3492 | __r = _S_compare(__size, __osize); |
| 3493 | return __r; |
| 3494 | } |
| 3495 | |
| 3496 | /** |
| 3497 | * @brief Compare to a string_view. |
| 3498 | * @param __pos A position in the string to start comparing from. |
| 3499 | * @param __n The number of characters to compare. |
| 3500 | * @param __svt An object convertible to string_view to compare |
| 3501 | * against. |
| 3502 | * @return Integer < 0, 0, or > 0. |
| 3503 | */ |
| 3504 | template<typename _Tp> |
| 3505 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3506 | _If_sv<_Tp, int> |
| 3507 | compare(size_type __pos, size_type __n, const _Tp& __svt) const |
| 3508 | noexcept(is_same<_Tp, __sv_type>::value) |
| 3509 | { |
| 3510 | __sv_type __sv = __svt; |
| 3511 | return __sv_type(*this).substr(__pos, __n).compare(__sv); |
| 3512 | } |
| 3513 | |
| 3514 | /** |
| 3515 | * @brief Compare to a string_view. |
| 3516 | * @param __pos1 A position in the string to start comparing from. |
| 3517 | * @param __n1 The number of characters to compare. |
| 3518 | * @param __svt An object convertible to string_view to compare |
| 3519 | * against. |
| 3520 | * @param __pos2 A position in the string_view to start comparing from. |
| 3521 | * @param __n2 The number of characters to compare. |
| 3522 | * @return Integer < 0, 0, or > 0. |
| 3523 | */ |
| 3524 | template<typename _Tp> |
| 3525 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3526 | _If_sv<_Tp, int> |
| 3527 | compare(size_type __pos1, size_type __n1, const _Tp& __svt, |
| 3528 | size_type __pos2, size_type __n2 = npos) const |
| 3529 | noexcept(is_same<_Tp, __sv_type>::value) |
| 3530 | { |
| 3531 | __sv_type __sv = __svt; |
| 3532 | return __sv_type(*this) |
| 3533 | .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); |
| 3534 | } |
| 3535 | #endif // C++17 |
| 3536 | |
| 3537 | /** |
| 3538 | * @brief Compare substring to a string. |
| 3539 | * @param __pos Index of first character of substring. |
| 3540 | * @param __n Number of characters in substring. |
| 3541 | * @param __str String to compare against. |
| 3542 | * @return Integer < 0, 0, or > 0. |
| 3543 | * |
| 3544 | * Form the substring of this string from the @a __n characters |
| 3545 | * starting at @a __pos. Returns an integer < 0 if the |
| 3546 | * substring is ordered before @a __str, 0 if their values are |
| 3547 | * equivalent, or > 0 if the substring is ordered after @a |
| 3548 | * __str. Determines the effective length rlen of the strings |
| 3549 | * to compare as the smallest of the length of the substring |
| 3550 | * and @a __str.size(). The function then compares the two |
| 3551 | * strings by calling |
| 3552 | * traits::compare(substring.data(),str.data(),rlen). If the |
| 3553 | * result of the comparison is nonzero returns it, otherwise |
| 3554 | * the shorter one is ordered first. |
| 3555 | */ |
| 3556 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3557 | int |
| 3558 | compare(size_type __pos, size_type __n, const basic_string& __str) const |
| 3559 | { |
| 3560 | _M_check(__pos, "basic_string::compare"); |
| 3561 | __n = _M_limit(__pos, __n); |
| 3562 | const size_type __osize = __str.size(); |
| 3563 | const size_type __len = std::min(__n, __osize); |
| 3564 | int __r = traits_type::compare(_M_data() + __pos, __str.data(), __len); |
| 3565 | if (!__r) |
| 3566 | __r = _S_compare(__n, __osize); |
| 3567 | return __r; |
| 3568 | } |
| 3569 | |
| 3570 | /** |
| 3571 | * @brief Compare substring to a substring. |
| 3572 | * @param __pos1 Index of first character of substring. |
| 3573 | * @param __n1 Number of characters in substring. |
| 3574 | * @param __str String to compare against. |
| 3575 | * @param __pos2 Index of first character of substring of str. |
| 3576 | * @param __n2 Number of characters in substring of str. |
| 3577 | * @return Integer < 0, 0, or > 0. |
| 3578 | * |
| 3579 | * Form the substring of this string from the @a __n1 |
| 3580 | * characters starting at @a __pos1. Form the substring of @a |
| 3581 | * __str from the @a __n2 characters starting at @a __pos2. |
| 3582 | * Returns an integer < 0 if this substring is ordered before |
| 3583 | * the substring of @a __str, 0 if their values are equivalent, |
| 3584 | * or > 0 if this substring is ordered after the substring of |
| 3585 | * @a __str. Determines the effective length rlen of the |
| 3586 | * strings to compare as the smallest of the lengths of the |
| 3587 | * substrings. The function then compares the two strings by |
| 3588 | * calling |
| 3589 | * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen). |
| 3590 | * If the result of the comparison is nonzero returns it, |
| 3591 | * otherwise the shorter one is ordered first. |
| 3592 | */ |
| 3593 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3594 | int |
| 3595 | compare(size_type __pos1, size_type __n1, const basic_string& __str, |
| 3596 | size_type __pos2, size_type __n2 = npos) const |
| 3597 | { |
| 3598 | _M_check(__pos1, "basic_string::compare"); |
| 3599 | __str._M_check(__pos2, "basic_string::compare"); |
| 3600 | __n1 = _M_limit(__pos1, __n1); |
| 3601 | __n2 = __str._M_limit(__pos2, __n2); |
| 3602 | const size_type __len = std::min(__n1, __n2); |
| 3603 | int __r = traits_type::compare(_M_data() + __pos1, |
| 3604 | __str.data() + __pos2, __len); |
| 3605 | if (!__r) |
| 3606 | __r = _S_compare(__n1, __n2); |
| 3607 | return __r; |
| 3608 | } |
| 3609 | |
| 3610 | /** |
| 3611 | * @brief Compare to a C string. |
| 3612 | * @param __s C string to compare against. |
| 3613 | * @return Integer < 0, 0, or > 0. |
| 3614 | * |
| 3615 | * Returns an integer < 0 if this string is ordered before @a __s, 0 if |
| 3616 | * their values are equivalent, or > 0 if this string is ordered after |
| 3617 | * @a __s. Determines the effective length rlen of the strings to |
| 3618 | * compare as the smallest of size() and the length of a string |
| 3619 | * constructed from @a __s. The function then compares the two strings |
| 3620 | * by calling traits::compare(data(),s,rlen). If the result of the |
| 3621 | * comparison is nonzero returns it, otherwise the shorter one is |
| 3622 | * ordered first. |
| 3623 | */ |
| 3624 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3625 | int |
| 3626 | compare(const _CharT* __s) const _GLIBCXX_NOEXCEPTnoexcept |
| 3627 | { |
| 3628 | __glibcxx_requires_string(__s); |
| 3629 | const size_type __size = this->size(); |
| 3630 | const size_type __osize = traits_type::length(__s); |
| 3631 | const size_type __len = std::min(__size, __osize); |
| 3632 | int __r = traits_type::compare(_M_data(), __s, __len); |
| 3633 | if (!__r) |
| 3634 | __r = _S_compare(__size, __osize); |
| 3635 | return __r; |
| 3636 | } |
| 3637 | |
| 3638 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
| 3639 | // 5 String::compare specification questionable |
| 3640 | /** |
| 3641 | * @brief Compare substring to a C string. |
| 3642 | * @param __pos Index of first character of substring. |
| 3643 | * @param __n1 Number of characters in substring. |
| 3644 | * @param __s C string to compare against. |
| 3645 | * @return Integer < 0, 0, or > 0. |
| 3646 | * |
| 3647 | * Form the substring of this string from the @a __n1 |
| 3648 | * characters starting at @a pos. Returns an integer < 0 if |
| 3649 | * the substring is ordered before @a __s, 0 if their values |
| 3650 | * are equivalent, or > 0 if the substring is ordered after @a |
| 3651 | * __s. Determines the effective length rlen of the strings to |
| 3652 | * compare as the smallest of the length of the substring and |
| 3653 | * the length of a string constructed from @a __s. The |
| 3654 | * function then compares the two string by calling |
| 3655 | * traits::compare(substring.data(),__s,rlen). If the result of |
| 3656 | * the comparison is nonzero returns it, otherwise the shorter |
| 3657 | * one is ordered first. |
| 3658 | */ |
| 3659 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3660 | int |
| 3661 | compare(size_type __pos, size_type __n1, const _CharT* __s) const |
| 3662 | { |
| 3663 | __glibcxx_requires_string(__s); |
| 3664 | _M_check(__pos, "basic_string::compare"); |
| 3665 | __n1 = _M_limit(__pos, __n1); |
| 3666 | const size_type __osize = traits_type::length(__s); |
| 3667 | const size_type __len = std::min(__n1, __osize); |
| 3668 | int __r = traits_type::compare(_M_data() + __pos, __s, __len); |
| 3669 | if (!__r) |
| 3670 | __r = _S_compare(__n1, __osize); |
| 3671 | return __r; |
| 3672 | } |
| 3673 | |
| 3674 | /** |
| 3675 | * @brief Compare substring against a character %array. |
| 3676 | * @param __pos Index of first character of substring. |
| 3677 | * @param __n1 Number of characters in substring. |
| 3678 | * @param __s character %array to compare against. |
| 3679 | * @param __n2 Number of characters of s. |
| 3680 | * @return Integer < 0, 0, or > 0. |
| 3681 | * |
| 3682 | * Form the substring of this string from the @a __n1 |
| 3683 | * characters starting at @a __pos. Form a string from the |
| 3684 | * first @a __n2 characters of @a __s. Returns an integer < 0 |
| 3685 | * if this substring is ordered before the string from @a __s, |
| 3686 | * 0 if their values are equivalent, or > 0 if this substring |
| 3687 | * is ordered after the string from @a __s. Determines the |
| 3688 | * effective length rlen of the strings to compare as the |
| 3689 | * smallest of the length of the substring and @a __n2. The |
| 3690 | * function then compares the two strings by calling |
| 3691 | * traits::compare(substring.data(),s,rlen). If the result of |
| 3692 | * the comparison is nonzero returns it, otherwise the shorter |
| 3693 | * one is ordered first. |
| 3694 | * |
| 3695 | * NB: s must have at least n2 characters, '\\0' has |
| 3696 | * no special meaning. |
| 3697 | */ |
| 3698 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3699 | int |
| 3700 | compare(size_type __pos, size_type __n1, const _CharT* __s, |
| 3701 | size_type __n2) const |
| 3702 | { |
| 3703 | __glibcxx_requires_string_len(__s, __n2); |
| 3704 | _M_check(__pos, "basic_string::compare"); |
| 3705 | __n1 = _M_limit(__pos, __n1); |
| 3706 | const size_type __len = std::min(__n1, __n2); |
| 3707 | int __r = traits_type::compare(_M_data() + __pos, __s, __len); |
| 3708 | if (!__r) |
| 3709 | __r = _S_compare(__n1, __n2); |
| 3710 | return __r; |
| 3711 | } |
| 3712 | |
| 3713 | #if __cplusplus201703L >= 202002L |
| 3714 | [[nodiscard]] |
| 3715 | constexpr bool |
| 3716 | starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept |
| 3717 | { return __sv_type(this->data(), this->size()).starts_with(__x); } |
| 3718 | |
| 3719 | [[nodiscard]] |
| 3720 | constexpr bool |
| 3721 | starts_with(_CharT __x) const noexcept |
| 3722 | { return __sv_type(this->data(), this->size()).starts_with(__x); } |
| 3723 | |
| 3724 | [[nodiscard, __gnu__::__nonnull__]] |
| 3725 | constexpr bool |
| 3726 | starts_with(const _CharT* __x) const noexcept |
| 3727 | { return __sv_type(this->data(), this->size()).starts_with(__x); } |
| 3728 | |
| 3729 | [[nodiscard]] |
| 3730 | constexpr bool |
| 3731 | ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept |
| 3732 | { return __sv_type(this->data(), this->size()).ends_with(__x); } |
| 3733 | |
| 3734 | [[nodiscard]] |
| 3735 | constexpr bool |
| 3736 | ends_with(_CharT __x) const noexcept |
| 3737 | { return __sv_type(this->data(), this->size()).ends_with(__x); } |
| 3738 | |
| 3739 | [[nodiscard, __gnu__::__nonnull__]] |
| 3740 | constexpr bool |
| 3741 | ends_with(const _CharT* __x) const noexcept |
| 3742 | { return __sv_type(this->data(), this->size()).ends_with(__x); } |
| 3743 | #endif // C++20 |
| 3744 | |
| 3745 | #if __cplusplus201703L > 202002L |
| 3746 | [[nodiscard]] |
| 3747 | constexpr bool |
| 3748 | contains(basic_string_view<_CharT, _Traits> __x) const noexcept |
| 3749 | { return __sv_type(this->data(), this->size()).contains(__x); } |
| 3750 | |
| 3751 | [[nodiscard]] |
| 3752 | constexpr bool |
| 3753 | contains(_CharT __x) const noexcept |
| 3754 | { return __sv_type(this->data(), this->size()).contains(__x); } |
| 3755 | |
| 3756 | [[nodiscard, __gnu__::__nonnull__]] |
| 3757 | constexpr bool |
| 3758 | contains(const _CharT* __x) const noexcept |
| 3759 | { return __sv_type(this->data(), this->size()).contains(__x); } |
| 3760 | #endif // C++23 |
| 3761 | |
| 3762 | // Allow basic_stringbuf::__xfer_bufptrs to call _M_length: |
| 3763 | template<typename, typename, typename> friend class basic_stringbuf; |
| 3764 | }; |
| 3765 | _GLIBCXX_END_NAMESPACE_CXX11} |
| 3766 | _GLIBCXX_END_NAMESPACE_VERSION |
| 3767 | } // namespace std |
| 3768 | #endif // _GLIBCXX_USE_CXX11_ABI |
| 3769 | |
| 3770 | namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default"))) |
| 3771 | { |
| 3772 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 3773 | |
| 3774 | #if __cpp_deduction_guides201703L >= 201606 |
| 3775 | _GLIBCXX_BEGIN_NAMESPACE_CXX11namespace __cxx11 { |
| 3776 | template<typename _InputIterator, typename _CharT |
| 3777 | = typename iterator_traits<_InputIterator>::value_type, |
| 3778 | typename _Allocator = allocator<_CharT>, |
| 3779 | typename = _RequireInputIter<_InputIterator>, |
| 3780 | typename = _RequireAllocator<_Allocator>> |
| 3781 | basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator()) |
| 3782 | -> basic_string<_CharT, char_traits<_CharT>, _Allocator>; |
| 3783 | |
| 3784 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
| 3785 | // 3075. basic_string needs deduction guides from basic_string_view |
| 3786 | template<typename _CharT, typename _Traits, |
| 3787 | typename _Allocator = allocator<_CharT>, |
| 3788 | typename = _RequireAllocator<_Allocator>> |
| 3789 | basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator()) |
| 3790 | -> basic_string<_CharT, _Traits, _Allocator>; |
| 3791 | |
| 3792 | template<typename _CharT, typename _Traits, |
| 3793 | typename _Allocator = allocator<_CharT>, |
| 3794 | typename = _RequireAllocator<_Allocator>> |
| 3795 | basic_string(basic_string_view<_CharT, _Traits>, |
| 3796 | typename basic_string<_CharT, _Traits, _Allocator>::size_type, |
| 3797 | typename basic_string<_CharT, _Traits, _Allocator>::size_type, |
| 3798 | const _Allocator& = _Allocator()) |
| 3799 | -> basic_string<_CharT, _Traits, _Allocator>; |
| 3800 | |
| 3801 | #if __glibcxx_containers_ranges // C++ >= 23 |
| 3802 | template<ranges::input_range _Rg, |
| 3803 | typename _Allocator = allocator<ranges::range_value_t<_Rg>>> |
| 3804 | basic_string(from_range_t, _Rg&&, _Allocator = _Allocator()) |
| 3805 | -> basic_string<ranges::range_value_t<_Rg>, |
| 3806 | char_traits<ranges::range_value_t<_Rg>>, |
| 3807 | _Allocator>; |
| 3808 | #endif |
| 3809 | _GLIBCXX_END_NAMESPACE_CXX11} |
| 3810 | #endif |
| 3811 | |
| 3812 | template<typename _Str> |
| 3813 | _GLIBCXX20_CONSTEXPR |
| 3814 | inline _Str |
| 3815 | __str_concat(typename _Str::value_type const* __lhs, |
| 3816 | typename _Str::size_type __lhs_len, |
| 3817 | typename _Str::value_type const* __rhs, |
| 3818 | typename _Str::size_type __rhs_len, |
| 3819 | typename _Str::allocator_type const& __a) |
| 3820 | { |
| 3821 | typedef typename _Str::allocator_type allocator_type; |
| 3822 | typedef __gnu_cxx::__alloc_traits<allocator_type> _Alloc_traits; |
| 3823 | _Str __str(_Alloc_traits::_S_select_on_copy(__a)); |
| 3824 | __str.reserve(__lhs_len + __rhs_len); |
| 3825 | __str.append(__lhs, __lhs_len); |
| 3826 | __str.append(__rhs, __rhs_len); |
| 3827 | return __str; |
| 3828 | } |
| 3829 | |
| 3830 | // operator+ |
| 3831 | /** |
| 3832 | * @brief Concatenate two strings. |
| 3833 | * @param __lhs First string. |
| 3834 | * @param __rhs Last string. |
| 3835 | * @return New string with value of @a __lhs followed by @a __rhs. |
| 3836 | */ |
| 3837 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3838 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3839 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3840 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 3841 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 3842 | { |
| 3843 | typedef basic_string<_CharT, _Traits, _Alloc> _Str; |
| 3844 | return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(), |
| 3845 | __rhs.c_str(), __rhs.size(), |
| 3846 | __lhs.get_allocator()); |
| 3847 | } |
| 3848 | |
| 3849 | /** |
| 3850 | * @brief Concatenate C string and string. |
| 3851 | * @param __lhs First string. |
| 3852 | * @param __rhs Last string. |
| 3853 | * @return New string with value of @a __lhs followed by @a __rhs. |
| 3854 | */ |
| 3855 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3856 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3857 | inline basic_string<_CharT,_Traits,_Alloc> |
| 3858 | operator+(const _CharT* __lhs, |
| 3859 | const basic_string<_CharT,_Traits,_Alloc>& __rhs) |
| 3860 | { |
| 3861 | __glibcxx_requires_string(__lhs); |
| 3862 | typedef basic_string<_CharT, _Traits, _Alloc> _Str; |
| 3863 | return std::__str_concat<_Str>(__lhs, _Traits::length(__lhs), |
| 3864 | __rhs.c_str(), __rhs.size(), |
| 3865 | __rhs.get_allocator()); |
| 3866 | } |
| 3867 | |
| 3868 | /** |
| 3869 | * @brief Concatenate character and string. |
| 3870 | * @param __lhs First string. |
| 3871 | * @param __rhs Last string. |
| 3872 | * @return New string with @a __lhs followed by @a __rhs. |
| 3873 | */ |
| 3874 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3875 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3876 | inline basic_string<_CharT,_Traits,_Alloc> |
| 3877 | operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs) |
| 3878 | { |
| 3879 | typedef basic_string<_CharT, _Traits, _Alloc> _Str; |
| 3880 | return std::__str_concat<_Str>(__builtin_addressof(__lhs), 1, |
| 3881 | __rhs.c_str(), __rhs.size(), |
| 3882 | __rhs.get_allocator()); |
| 3883 | } |
| 3884 | |
| 3885 | /** |
| 3886 | * @brief Concatenate string and C string. |
| 3887 | * @param __lhs First string. |
| 3888 | * @param __rhs Last string. |
| 3889 | * @return New string with @a __lhs followed by @a __rhs. |
| 3890 | */ |
| 3891 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3892 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3893 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3894 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 3895 | const _CharT* __rhs) |
| 3896 | { |
| 3897 | __glibcxx_requires_string(__rhs); |
| 3898 | typedef basic_string<_CharT, _Traits, _Alloc> _Str; |
| 3899 | return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(), |
| 3900 | __rhs, _Traits::length(__rhs), |
| 3901 | __lhs.get_allocator()); |
| 3902 | } |
| 3903 | /** |
| 3904 | * @brief Concatenate string and character. |
| 3905 | * @param __lhs First string. |
| 3906 | * @param __rhs Last string. |
| 3907 | * @return New string with @a __lhs followed by @a __rhs. |
| 3908 | */ |
| 3909 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3910 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3911 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3912 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs) |
| 3913 | { |
| 3914 | typedef basic_string<_CharT, _Traits, _Alloc> _Str; |
| 3915 | return std::__str_concat<_Str>(__lhs.c_str(), __lhs.size(), |
| 3916 | __builtin_addressof(__rhs), 1, |
| 3917 | __lhs.get_allocator()); |
| 3918 | } |
| 3919 | |
| 3920 | #if __cplusplus201703L >= 201103L |
| 3921 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3922 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3923 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3924 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
| 3925 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 3926 | { return std::move(__lhs.append(__rhs)); } |
| 3927 | |
| 3928 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3929 | _GLIBCXX20_CONSTEXPR |
| 3930 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3931 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 3932 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
| 3933 | { return std::move(__rhs.insert(0, __lhs)); } |
| 3934 | |
| 3935 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3936 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3937 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3938 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
| 3939 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
| 3940 | { |
| 3941 | #if _GLIBCXX_USE_CXX11_ABI1 |
| 3942 | using _Alloc_traits = allocator_traits<_Alloc>; |
| 3943 | bool __use_rhs = false; |
| 3944 | if _GLIBCXX17_CONSTEXPRconstexpr (typename _Alloc_traits::is_always_equal{}) |
| 3945 | __use_rhs = true; |
| 3946 | else if (__lhs.get_allocator() == __rhs.get_allocator()) |
| 3947 | __use_rhs = true; |
| 3948 | if (__use_rhs) |
| 3949 | #endif |
| 3950 | { |
| 3951 | const auto __size = __lhs.size() + __rhs.size(); |
| 3952 | if (__size > __lhs.capacity() && __size <= __rhs.capacity()) |
| 3953 | return std::move(__rhs.insert(0, __lhs)); |
| 3954 | } |
| 3955 | return std::move(__lhs.append(__rhs)); |
| 3956 | } |
| 3957 | |
| 3958 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3959 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3960 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3961 | operator+(const _CharT* __lhs, |
| 3962 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
| 3963 | { return std::move(__rhs.insert(0, __lhs)); } |
| 3964 | |
| 3965 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3966 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3967 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3968 | operator+(_CharT __lhs, |
| 3969 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
| 3970 | { return std::move(__rhs.insert(0, 1, __lhs)); } |
| 3971 | |
| 3972 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3973 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3974 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3975 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
| 3976 | const _CharT* __rhs) |
| 3977 | { return std::move(__lhs.append(__rhs)); } |
| 3978 | |
| 3979 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3980 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 3981 | inline basic_string<_CharT, _Traits, _Alloc> |
| 3982 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
| 3983 | _CharT __rhs) |
| 3984 | { return std::move(__lhs.append(1, __rhs)); } |
| 3985 | #endif |
| 3986 | |
| 3987 | #if __glibcxx_string_view201803L >= 202403L |
| 3988 | // const string & + string_view |
| 3989 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 3990 | [[nodiscard]] |
| 3991 | constexpr basic_string<_CharT, _Traits, _Alloc> |
| 3992 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 3993 | type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) |
| 3994 | { |
| 3995 | using _Str = basic_string<_CharT, _Traits, _Alloc>; |
| 3996 | return std::__str_concat<_Str>(__lhs.data(), __lhs.size(), |
| 3997 | __rhs.data(), __rhs.size(), |
| 3998 | __lhs.get_allocator()); |
| 3999 | } |
| 4000 | |
| 4001 | // string && + string_view |
| 4002 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4003 | [[nodiscard]] |
| 4004 | constexpr basic_string<_CharT, _Traits, _Alloc> |
| 4005 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, |
| 4006 | type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) |
| 4007 | { |
| 4008 | return std::move(__lhs.append(__rhs)); |
| 4009 | } |
| 4010 | |
| 4011 | // string_view + const string & |
| 4012 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4013 | [[nodiscard]] |
| 4014 | constexpr basic_string<_CharT, _Traits, _Alloc> |
| 4015 | operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs, |
| 4016 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4017 | { |
| 4018 | using _Str = basic_string<_CharT, _Traits, _Alloc>; |
| 4019 | return std::__str_concat<_Str>(__lhs.data(), __lhs.size(), |
| 4020 | __rhs.data(), __rhs.size(), |
| 4021 | __rhs.get_allocator()); |
| 4022 | } |
| 4023 | |
| 4024 | // string_view + string && |
| 4025 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4026 | [[nodiscard]] |
| 4027 | constexpr basic_string<_CharT, _Traits, _Alloc> |
| 4028 | operator+(type_identity_t<basic_string_view<_CharT, _Traits>> __lhs, |
| 4029 | basic_string<_CharT, _Traits, _Alloc>&& __rhs) |
| 4030 | { |
| 4031 | return std::move(__rhs.insert(0, __lhs)); |
| 4032 | } |
| 4033 | #endif |
| 4034 | |
| 4035 | // operator == |
| 4036 | /** |
| 4037 | * @brief Test equivalence of two strings. |
| 4038 | * @param __lhs First string. |
| 4039 | * @param __rhs Second string. |
| 4040 | * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. |
| 4041 | */ |
| 4042 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4043 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 4044 | inline bool |
| 4045 | operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4046 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4047 | _GLIBCXX_NOEXCEPTnoexcept |
| 4048 | { |
| 4049 | return __lhs.size() == __rhs.size() |
| 4050 | && !_Traits::compare(__lhs.data(), __rhs.data(), __lhs.size()); |
| 4051 | } |
| 4052 | |
| 4053 | /** |
| 4054 | * @brief Test equivalence of string and C string. |
| 4055 | * @param __lhs String. |
| 4056 | * @param __rhs C string. |
| 4057 | * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. |
| 4058 | */ |
| 4059 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4060 | _GLIBCXX_NODISCARD[[__nodiscard__]] _GLIBCXX20_CONSTEXPR |
| 4061 | inline bool |
| 4062 | operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4063 | const _CharT* __rhs) |
| 4064 | { |
| 4065 | return __lhs.size() == _Traits::length(__rhs) |
| 4066 | && !_Traits::compare(__lhs.data(), __rhs, __lhs.size()); |
| 4067 | } |
| 4068 | |
| 4069 | #if __cpp_lib_three_way_comparison |
| 4070 | /** |
| 4071 | * @brief Three-way comparison of a string and a C string. |
| 4072 | * @param __lhs A string. |
| 4073 | * @param __rhs A null-terminated string. |
| 4074 | * @return A value indicating whether `__lhs` is less than, equal to, |
| 4075 | * greater than, or incomparable with `__rhs`. |
| 4076 | */ |
| 4077 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4078 | [[nodiscard]] |
| 4079 | constexpr auto |
| 4080 | operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4081 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) noexcept |
| 4082 | -> decltype(__detail::__char_traits_cmp_cat<_Traits>(0)) |
| 4083 | { return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); } |
| 4084 | |
| 4085 | /** |
| 4086 | * @brief Three-way comparison of a string and a C string. |
| 4087 | * @param __lhs A string. |
| 4088 | * @param __rhs A null-terminated string. |
| 4089 | * @return A value indicating whether `__lhs` is less than, equal to, |
| 4090 | * greater than, or incomparable with `__rhs`. |
| 4091 | */ |
| 4092 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4093 | [[nodiscard]] |
| 4094 | constexpr auto |
| 4095 | operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4096 | const _CharT* __rhs) noexcept |
| 4097 | -> decltype(__detail::__char_traits_cmp_cat<_Traits>(0)) |
| 4098 | { return __detail::__char_traits_cmp_cat<_Traits>(__lhs.compare(__rhs)); } |
| 4099 | #else |
| 4100 | /** |
| 4101 | * @brief Test equivalence of C string and string. |
| 4102 | * @param __lhs C string. |
| 4103 | * @param __rhs String. |
| 4104 | * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise. |
| 4105 | */ |
| 4106 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4107 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4108 | inline bool |
| 4109 | operator==(const _CharT* __lhs, |
| 4110 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4111 | { return __rhs == __lhs; } |
| 4112 | |
| 4113 | // operator != |
| 4114 | /** |
| 4115 | * @brief Test difference of two strings. |
| 4116 | * @param __lhs First string. |
| 4117 | * @param __rhs Second string. |
| 4118 | * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. |
| 4119 | */ |
| 4120 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4121 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4122 | inline bool |
| 4123 | operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4124 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4125 | _GLIBCXX_NOEXCEPTnoexcept |
| 4126 | { return !(__lhs == __rhs); } |
| 4127 | |
| 4128 | /** |
| 4129 | * @brief Test difference of C string and string. |
| 4130 | * @param __lhs C string. |
| 4131 | * @param __rhs String. |
| 4132 | * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise. |
| 4133 | */ |
| 4134 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4135 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4136 | inline bool |
| 4137 | operator!=(const _CharT* __lhs, |
| 4138 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4139 | { return !(__rhs == __lhs); } |
| 4140 | |
| 4141 | /** |
| 4142 | * @brief Test difference of string and C string. |
| 4143 | * @param __lhs String. |
| 4144 | * @param __rhs C string. |
| 4145 | * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. |
| 4146 | */ |
| 4147 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4148 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4149 | inline bool |
| 4150 | operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4151 | const _CharT* __rhs) |
| 4152 | { return !(__lhs == __rhs); } |
| 4153 | |
| 4154 | // operator < |
| 4155 | /** |
| 4156 | * @brief Test if string precedes string. |
| 4157 | * @param __lhs First string. |
| 4158 | * @param __rhs Second string. |
| 4159 | * @return True if @a __lhs precedes @a __rhs. False otherwise. |
| 4160 | */ |
| 4161 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4162 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4163 | inline bool |
| 4164 | operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4165 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4166 | _GLIBCXX_NOEXCEPTnoexcept |
| 4167 | { return __lhs.compare(__rhs) < 0; } |
| 4168 | |
| 4169 | /** |
| 4170 | * @brief Test if string precedes C string. |
| 4171 | * @param __lhs String. |
| 4172 | * @param __rhs C string. |
| 4173 | * @return True if @a __lhs precedes @a __rhs. 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 _CharT* __rhs) |
| 4180 | { return __lhs.compare(__rhs) < 0; } |
| 4181 | |
| 4182 | /** |
| 4183 | * @brief Test if C string precedes string. |
| 4184 | * @param __lhs C string. |
| 4185 | * @param __rhs String. |
| 4186 | * @return True if @a __lhs precedes @a __rhs. False otherwise. |
| 4187 | */ |
| 4188 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4189 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4190 | inline bool |
| 4191 | operator<(const _CharT* __lhs, |
| 4192 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4193 | { return __rhs.compare(__lhs) > 0; } |
| 4194 | |
| 4195 | // operator > |
| 4196 | /** |
| 4197 | * @brief Test if string follows string. |
| 4198 | * @param __lhs First string. |
| 4199 | * @param __rhs Second string. |
| 4200 | * @return True if @a __lhs follows @a __rhs. 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 basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4207 | _GLIBCXX_NOEXCEPTnoexcept |
| 4208 | { return __lhs.compare(__rhs) > 0; } |
| 4209 | |
| 4210 | /** |
| 4211 | * @brief Test if string follows C string. |
| 4212 | * @param __lhs String. |
| 4213 | * @param __rhs C string. |
| 4214 | * @return True if @a __lhs follows @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 _CharT* __rhs) |
| 4221 | { return __lhs.compare(__rhs) > 0; } |
| 4222 | |
| 4223 | /** |
| 4224 | * @brief Test if C string follows string. |
| 4225 | * @param __lhs C string. |
| 4226 | * @param __rhs String. |
| 4227 | * @return True if @a __lhs follows @a __rhs. False otherwise. |
| 4228 | */ |
| 4229 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4230 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4231 | inline bool |
| 4232 | operator>(const _CharT* __lhs, |
| 4233 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4234 | { return __rhs.compare(__lhs) < 0; } |
| 4235 | |
| 4236 | // operator <= |
| 4237 | /** |
| 4238 | * @brief Test if string doesn't follow string. |
| 4239 | * @param __lhs First string. |
| 4240 | * @param __rhs Second string. |
| 4241 | * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. |
| 4242 | */ |
| 4243 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4244 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4245 | inline bool |
| 4246 | operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4247 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4248 | _GLIBCXX_NOEXCEPTnoexcept |
| 4249 | { return __lhs.compare(__rhs) <= 0; } |
| 4250 | |
| 4251 | /** |
| 4252 | * @brief Test if string doesn't follow C string. |
| 4253 | * @param __lhs String. |
| 4254 | * @param __rhs C string. |
| 4255 | * @return True if @a __lhs doesn't follow @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 _CharT* __rhs) |
| 4262 | { return __lhs.compare(__rhs) <= 0; } |
| 4263 | |
| 4264 | /** |
| 4265 | * @brief Test if C string doesn't follow string. |
| 4266 | * @param __lhs C string. |
| 4267 | * @param __rhs String. |
| 4268 | * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. |
| 4269 | */ |
| 4270 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4271 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4272 | inline bool |
| 4273 | operator<=(const _CharT* __lhs, |
| 4274 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4275 | { return __rhs.compare(__lhs) >= 0; } |
| 4276 | |
| 4277 | // operator >= |
| 4278 | /** |
| 4279 | * @brief Test if string doesn't precede string. |
| 4280 | * @param __lhs First string. |
| 4281 | * @param __rhs Second string. |
| 4282 | * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. |
| 4283 | */ |
| 4284 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4285 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4286 | inline bool |
| 4287 | operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4288 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4289 | _GLIBCXX_NOEXCEPTnoexcept |
| 4290 | { return __lhs.compare(__rhs) >= 0; } |
| 4291 | |
| 4292 | /** |
| 4293 | * @brief Test if string doesn't precede C string. |
| 4294 | * @param __lhs String. |
| 4295 | * @param __rhs C string. |
| 4296 | * @return True if @a __lhs doesn't precede @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 _CharT* __rhs) |
| 4303 | { return __lhs.compare(__rhs) >= 0; } |
| 4304 | |
| 4305 | /** |
| 4306 | * @brief Test if C string doesn't precede string. |
| 4307 | * @param __lhs C string. |
| 4308 | * @param __rhs String. |
| 4309 | * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. |
| 4310 | */ |
| 4311 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4312 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4313 | inline bool |
| 4314 | operator>=(const _CharT* __lhs, |
| 4315 | const basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4316 | { return __rhs.compare(__lhs) <= 0; } |
| 4317 | #endif // three-way comparison |
| 4318 | |
| 4319 | /** |
| 4320 | * @brief Swap contents of two strings. |
| 4321 | * @param __lhs First string. |
| 4322 | * @param __rhs Second string. |
| 4323 | * |
| 4324 | * Exchanges the contents of @a __lhs and @a __rhs in constant time. |
| 4325 | */ |
| 4326 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4327 | _GLIBCXX20_CONSTEXPR |
| 4328 | inline void |
| 4329 | swap(basic_string<_CharT, _Traits, _Alloc>& __lhs, |
| 4330 | basic_string<_CharT, _Traits, _Alloc>& __rhs) |
| 4331 | _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))noexcept(noexcept(__lhs.swap(__rhs))) |
| 4332 | { __lhs.swap(__rhs); } |
| 4333 | |
| 4334 | |
| 4335 | /** |
| 4336 | * @brief Read stream into a string. |
| 4337 | * @param __is Input stream. |
| 4338 | * @param __str Buffer to store into. |
| 4339 | * @return Reference to the input stream. |
| 4340 | * |
| 4341 | * Stores characters from @a __is into @a __str until whitespace is |
| 4342 | * found, the end of the stream is encountered, or str.max_size() |
| 4343 | * is reached. If is.width() is non-zero, that is the limit on the |
| 4344 | * number of characters stored into @a __str. Any previous |
| 4345 | * contents of @a __str are erased. |
| 4346 | */ |
| 4347 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4348 | basic_istream<_CharT, _Traits>& |
| 4349 | operator>>(basic_istream<_CharT, _Traits>& __is, |
| 4350 | basic_string<_CharT, _Traits, _Alloc>& __str); |
| 4351 | |
| 4352 | template<> |
| 4353 | basic_istream<char>& |
| 4354 | operator>>(basic_istream<char>& __is, basic_string<char>& __str); |
| 4355 | |
| 4356 | /** |
| 4357 | * @brief Write string to a stream. |
| 4358 | * @param __os Output stream. |
| 4359 | * @param __str String to write out. |
| 4360 | * @return Reference to the output stream. |
| 4361 | * |
| 4362 | * Output characters of @a __str into os following the same rules as for |
| 4363 | * writing a C string. |
| 4364 | */ |
| 4365 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4366 | inline basic_ostream<_CharT, _Traits>& |
| 4367 | operator<<(basic_ostream<_CharT, _Traits>& __os, |
| 4368 | const basic_string<_CharT, _Traits, _Alloc>& __str) |
| 4369 | { |
| 4370 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
| 4371 | // 586. string inserter not a formatted function |
| 4372 | return __ostream_insert(__os, __str.data(), __str.size()); |
| 4373 | } |
| 4374 | |
| 4375 | /** |
| 4376 | * @brief Read a line from stream into a string. |
| 4377 | * @param __is Input stream. |
| 4378 | * @param __str Buffer to store into. |
| 4379 | * @param __delim Character marking end of line. |
| 4380 | * @return Reference to the input stream. |
| 4381 | * |
| 4382 | * Stores characters from @a __is into @a __str until @a __delim is |
| 4383 | * found, the end of the stream is encountered, or str.max_size() |
| 4384 | * is reached. Any previous contents of @a __str are erased. If |
| 4385 | * @a __delim is encountered, it is extracted but not stored into |
| 4386 | * @a __str. |
| 4387 | */ |
| 4388 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4389 | basic_istream<_CharT, _Traits>& |
| 4390 | getline(basic_istream<_CharT, _Traits>& __is, |
| 4391 | basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim); |
| 4392 | |
| 4393 | /** |
| 4394 | * @brief Read a line from stream into a string. |
| 4395 | * @param __is Input stream. |
| 4396 | * @param __str Buffer to store into. |
| 4397 | * @return Reference to the input stream. |
| 4398 | * |
| 4399 | * Stores characters from is into @a __str until '\n' is |
| 4400 | * found, the end of the stream is encountered, or str.max_size() |
| 4401 | * is reached. Any previous contents of @a __str are erased. If |
| 4402 | * end of line is encountered, it is extracted but not stored into |
| 4403 | * @a __str. |
| 4404 | */ |
| 4405 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4406 | inline basic_istream<_CharT, _Traits>& |
| 4407 | getline(basic_istream<_CharT, _Traits>& __is, |
| 4408 | basic_string<_CharT, _Traits, _Alloc>& __str) |
| 4409 | { return std::getline(__is, __str, __is.widen('\n')); } |
| 4410 | |
| 4411 | #if __cplusplus201703L >= 201103L |
| 4412 | /// Read a line from an rvalue stream into a string. |
| 4413 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4414 | inline basic_istream<_CharT, _Traits>& |
| 4415 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 4416 | basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim) |
| 4417 | { return std::getline(__is, __str, __delim); } |
| 4418 | |
| 4419 | /// Read a line from an rvalue stream into a string. |
| 4420 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4421 | inline basic_istream<_CharT, _Traits>& |
| 4422 | getline(basic_istream<_CharT, _Traits>&& __is, |
| 4423 | basic_string<_CharT, _Traits, _Alloc>& __str) |
| 4424 | { return std::getline(__is, __str); } |
| 4425 | #endif |
| 4426 | |
| 4427 | template<> |
| 4428 | basic_istream<char>& |
| 4429 | getline(basic_istream<char>& __in, basic_string<char>& __str, |
| 4430 | char __delim); |
| 4431 | |
| 4432 | #ifdef _GLIBCXX_USE_WCHAR_T1 |
| 4433 | template<> |
| 4434 | basic_istream<wchar_t>& |
| 4435 | getline(basic_istream<wchar_t>& __in, basic_string<wchar_t>& __str, |
| 4436 | wchar_t __delim); |
| 4437 | #endif |
| 4438 | |
| 4439 | _GLIBCXX_END_NAMESPACE_VERSION |
| 4440 | } // namespace |
| 4441 | |
| 4442 | #if __cplusplus201703L >= 201103L |
| 4443 | |
| 4444 | #include <ext/string_conversions.h> |
| 4445 | #include <bits/charconv.h> |
| 4446 | |
| 4447 | namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default"))) |
| 4448 | { |
| 4449 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 4450 | _GLIBCXX_BEGIN_NAMESPACE_CXX11namespace __cxx11 { |
| 4451 | |
| 4452 | // 21.4 Numeric Conversions [string.conversions]. |
| 4453 | inline int |
| 4454 | stoi(const string& __str, size_t* __idx = 0, int __base = 10) |
| 4455 | { return __gnu_cxx::__stoa<long, int>(&std::strtol, "stoi", __str.c_str(), |
| 4456 | __idx, __base); } |
| 4457 | |
| 4458 | inline long |
| 4459 | stol(const string& __str, size_t* __idx = 0, int __base = 10) |
| 4460 | { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(), |
| 4461 | __idx, __base); } |
| 4462 | |
| 4463 | inline unsigned long |
| 4464 | stoul(const string& __str, size_t* __idx = 0, int __base = 10) |
| 4465 | { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(), |
| 4466 | __idx, __base); } |
| 4467 | |
| 4468 | #if _GLIBCXX_USE_C99_STDLIB1 |
| 4469 | inline long long |
| 4470 | stoll(const string& __str, size_t* __idx = 0, int __base = 10) |
| 4471 | { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(), |
| 4472 | __idx, __base); } |
| 4473 | |
| 4474 | inline unsigned long long |
| 4475 | stoull(const string& __str, size_t* __idx = 0, int __base = 10) |
| 4476 | { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(), |
| 4477 | __idx, __base); } |
| 4478 | #elif __LONG_WIDTH__64 == __LONG_LONG_WIDTH__ |
| 4479 | inline long long |
| 4480 | stoll(const string& __str, size_t* __idx = 0, int __base = 10) |
| 4481 | { return std::stol(__str, __idx, __base); } |
| 4482 | |
| 4483 | inline unsigned long long |
| 4484 | stoull(const string& __str, size_t* __idx = 0, int __base = 10) |
| 4485 | { return std::stoul(__str, __idx, __base); } |
| 4486 | #endif |
| 4487 | |
| 4488 | inline double |
| 4489 | stod(const string& __str, size_t* __idx = 0) |
| 4490 | { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); } |
| 4491 | |
| 4492 | #if _GLIBCXX_HAVE_STRTOF1 |
| 4493 | // NB: strtof vs strtod. |
| 4494 | inline float |
| 4495 | stof(const string& __str, size_t* __idx = 0) |
| 4496 | { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); } |
| 4497 | #else |
| 4498 | inline float |
| 4499 | stof(const string& __str, size_t* __idx = 0) |
| 4500 | { |
| 4501 | double __d = std::stod(__str, __idx); |
| 4502 | if (__builtin_isfinite(__d) && __d != 0.0) |
| 4503 | { |
| 4504 | double __abs_d = __builtin_fabs(__d); |
| 4505 | if (__abs_d < __FLT_MIN__1.17549435e-38F || __abs_d > __FLT_MAX__3.40282347e+38F) |
| 4506 | { |
| 4507 | errno(*__errno_location ()) = ERANGE34; |
| 4508 | std::__throw_out_of_range("stof"); |
| 4509 | } |
| 4510 | } |
| 4511 | return __d; |
| 4512 | } |
| 4513 | #endif |
| 4514 | |
| 4515 | #if _GLIBCXX_HAVE_STRTOLD1 && ! _GLIBCXX_HAVE_BROKEN_STRTOLD |
| 4516 | inline long double |
| 4517 | stold(const string& __str, size_t* __idx = 0) |
| 4518 | { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); } |
| 4519 | #elif __DBL_MANT_DIG__53 == __LDBL_MANT_DIG__64 |
| 4520 | inline long double |
| 4521 | stold(const string& __str, size_t* __idx = 0) |
| 4522 | { return std::stod(__str, __idx); } |
| 4523 | #endif |
| 4524 | |
| 4525 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
| 4526 | // DR 1261. Insufficent overloads for to_string / to_wstring |
| 4527 | |
| 4528 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4529 | inline string |
| 4530 | to_string(int __val) |
| 4531 | #if _GLIBCXX_USE_CXX11_ABI1 && (__CHAR_BIT__8 * __SIZEOF_INT__4) <= 32 |
| 4532 | noexcept // any 32-bit value fits in the SSO buffer |
| 4533 | #endif |
| 4534 | { |
| 4535 | const bool __neg = __val < 0; |
| 4536 | const unsigned __uval = __neg ? (unsigned)~__val + 1u : __val; |
| 4537 | const auto __len = __detail::__to_chars_len(__uval); |
| 4538 | string __str; |
| 4539 | __str.__resize_and_overwrite(__neg + __len, [=](char* __p, size_t __n) { |
| 4540 | __p[0] = '-'; |
| 4541 | __detail::__to_chars_10_impl(__p + (int)__neg, __len, __uval); |
| 4542 | return __n; |
| 4543 | }); |
| 4544 | return __str; |
| 4545 | } |
| 4546 | |
| 4547 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4548 | inline string |
| 4549 | to_string(unsigned __val) |
| 4550 | #if _GLIBCXX_USE_CXX11_ABI1 && (__CHAR_BIT__8 * __SIZEOF_INT__4) <= 32 |
| 4551 | noexcept // any 32-bit value fits in the SSO buffer |
| 4552 | #endif |
| 4553 | { |
| 4554 | const auto __len = __detail::__to_chars_len(__val); |
| 4555 | string __str; |
| 4556 | __str.__resize_and_overwrite(__len, [__val](char* __p, size_t __n) { |
| 4557 | __detail::__to_chars_10_impl(__p, __n, __val); |
| 4558 | return __n; |
| 4559 | }); |
| 4560 | return __str; |
| 4561 | } |
| 4562 | |
| 4563 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4564 | inline string |
| 4565 | to_string(long __val) |
| 4566 | #if _GLIBCXX_USE_CXX11_ABI1 && (__CHAR_BIT__8 * __SIZEOF_LONG__8) <= 32 |
| 4567 | noexcept // any 32-bit value fits in the SSO buffer |
| 4568 | #endif |
| 4569 | { |
| 4570 | const bool __neg = __val < 0; |
| 4571 | const unsigned long __uval = __neg ? (unsigned long)~__val + 1ul : __val; |
| 4572 | const auto __len = __detail::__to_chars_len(__uval); |
| 4573 | string __str; |
| 4574 | __str.__resize_and_overwrite(__neg + __len, [=](char* __p, size_t __n) { |
| 4575 | __p[0] = '-'; |
| 4576 | __detail::__to_chars_10_impl(__p + (int)__neg, __len, __uval); |
| 4577 | return __n; |
| 4578 | }); |
| 4579 | return __str; |
| 4580 | } |
| 4581 | |
| 4582 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4583 | inline string |
| 4584 | to_string(unsigned long __val) |
| 4585 | #if _GLIBCXX_USE_CXX11_ABI1 && (__CHAR_BIT__8 * __SIZEOF_LONG__8) <= 32 |
| 4586 | noexcept // any 32-bit value fits in the SSO buffer |
| 4587 | #endif |
| 4588 | { |
| 4589 | const auto __len = __detail::__to_chars_len(__val); |
| 4590 | string __str; |
| 4591 | __str.__resize_and_overwrite(__len, [__val](char* __p, size_t __n) { |
| 4592 | __detail::__to_chars_10_impl(__p, __n, __val); |
| 4593 | return __n; |
| 4594 | }); |
| 4595 | return __str; |
| 4596 | } |
| 4597 | |
| 4598 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4599 | inline string |
| 4600 | to_string(long long __val) |
| 4601 | { |
| 4602 | const bool __neg = __val < 0; |
| 4603 | const unsigned long long __uval |
| 4604 | = __neg ? (unsigned long long)~__val + 1ull : __val; |
| 4605 | const auto __len = __detail::__to_chars_len(__uval); |
| 4606 | string __str; |
| 4607 | __str.__resize_and_overwrite(__neg + __len, [=](char* __p, size_t __n) { |
| 4608 | __p[0] = '-'; |
| 4609 | __detail::__to_chars_10_impl(__p + (int)__neg, __len, __uval); |
| 4610 | return __n; |
| 4611 | }); |
| 4612 | return __str; |
| 4613 | } |
| 4614 | |
| 4615 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4616 | inline string |
| 4617 | to_string(unsigned long long __val) |
| 4618 | { |
| 4619 | const auto __len = __detail::__to_chars_len(__val); |
| 4620 | string __str; |
| 4621 | __str.__resize_and_overwrite(__len, [__val](char* __p, size_t __n) { |
| 4622 | __detail::__to_chars_10_impl(__p, __n, __val); |
| 4623 | return __n; |
| 4624 | }); |
| 4625 | return __str; |
| 4626 | } |
| 4627 | |
| 4628 | #if __glibcxx_to_string >= 202306L // C++ >= 26 |
| 4629 | |
| 4630 | [[nodiscard]] |
| 4631 | inline string |
| 4632 | to_string(float __val) |
| 4633 | { |
| 4634 | string __str; |
| 4635 | size_t __len = 15; |
| 4636 | do { |
| 4637 | __str.resize_and_overwrite(__len, |
| 4638 | [__val, &__len] (char* __p, size_t __n) { |
| 4639 | auto [__end, __err] = std::to_chars(__p, __p + __n, __val); |
| 4640 | if (__err == errc{}) [[likely]] |
| 4641 | return __end - __p; |
| 4642 | __len *= 2; |
| 4643 | return __p - __p;; |
| 4644 | }); |
| 4645 | } while (__str.empty()); |
| 4646 | return __str; |
| 4647 | } |
| 4648 | |
| 4649 | [[nodiscard]] |
| 4650 | inline string |
| 4651 | to_string(double __val) |
| 4652 | { |
| 4653 | string __str; |
| 4654 | size_t __len = 15; |
| 4655 | do { |
| 4656 | __str.resize_and_overwrite(__len, |
| 4657 | [__val, &__len] (char* __p, size_t __n) { |
| 4658 | auto [__end, __err] = std::to_chars(__p, __p + __n, __val); |
| 4659 | if (__err == errc{}) [[likely]] |
| 4660 | return __end - __p; |
| 4661 | __len *= 2; |
| 4662 | return __p - __p;; |
| 4663 | }); |
| 4664 | } while (__str.empty()); |
| 4665 | return __str; |
| 4666 | } |
| 4667 | |
| 4668 | [[nodiscard]] |
| 4669 | inline string |
| 4670 | to_string(long double __val) |
| 4671 | { |
| 4672 | string __str; |
| 4673 | size_t __len = 15; |
| 4674 | do { |
| 4675 | __str.resize_and_overwrite(__len, |
| 4676 | [__val, &__len] (char* __p, size_t __n) { |
| 4677 | auto [__end, __err] = std::to_chars(__p, __p + __n, __val); |
| 4678 | if (__err == errc{}) [[likely]] |
| 4679 | return __end - __p; |
| 4680 | __len *= 2; |
| 4681 | return __p - __p;; |
| 4682 | }); |
| 4683 | } while (__str.empty()); |
| 4684 | return __str; |
| 4685 | } |
| 4686 | #elif _GLIBCXX_USE_C99_STDIO1 |
| 4687 | #pragma GCC diagnostic push |
| 4688 | #pragma GCC diagnostic ignored "-Wsuggest-attribute=format" |
| 4689 | // NB: (v)snprintf vs sprintf. |
| 4690 | |
| 4691 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4692 | inline string |
| 4693 | to_string(float __val) |
| 4694 | { |
| 4695 | const int __n = |
| 4696 | __gnu_cxx::__numeric_traits<float>::__max_exponent10 + 20; |
| 4697 | return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, |
| 4698 | "%f", __val); |
| 4699 | } |
| 4700 | |
| 4701 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4702 | inline string |
| 4703 | to_string(double __val) |
| 4704 | { |
| 4705 | const int __n = |
| 4706 | __gnu_cxx::__numeric_traits<double>::__max_exponent10 + 20; |
| 4707 | return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, |
| 4708 | "%f", __val); |
| 4709 | } |
| 4710 | |
| 4711 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4712 | inline string |
| 4713 | to_string(long double __val) |
| 4714 | { |
| 4715 | const int __n = |
| 4716 | __gnu_cxx::__numeric_traits<long double>::__max_exponent10 + 20; |
| 4717 | return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, __n, |
| 4718 | "%Lf", __val); |
| 4719 | } |
| 4720 | #pragma GCC diagnostic pop |
| 4721 | #endif // _GLIBCXX_USE_C99_STDIO |
| 4722 | |
| 4723 | #if defined(_GLIBCXX_USE_WCHAR_T1) && _GLIBCXX_USE_C99_WCHAR1 |
| 4724 | inline int |
| 4725 | stoi(const wstring& __str, size_t* __idx = 0, int __base = 10) |
| 4726 | { return __gnu_cxx::__stoa<long, int>(&std::wcstol, "stoi", __str.c_str(), |
| 4727 | __idx, __base); } |
| 4728 | |
| 4729 | inline long |
| 4730 | stol(const wstring& __str, size_t* __idx = 0, int __base = 10) |
| 4731 | { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(), |
| 4732 | __idx, __base); } |
| 4733 | |
| 4734 | inline unsigned long |
| 4735 | stoul(const wstring& __str, size_t* __idx = 0, int __base = 10) |
| 4736 | { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(), |
| 4737 | __idx, __base); } |
| 4738 | |
| 4739 | inline long long |
| 4740 | stoll(const wstring& __str, size_t* __idx = 0, int __base = 10) |
| 4741 | { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(), |
| 4742 | __idx, __base); } |
| 4743 | |
| 4744 | inline unsigned long long |
| 4745 | stoull(const wstring& __str, size_t* __idx = 0, int __base = 10) |
| 4746 | { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(), |
| 4747 | __idx, __base); } |
| 4748 | |
| 4749 | // NB: wcstof vs wcstod. |
| 4750 | inline float |
| 4751 | stof(const wstring& __str, size_t* __idx = 0) |
| 4752 | { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); } |
| 4753 | |
| 4754 | inline double |
| 4755 | stod(const wstring& __str, size_t* __idx = 0) |
| 4756 | { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); } |
| 4757 | |
| 4758 | inline long double |
| 4759 | stold(const wstring& __str, size_t* __idx = 0) |
| 4760 | { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); } |
| 4761 | #endif |
| 4762 | |
| 4763 | #ifdef _GLIBCXX_USE_WCHAR_T1 |
| 4764 | #pragma GCC diagnostic push |
| 4765 | #pragma GCC diagnostic ignored "-Wc++17-extensions" |
| 4766 | _GLIBCXX20_CONSTEXPR |
| 4767 | inline void |
| 4768 | __to_wstring_numeric(const char* __s, int __len, wchar_t* __wout) |
| 4769 | { |
| 4770 | // This condition is true if exec-charset and wide-exec-charset share the |
| 4771 | // same values for the ASCII subset or the EBCDIC invariant character set. |
| 4772 | if constexpr (wchar_t('0') == L'0' && wchar_t('-') == L'-' |
| 4773 | && wchar_t('.') == L'.' && wchar_t('e') == L'e') |
| 4774 | { |
| 4775 | for (int __i = 0; __i < __len; ++__i) |
| 4776 | __wout[__i] = (wchar_t) __s[__i]; |
| 4777 | } |
| 4778 | else |
| 4779 | { |
| 4780 | wchar_t __wc[256]; |
| 4781 | for (int __i = '0'; __i <= '9'; ++__i) |
| 4782 | __wc[__i] = L'0' + __i; |
| 4783 | __wc['.'] = L'.'; |
| 4784 | __wc['+'] = L'+'; |
| 4785 | __wc['-'] = L'-'; |
| 4786 | __wc['a'] = L'a'; |
| 4787 | __wc['b'] = L'b'; |
| 4788 | __wc['c'] = L'c'; |
| 4789 | __wc['d'] = L'd'; |
| 4790 | __wc['e'] = L'e'; |
| 4791 | __wc['f'] = L'f'; |
| 4792 | __wc['i'] = L'i'; // for "inf" |
| 4793 | __wc['n'] = L'n'; // for "nan" and "inf" |
| 4794 | __wc['p'] = L'p'; // for hexfloats "0x1p1" |
| 4795 | __wc['x'] = L'x'; |
| 4796 | __wc['A'] = L'A'; |
| 4797 | __wc['B'] = L'B'; |
| 4798 | __wc['C'] = L'C'; |
| 4799 | __wc['D'] = L'D'; |
| 4800 | __wc['E'] = L'E'; |
| 4801 | __wc['F'] = L'F'; |
| 4802 | __wc['I'] = L'I'; |
| 4803 | __wc['N'] = L'N'; |
| 4804 | __wc['P'] = L'P'; |
| 4805 | __wc['X'] = L'X'; |
| 4806 | |
| 4807 | for (int __i = 0; __i < __len; ++__i) |
| 4808 | __wout[__i] = __wc[(int)__s[__i]]; |
| 4809 | } |
| 4810 | } |
| 4811 | |
| 4812 | #if __glibcxx_constexpr_string201611L >= 201907L |
| 4813 | constexpr |
| 4814 | #endif |
| 4815 | inline wstring |
| 4816 | #ifdef __glibcxx_string_view201803L // >= C++17 |
| 4817 | __to_wstring_numeric(string_view __s) |
| 4818 | #else |
| 4819 | __to_wstring_numeric(const string& __s) |
| 4820 | #endif |
| 4821 | { |
| 4822 | if constexpr (wchar_t('0') == L'0' && wchar_t('-') == L'-' |
| 4823 | && wchar_t('.') == L'.' && wchar_t('e') == L'e') |
| 4824 | return wstring(__s.data(), __s.data() + __s.size()); |
| 4825 | else |
| 4826 | { |
| 4827 | wstring __ws; |
| 4828 | auto __f = __s.data(); |
| 4829 | __ws.__resize_and_overwrite(__s.size(), |
| 4830 | [__f] (wchar_t* __to, int __n) { |
| 4831 | std::__to_wstring_numeric(__f, __n, __to); |
| 4832 | return __n; |
| 4833 | }); |
| 4834 | return __ws; |
| 4835 | } |
| 4836 | } |
| 4837 | #pragma GCC diagnostic pop |
| 4838 | |
| 4839 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4840 | inline wstring |
| 4841 | to_wstring(int __val) |
| 4842 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4843 | |
| 4844 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4845 | inline wstring |
| 4846 | to_wstring(unsigned __val) |
| 4847 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4848 | |
| 4849 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4850 | inline wstring |
| 4851 | to_wstring(long __val) |
| 4852 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4853 | |
| 4854 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4855 | inline wstring |
| 4856 | to_wstring(unsigned long __val) |
| 4857 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4858 | |
| 4859 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4860 | inline wstring |
| 4861 | to_wstring(long long __val) |
| 4862 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4863 | |
| 4864 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4865 | inline wstring |
| 4866 | to_wstring(unsigned long long __val) |
| 4867 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4868 | |
| 4869 | #if __glibcxx_to_string || _GLIBCXX_USE_C99_STDIO1 |
| 4870 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4871 | inline wstring |
| 4872 | to_wstring(float __val) |
| 4873 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4874 | |
| 4875 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4876 | inline wstring |
| 4877 | to_wstring(double __val) |
| 4878 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4879 | |
| 4880 | _GLIBCXX_NODISCARD[[__nodiscard__]] |
| 4881 | inline wstring |
| 4882 | to_wstring(long double __val) |
| 4883 | { return std::__to_wstring_numeric(std::to_string(__val)); } |
| 4884 | #endif |
| 4885 | #endif // _GLIBCXX_USE_WCHAR_T |
| 4886 | |
| 4887 | _GLIBCXX_END_NAMESPACE_CXX11} |
| 4888 | _GLIBCXX_END_NAMESPACE_VERSION |
| 4889 | } // namespace |
| 4890 | |
| 4891 | #endif /* C++11 */ |
| 4892 | |
| 4893 | #if __cplusplus201703L >= 201103L |
| 4894 | |
| 4895 | #include <bits/functional_hash.h> |
| 4896 | |
| 4897 | namespace std _GLIBCXX_VISIBILITY(default)__attribute__ ((__visibility__ ("default"))) |
| 4898 | { |
| 4899 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 4900 | |
| 4901 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
| 4902 | // 3705. Hashability shouldn't depend on basic_string's allocator |
| 4903 | |
| 4904 | template<typename _CharT, typename _Alloc, |
| 4905 | typename _StrT = basic_string<_CharT, char_traits<_CharT>, _Alloc>> |
| 4906 | struct __str_hash_base |
| 4907 | : public __hash_base<size_t, _StrT> |
| 4908 | { |
| 4909 | [[__nodiscard__]] |
| 4910 | size_t |
| 4911 | operator()(const _StrT& __s) const noexcept |
| 4912 | { return _Hash_impl::hash(__s.data(), __s.length() * sizeof(_CharT)); } |
| 4913 | }; |
| 4914 | |
| 4915 | #ifndef _GLIBCXX_COMPATIBILITY_CXX0X |
| 4916 | /// std::hash specialization for string. |
| 4917 | template<typename _Alloc> |
| 4918 | struct hash<basic_string<char, char_traits<char>, _Alloc>> |
| 4919 | : public __str_hash_base<char, _Alloc> |
| 4920 | { }; |
| 4921 | |
| 4922 | /// std::hash specialization for wstring. |
| 4923 | template<typename _Alloc> |
| 4924 | struct hash<basic_string<wchar_t, char_traits<wchar_t>, _Alloc>> |
| 4925 | : public __str_hash_base<wchar_t, _Alloc> |
| 4926 | { }; |
| 4927 | |
| 4928 | template<typename _Alloc> |
| 4929 | struct __is_fast_hash<hash<basic_string<wchar_t, char_traits<wchar_t>, |
| 4930 | _Alloc>>> |
| 4931 | : std::false_type |
| 4932 | { }; |
| 4933 | #endif /* _GLIBCXX_COMPATIBILITY_CXX0X */ |
| 4934 | |
| 4935 | #ifdef _GLIBCXX_USE_CHAR8_T |
| 4936 | /// std::hash specialization for u8string. |
| 4937 | template<typename _Alloc> |
| 4938 | struct hash<basic_string<char8_t, char_traits<char8_t>, _Alloc>> |
| 4939 | : public __str_hash_base<char8_t, _Alloc> |
| 4940 | { }; |
| 4941 | #endif |
| 4942 | |
| 4943 | /// std::hash specialization for u16string. |
| 4944 | template<typename _Alloc> |
| 4945 | struct hash<basic_string<char16_t, char_traits<char16_t>, _Alloc>> |
| 4946 | : public __str_hash_base<char16_t, _Alloc> |
| 4947 | { }; |
| 4948 | |
| 4949 | /// std::hash specialization for u32string. |
| 4950 | template<typename _Alloc> |
| 4951 | struct hash<basic_string<char32_t, char_traits<char32_t>, _Alloc>> |
| 4952 | : public __str_hash_base<char32_t, _Alloc> |
| 4953 | { }; |
| 4954 | |
| 4955 | #if ! _GLIBCXX_INLINE_VERSION0 |
| 4956 | // PR libstdc++/105907 - __is_fast_hash affects unordered container ABI. |
| 4957 | template<> struct __is_fast_hash<hash<string>> : std::false_type { }; |
| 4958 | template<> struct __is_fast_hash<hash<wstring>> : std::false_type { }; |
| 4959 | template<> struct __is_fast_hash<hash<u16string>> : std::false_type { }; |
| 4960 | template<> struct __is_fast_hash<hash<u32string>> : std::false_type { }; |
| 4961 | #ifdef _GLIBCXX_USE_CHAR8_T |
| 4962 | template<> struct __is_fast_hash<hash<u8string>> : std::false_type { }; |
| 4963 | #endif |
| 4964 | #else |
| 4965 | // For versioned namespace, assume every std::hash<basic_string<>> is slow. |
| 4966 | template<typename _CharT, typename _Traits, typename _Alloc> |
| 4967 | struct __is_fast_hash<hash<basic_string<_CharT, _Traits, _Alloc>>> |
| 4968 | : std::false_type |
| 4969 | { }; |
| 4970 | #endif |
| 4971 | |
| 4972 | #ifdef __glibcxx_string_udls201304L // C++ >= 14 |
| 4973 | inline namespace literals |
| 4974 | { |
| 4975 | inline namespace string_literals |
| 4976 | { |
| 4977 | #pragma GCC diagnostic push |
| 4978 | #pragma GCC diagnostic ignored "-Wliteral-suffix" |
| 4979 | |
| 4980 | #if __glibcxx_constexpr_string201611L >= 201907L |
| 4981 | # define _GLIBCXX_STRING_CONSTEXPR constexpr |
| 4982 | #else |
| 4983 | # define _GLIBCXX_STRING_CONSTEXPR |
| 4984 | #endif |
| 4985 | |
| 4986 | _GLIBCXX_DEFAULT_ABI_TAG__attribute ((__abi_tag__ ("cxx11"))) _GLIBCXX_STRING_CONSTEXPR |
| 4987 | inline basic_string<char> |
| 4988 | operator""s(const char* __str, size_t __len) |
| 4989 | { return basic_string<char>{__str, __len}; } |
| 4990 | |
| 4991 | _GLIBCXX_DEFAULT_ABI_TAG__attribute ((__abi_tag__ ("cxx11"))) _GLIBCXX_STRING_CONSTEXPR |
| 4992 | inline basic_string<wchar_t> |
| 4993 | operator""s(const wchar_t* __str, size_t __len) |
| 4994 | { return basic_string<wchar_t>{__str, __len}; } |
| 4995 | |
| 4996 | #ifdef _GLIBCXX_USE_CHAR8_T |
| 4997 | _GLIBCXX_DEFAULT_ABI_TAG__attribute ((__abi_tag__ ("cxx11"))) _GLIBCXX_STRING_CONSTEXPR |
| 4998 | inline basic_string<char8_t> |
| 4999 | operator""s(const char8_t* __str, size_t __len) |
| 5000 | { return basic_string<char8_t>{__str, __len}; } |
| 5001 | #endif |
| 5002 | |
| 5003 | _GLIBCXX_DEFAULT_ABI_TAG__attribute ((__abi_tag__ ("cxx11"))) _GLIBCXX_STRING_CONSTEXPR |
| 5004 | inline basic_string<char16_t> |
| 5005 | operator""s(const char16_t* __str, size_t __len) |
| 5006 | { return basic_string<char16_t>{__str, __len}; } |
| 5007 | |
| 5008 | _GLIBCXX_DEFAULT_ABI_TAG__attribute ((__abi_tag__ ("cxx11"))) _GLIBCXX_STRING_CONSTEXPR |
| 5009 | inline basic_string<char32_t> |
| 5010 | operator""s(const char32_t* __str, size_t __len) |
| 5011 | { return basic_string<char32_t>{__str, __len}; } |
| 5012 | |
| 5013 | #undef _GLIBCXX_STRING_CONSTEXPR |
| 5014 | #pragma GCC diagnostic pop |
| 5015 | } // inline namespace string_literals |
| 5016 | } // inline namespace literals |
| 5017 | #endif // __glibcxx_string_udls |
| 5018 | |
| 5019 | #ifdef __glibcxx_variant202102L // >= C++17 |
| 5020 | namespace __detail::__variant |
| 5021 | { |
| 5022 | template<typename> struct _Never_valueless_alt; // see <variant> |
| 5023 | |
| 5024 | // Provide the strong exception-safety guarantee when emplacing a |
| 5025 | // basic_string into a variant, but only if moving the string cannot throw. |
| 5026 | template<typename _Tp, typename _Traits, typename _Alloc> |
| 5027 | struct _Never_valueless_alt<std::basic_string<_Tp, _Traits, _Alloc>> |
| 5028 | : __and_< |
| 5029 | is_nothrow_move_constructible<std::basic_string<_Tp, _Traits, _Alloc>>, |
| 5030 | is_nothrow_move_assignable<std::basic_string<_Tp, _Traits, _Alloc>> |
| 5031 | >::type |
| 5032 | { }; |
| 5033 | } // namespace __detail::__variant |
| 5034 | #endif // C++17 |
| 5035 | |
| 5036 | _GLIBCXX_END_NAMESPACE_VERSION |
| 5037 | } // namespace std |
| 5038 | |
| 5039 | #endif // C++11 |
| 5040 | |
| 5041 | #endif /* _BASIC_STRING_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 file implements the AssertionResult type. | |||
| 33 | ||||
| 34 | // IWYU pragma: private, include "gtest/gtest.h" | |||
| 35 | // IWYU pragma: friend gtest/.* | |||
| 36 | // IWYU pragma: friend gmock/.* | |||
| 37 | ||||
| 38 | #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_ASSERTION_RESULT_H_ | |||
| 39 | #define GOOGLETEST_INCLUDE_GTEST_GTEST_ASSERTION_RESULT_H_ | |||
| 40 | ||||
| 41 | #include <memory> | |||
| 42 | #include <ostream> | |||
| 43 | #include <string> | |||
| 44 | #include <type_traits> | |||
| 45 | ||||
| 46 | #include "gtest/gtest-message.h" | |||
| 47 | #include "gtest/internal/gtest-port.h" | |||
| 48 | ||||
| 49 | GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ | |||
| 50 | /* class A needs to have dll-interface to be used by clients of class B */) | |||
| 51 | ||||
| 52 | namespace testing { | |||
| 53 | ||||
| 54 | // A class for indicating whether an assertion was successful. When | |||
| 55 | // the assertion wasn't successful, the AssertionResult object | |||
| 56 | // remembers a non-empty message that describes how it failed. | |||
| 57 | // | |||
| 58 | // To create an instance of this class, use one of the factory functions | |||
| 59 | // (AssertionSuccess() and AssertionFailure()). | |||
| 60 | // | |||
| 61 | // This class is useful for two purposes: | |||
| 62 | // 1. Defining predicate functions to be used with Boolean test assertions | |||
| 63 | // EXPECT_TRUE/EXPECT_FALSE and their ASSERT_ counterparts | |||
| 64 | // 2. Defining predicate-format functions to be | |||
| 65 | // used with predicate assertions (ASSERT_PRED_FORMAT*, etc). | |||
| 66 | // | |||
| 67 | // For example, if you define IsEven predicate: | |||
| 68 | // | |||
| 69 | // testing::AssertionResult IsEven(int n) { | |||
| 70 | // if ((n % 2) == 0) | |||
| 71 | // return testing::AssertionSuccess(); | |||
| 72 | // else | |||
| 73 | // return testing::AssertionFailure() << n << " is odd"; | |||
| 74 | // } | |||
| 75 | // | |||
| 76 | // Then the failed expectation EXPECT_TRUE(IsEven(Fib(5))) | |||
| 77 | // will print the message | |||
| 78 | // | |||
| 79 | // Value of: IsEven(Fib(5)) | |||
| 80 | // Actual: false (5 is odd) | |||
| 81 | // Expected: true | |||
| 82 | // | |||
| 83 | // instead of a more opaque | |||
| 84 | // | |||
| 85 | // Value of: IsEven(Fib(5)) | |||
| 86 | // Actual: false | |||
| 87 | // Expected: true | |||
| 88 | // | |||
| 89 | // in case IsEven is a simple Boolean predicate. | |||
| 90 | // | |||
| 91 | // If you expect your predicate to be reused and want to support informative | |||
| 92 | // messages in EXPECT_FALSE and ASSERT_FALSE (negative assertions show up | |||
| 93 | // about half as often as positive ones in our tests), supply messages for | |||
| 94 | // both success and failure cases: | |||
| 95 | // | |||
| 96 | // testing::AssertionResult IsEven(int n) { | |||
| 97 | // if ((n % 2) == 0) | |||
| 98 | // return testing::AssertionSuccess() << n << " is even"; | |||
| 99 | // else | |||
| 100 | // return testing::AssertionFailure() << n << " is odd"; | |||
| 101 | // } | |||
| 102 | // | |||
| 103 | // Then a statement EXPECT_FALSE(IsEven(Fib(6))) will print | |||
| 104 | // | |||
| 105 | // Value of: IsEven(Fib(6)) | |||
| 106 | // Actual: true (8 is even) | |||
| 107 | // Expected: false | |||
| 108 | // | |||
| 109 | // NB: Predicates that support negative Boolean assertions have reduced | |||
| 110 | // performance in positive ones so be careful not to use them in tests | |||
| 111 | // that have lots (tens of thousands) of positive Boolean assertions. | |||
| 112 | // | |||
| 113 | // To use this class with EXPECT_PRED_FORMAT assertions such as: | |||
| 114 | // | |||
| 115 | // // Verifies that Foo() returns an even number. | |||
| 116 | // EXPECT_PRED_FORMAT1(IsEven, Foo()); | |||
| 117 | // | |||
| 118 | // you need to define: | |||
| 119 | // | |||
| 120 | // testing::AssertionResult IsEven(const char* expr, int n) { | |||
| 121 | // if ((n % 2) == 0) | |||
| 122 | // return testing::AssertionSuccess(); | |||
| 123 | // else | |||
| 124 | // return testing::AssertionFailure() | |||
| 125 | // << "Expected: " << expr << " is even\n Actual: it's " << n; | |||
| 126 | // } | |||
| 127 | // | |||
| 128 | // If Foo() returns 5, you will see the following message: | |||
| 129 | // | |||
| 130 | // Expected: Foo() is even | |||
| 131 | // Actual: it's 5 | |||
| 132 | ||||
| 133 | class GTEST_API___attribute__((visibility("default"))) AssertionResult { | |||
| 134 | public: | |||
| 135 | // Copy constructor. | |||
| 136 | // Used in EXPECT_TRUE/FALSE(assertion_result). | |||
| 137 | AssertionResult(const AssertionResult& other); | |||
| 138 | ||||
| 139 | // C4800 is a level 3 warning in Visual Studio 2015 and earlier. | |||
| 140 | // This warning is not emitted in Visual Studio 2017. | |||
| 141 | // This warning is off by default starting in Visual Studio 2019 but can be | |||
| 142 | // enabled with command-line options. | |||
| 143 | #if defined(_MSC_VER) && (_MSC_VER < 1910 || _MSC_VER >= 1920) | |||
| 144 | GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 /* forcing value to bool */) | |||
| 145 | #endif | |||
| 146 | ||||
| 147 | // Used in the EXPECT_TRUE/FALSE(bool_expression). | |||
| 148 | // | |||
| 149 | // T must be contextually convertible to bool. | |||
| 150 | // | |||
| 151 | // The second parameter prevents this overload from being considered if | |||
| 152 | // the argument is implicitly convertible to AssertionResult. In that case | |||
| 153 | // we want AssertionResult's copy constructor to be used. | |||
| 154 | template <typename T> | |||
| 155 | explicit AssertionResult( | |||
| 156 | const T& success, | |||
| 157 | typename std::enable_if< | |||
| 158 | !std::is_convertible<T, AssertionResult>::value>::type* | |||
| 159 | /*enabler*/ | |||
| 160 | = nullptr) | |||
| 161 | : success_(success) {} | |||
| ||||
| 162 | ||||
| 163 | #if defined(_MSC_VER) && (_MSC_VER < 1910 || _MSC_VER >= 1920) | |||
| 164 | GTEST_DISABLE_MSC_WARNINGS_POP_() | |||
| 165 | #endif | |||
| 166 | ||||
| 167 | // Assignment operator. | |||
| 168 | AssertionResult& operator=(AssertionResult other) { | |||
| 169 | swap(other); | |||
| 170 | return *this; | |||
| 171 | } | |||
| 172 | ||||
| 173 | // Returns true if and only if the assertion succeeded. | |||
| 174 | operator bool() const { return success_; } // NOLINT | |||
| 175 | ||||
| 176 | // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE. | |||
| 177 | AssertionResult operator!() const; | |||
| 178 | ||||
| 179 | // Returns the text streamed into this AssertionResult. Test assertions | |||
| 180 | // use it when they fail (i.e., the predicate's outcome doesn't match the | |||
| 181 | // assertion's expectation). When nothing has been streamed into the | |||
| 182 | // object, returns an empty string. | |||
| 183 | const char* message() const { | |||
| 184 | return message_ != nullptr ? message_->c_str() : ""; | |||
| 185 | } | |||
| 186 | // Deprecated; please use message() instead. | |||
| 187 | const char* failure_message() const { return message(); } | |||
| 188 | ||||
| 189 | // Streams a custom failure message into this object. | |||
| 190 | template <typename T> | |||
| 191 | AssertionResult& operator<<(const T& value) { | |||
| 192 | AppendMessage(Message() << value); | |||
| 193 | return *this; | |||
| 194 | } | |||
| 195 | ||||
| 196 | // Allows streaming basic output manipulators such as endl or flush into | |||
| 197 | // this object. | |||
| 198 | AssertionResult& operator<<( | |||
| 199 | ::std::ostream& (*basic_manipulator)(::std::ostream& stream)) { | |||
| 200 | AppendMessage(Message() << basic_manipulator); | |||
| 201 | return *this; | |||
| 202 | } | |||
| 203 | ||||
| 204 | private: | |||
| 205 | // Appends the contents of message to message_. | |||
| 206 | void AppendMessage(const Message& a_message) { | |||
| 207 | if (message_ == nullptr) message_ = ::std::make_unique<::std::string>(); | |||
| 208 | message_->append(a_message.GetString().c_str()); | |||
| 209 | } | |||
| 210 | ||||
| 211 | // Swap the contents of this AssertionResult with other. | |||
| 212 | void swap(AssertionResult& other); | |||
| 213 | ||||
| 214 | // Stores result of the assertion predicate. | |||
| 215 | bool success_; | |||
| 216 | // Stores the message describing the condition in case the expectation | |||
| 217 | // construct is not satisfied with the predicate's outcome. | |||
| 218 | // Referenced via a pointer to avoid taking too much stack frame space | |||
| 219 | // with test assertions. | |||
| 220 | std::unique_ptr< ::std::string> message_; | |||
| 221 | }; | |||
| 222 | ||||
| 223 | // Makes a successful assertion result. | |||
| 224 | GTEST_API___attribute__((visibility("default"))) AssertionResult AssertionSuccess(); | |||
| 225 | ||||
| 226 | // Makes a failed assertion result. | |||
| 227 | GTEST_API___attribute__((visibility("default"))) AssertionResult AssertionFailure(); | |||
| 228 | ||||
| 229 | // Makes a failed assertion result with the given failure message. | |||
| 230 | // Deprecated; use AssertionFailure() << msg. | |||
| 231 | GTEST_API___attribute__((visibility("default"))) AssertionResult AssertionFailure(const Message& msg); | |||
| 232 | ||||
| 233 | } // namespace testing | |||
| 234 | ||||
| 235 | GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 | |||
| 236 | ||||
| 237 | #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_ASSERTION_RESULT_H_ |