From: Tomek Mrugalski Date: Fri, 27 Jan 2017 19:42:16 +0000 (+0100) Subject: [5122] Obsolete ParserContext class removed. X-Git-Tag: trac5126_base~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d3bfac3329c84c12dc580ee733be9829cbfd3d17;p=thirdparty%2Fkea.git [5122] Obsolete ParserContext class removed. --- diff --git a/src/bin/dhcp4/json_config_parser.cc b/src/bin/dhcp4/json_config_parser.cc index fe8e17da7f..d3cff2d9f9 100644 --- a/src/bin/dhcp4/json_config_parser.cc +++ b/src/bin/dhcp4/json_config_parser.cc @@ -423,9 +423,6 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) { LOG_DEBUG(dhcp4_logger, DBG_DHCP4_COMMAND, DHCP4_CONFIG_START).arg(config_set->str()); - // Reset global context. - globalContext().reset(new ParserContext(Option::V4)); - // Before starting any subnet operations, let's reset the subnet-id counter, // so newly recreated configuration starts with first subnet-id equal 1. Subnet::resetSubnetID(); @@ -444,15 +441,6 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) { // the same risk of failure as doing the change.) HooksLibrariesParser hooks_parser; - // The subnet parsers implement data inheritance by directly - // accessing global storage. For this reason the global data - // parsers must store the parsed data into global storages - // immediately. This may cause data inconsistency if the - // parsing operation fails after the global storage has been - // modified. We need to preserve the original global data here - // so as we can rollback changes when an error occurs. - ParserContext original_context(*globalContext()); - // Answer will hold the result. ConstElementPtr answer; // Rollback informs whether error occurred and original data @@ -661,7 +649,6 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) { // Rollback changes as the configuration parsing failed. if (rollback) { - globalContext().reset(new ParserContext(original_context)); // Revert to original configuration of runtime option definitions // in the libdhcp++. LibDHCP::revertRuntimeOptionDefs(); @@ -677,10 +664,5 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) { return (answer); } -ParserContextPtr& globalContext() { - static ParserContextPtr global_context_ptr(new ParserContext(Option::V4)); - return (global_context_ptr); -} - }; // end of isc::dhcp namespace }; // end of isc namespace diff --git a/src/bin/dhcp4/json_config_parser.h b/src/bin/dhcp4/json_config_parser.h index 4588200057..df25a3d032 100644 --- a/src/bin/dhcp4/json_config_parser.h +++ b/src/bin/dhcp4/json_config_parser.h @@ -53,11 +53,6 @@ isc::data::ConstElementPtr configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set); -/// @brief Returns the global context -/// -/// @return a reference to the global context -ParserContextPtr& globalContext(); - }; // end of isc::dhcp namespace }; // end of isc namespace diff --git a/src/bin/dhcp4/tests/config_parser_unittest.cc b/src/bin/dhcp4/tests/config_parser_unittest.cc index 2448976d89..6d2bfcc868 100644 --- a/src/bin/dhcp4/tests/config_parser_unittest.cc +++ b/src/bin/dhcp4/tests/config_parser_unittest.cc @@ -166,23 +166,10 @@ public: // is sane. srv_.reset(new Dhcpv4Srv(0)); // Create fresh context. - globalContext()->copyContext(ParserContext(Option::V4)); resetConfiguration(); } public: - // Checks if global parameter of name have expected_value - void checkGlobalUint32(string name, uint32_t expected_value) { - const Uint32StoragePtr uint32_defaults = - globalContext()->uint32_values_; - try { - uint32_t actual_value = uint32_defaults->getParam(name); - EXPECT_EQ(expected_value, actual_value); - } catch (DhcpConfigError) { - ADD_FAILURE() << "Expected uint32 with name " << name - << " not found"; - } - } // Checks if the result of DHCP server configuration has // expected code (0 for success, other for failures). @@ -2864,26 +2851,23 @@ TEST_F(Dhcp4ParserTest, DISABLED_Uint32Parser) { // CASE 1: 0 - minimum value, should work EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, - parseDHCP4("{\"version\": 0," - "\"renew-timer\": 0}"))); + parseDHCP4("{\"renew-timer\": 0}"))); // returned value must be ok (0 is a proper value) checkResult(status, 0); - checkGlobalUint32("renew-timer", 0); + /// @todo: check that the renew-timer is really 0 // CASE 2: 4294967295U (UINT_MAX) should work as well EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, - parseDHCP4("{\"version\": 0," - "\"renew-timer\": 4294967295}"))); + parseDHCP4("{\"renew-timer\": 4294967295}"))); // returned value must be ok (0 is a proper value) checkResult(status, 0); - checkGlobalUint32("renew-timer", 4294967295U); + /// @todo: check that the renew-timer is really 4294967295U // CASE 3: 4294967296U (UINT_MAX + 1) should not work EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, - parseJSON("{\"version\": 0," - "\"renew-timer\": 4294967296}"))); + parseJSON("{\"renew-timer\": 4294967296}"))); // returned value must be rejected (1 configuration error) checkResult(status, 1); @@ -2891,8 +2875,7 @@ TEST_F(Dhcp4ParserTest, DISABLED_Uint32Parser) { // CASE 4: -1 (UINT_MIN -1 ) should not work EXPECT_NO_THROW(status = configureDhcp4Server(*srv_, - parseJSON("{\"version\": 0," - "\"renew-timer\": -1}"))); + parseJSON("{\"renew-timer\": -1}"))); // returned value must be rejected (1 configuration error) checkResult(status, 1); diff --git a/src/bin/dhcp6/json_config_parser.cc b/src/bin/dhcp6/json_config_parser.cc index 8c4a5a3442..5c3d0dda6b 100644 --- a/src/bin/dhcp6/json_config_parser.cc +++ b/src/bin/dhcp6/json_config_parser.cc @@ -701,9 +701,6 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) { LOG_DEBUG(dhcp6_logger, DBG_DHCP6_COMMAND, DHCP6_CONFIG_START).arg(config_set->str()); - // Reset global context. - globalContext().reset(new ParserContext(Option::V6)); - // Before starting any subnet operations, let's reset the subnet-id counter, // so newly recreated configuration starts with first subnet-id equal 1. Subnet::resetSubnetID(); @@ -722,15 +719,6 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) { // has the same risk of failure as doing the change.) HooksLibrariesParser hooks_parser; - // The subnet parsers implement data inheritance by directly - // accessing global storage. For this reason the global data - // parsers must store the parsed data into global storages - // immediately. This may cause data inconsistency if the - // parsing operation fails after the global storage has been - // modified. We need to preserve the original global data here - // so as we can rollback changes when an error occurs. - ParserContext original_context(*globalContext()); - // This is a way to convert ConstElementPtr to ElementPtr. // We need a config that can be edited, because we will insert // default values and will insert derived values as well. @@ -958,7 +946,6 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) { // Rollback changes as the configuration parsing failed. if (rollback) { - globalContext().reset(new ParserContext(original_context)); // Revert to original configuration of runtime option definitions // in the libdhcp++. LibDHCP::revertRuntimeOptionDefs(); @@ -974,10 +961,5 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) { return (answer); } -ParserContextPtr& globalContext() { - static ParserContextPtr global_context_ptr(new ParserContext(Option::V6)); - return (global_context_ptr); -} - }; // end of isc::dhcp namespace }; // end of isc namespace diff --git a/src/bin/dhcp6/json_config_parser.h b/src/bin/dhcp6/json_config_parser.h index 7326878331..c60e8c06fd 100644 --- a/src/bin/dhcp6/json_config_parser.h +++ b/src/bin/dhcp6/json_config_parser.h @@ -38,11 +38,6 @@ class Dhcpv6Srv; isc::data::ConstElementPtr configureDhcp6Server(Dhcpv6Srv& server, isc::data::ConstElementPtr config_set); -/// @brief Returns the global context -/// -/// @returns a reference to the global context -ParserContextPtr& globalContext(); - }; // end of isc::dhcp namespace }; // end of isc namespace diff --git a/src/bin/dhcp6/tests/config_parser_unittest.cc b/src/bin/dhcp6/tests/config_parser_unittest.cc index 8ab355323d..34aaa6a500 100644 --- a/src/bin/dhcp6/tests/config_parser_unittest.cc +++ b/src/bin/dhcp6/tests/config_parser_unittest.cc @@ -524,8 +524,6 @@ public: // all interfaces before each test and later check that this setting // has been overridden by the configuration used in the test. CfgMgr::instance().clear(); - // Create fresh context. - globalContext()->copyContext(ParserContext(Option::V6)); } /// @brief Retrieve an option associated with a host. diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc index 57b4c33d3f..c8742f98d8 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc +++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc @@ -34,61 +34,6 @@ using namespace isc::util; namespace isc { namespace dhcp { -// *********************** ParserContext ************************* - -ParserContext::ParserContext(Option::Universe universe): - boolean_values_(new BooleanStorage()), - uint32_values_(new Uint32Storage()), - string_values_(new StringStorage()), - hooks_libraries_(), - universe_(universe) -{ -} - -ParserContext::ParserContext(const ParserContext& rhs): - boolean_values_(), - uint32_values_(), - string_values_(), - hooks_libraries_(), - universe_(rhs.universe_) -{ - copyContext(rhs); -} - -ParserContext& -// The cppcheck version 1.56 doesn't recognize that copyContext -// copies all context fields. -// cppcheck-suppress operatorEqVarError -ParserContext::operator=(const ParserContext& rhs) { - if (this != &rhs) { - copyContext(rhs); - } - - return (*this); -} - -void -ParserContext::copyContext(const ParserContext& ctx) { - copyContextPointer(ctx.boolean_values_, boolean_values_); - copyContextPointer(ctx.uint32_values_, uint32_values_); - copyContextPointer(ctx.string_values_, string_values_); - copyContextPointer(ctx.hooks_libraries_, hooks_libraries_); - // Copy universe. - universe_ = ctx.universe_; -} - -template -void -ParserContext::copyContextPointer(const boost::shared_ptr& source_ptr, - boost::shared_ptr& dest_ptr) { - if (source_ptr) { - dest_ptr.reset(new T(*source_ptr)); - } else { - dest_ptr.reset(); - } -} - - // **************************** DebugParser ************************* DebugParser::DebugParser(const std::string& param_name) diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.h b/src/lib/dhcpsrv/parsers/dhcp_parsers.h index 625f9d901b..26d6c38fc2 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_parsers.h +++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.h @@ -183,68 +183,6 @@ typedef boost::shared_ptr StringStoragePtr; typedef ValueStorage BooleanStorage; typedef boost::shared_ptr BooleanStoragePtr; -/// @brief Container for the current parsing context. It provides a -/// single enclosure for the storage of configuration parameters, -/// options, option definitions, and other context specific information -/// that needs to be accessible throughout the parsing and parsing -/// constructs. -class ParserContext { -public: - /// @brief Constructor - /// - /// @param universe is the Option::Universe value of this - /// context. - ParserContext(Option::Universe universe); - - /// @brief Copy constructor - ParserContext(const ParserContext& rhs); - - /// @brief Storage for boolean parameters. - BooleanStoragePtr boolean_values_; - - /// @brief Storage for uint32 parameters. - Uint32StoragePtr uint32_values_; - - /// @brief Storage for string parameters. - StringStoragePtr string_values_; - - /// @brief Hooks libraries pointer. - /// - /// The hooks libraries information is a vector of strings, each containing - /// the name of a library. Hooks libraries should only be reloaded if the - /// list of names has changed, so the list of current DHCP parameters - /// (in isc::dhcp::CfgMgr) contains an indication as to whether the list has - /// altered. This indication is implemented by storing a pointer to the - /// list of library names which is cleared when the libraries are loaded. - /// So either the pointer is null (meaning don't reload the libraries and - /// the list of current names can be obtained from the HooksManager) or it - /// is non-null (this is the new list of names, reload the libraries when - /// possible). - isc::hooks::HookLibsCollectionPtr hooks_libraries_; - - /// @brief The parsing universe of this context. - Option::Universe universe_; - - /// @brief Assignment operator - ParserContext& operator=(const ParserContext& rhs); - - /// @brief Copy the context fields. - /// - /// This class method initializes the context data by copying the data - /// stored in the context instance provided as an argument. Note that - /// this function will also handle copying the NULL pointers. - /// - /// @param ctx context to be copied. - void copyContext(const ParserContext& ctx); - - template - void copyContextPointer(const boost::shared_ptr& source_ptr, - boost::shared_ptr& dest_ptr); -}; - -/// @brief Pointer to various parser context. -typedef boost::shared_ptr ParserContextPtr; - /// @brief Simple data-type parser template class /// /// This is the template class for simple data-type parsers. It supports @@ -629,10 +567,6 @@ private: uint16_t address_family_; }; -///@brief Function pointer for OptionDataParser factory methods -typedef OptionDataParser *OptionDataParserFactory(const std::string&, - OptionStoragePtr options, ParserContextPtr global_context); - /// @brief Parser for option data values within a subnet. /// /// This parser iterates over all entries that define options diff --git a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc index 3b32b35566..0a293ef5e3 100644 --- a/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc +++ b/src/lib/dhcpsrv/tests/dhcp_parsers_unittest.cc @@ -321,7 +321,8 @@ TEST_F(DhcpParserTest, MacSourcesDuplicate) { class ParseConfigTest : public ::testing::Test { public: /// @brief Constructor - ParseConfigTest() { + ParseConfigTest() + :family_(AF_INET6) { reset_context(); CfgMgr::instance().clear(); } @@ -382,9 +383,6 @@ public: } } - int family = parser_context_->universe_ == Option::V4 - ? AF_INET : AF_INET6; - // The option definition parser is the next one to be run. std::map::const_iterator def_config = values_map.find("option-def"); @@ -401,7 +399,7 @@ public: if (option_config != values_map.end()) { CfgOptionPtr cfg_option = CfgMgr::instance().getStagingCfg()->getCfgOption(); - OptionDataListParser option_list_parser(family); + OptionDataListParser option_list_parser(family_); option_list_parser.parse(cfg_option, option_config->second); } @@ -600,7 +598,7 @@ public: void reset_context(){ // Note set context universe to V6 as it has to be something. CfgMgr::instance().clear(); - parser_context_.reset(new ParserContext(Option::V6)); + family_ = AF_INET6; // Ensure no hooks libraries are loaded. HooksManager::unloadLibraries(); @@ -615,8 +613,8 @@ public: /// Allows the tests to interrogate the state of the parsers (if required). boost::shared_ptr hooks_libraries_parser_; - /// @brief Parser context - provides storage for options and definitions - ParserContextPtr parser_context_; + /// @brief specifies IP protocol family (AF_INET or AF_INET6) + uint16_t family_; /// @brief Error string if the parsing failed std::string error_text_; @@ -818,7 +816,7 @@ TEST_F(ParseConfigTest, minimalOptionDataTest) { /// has the actual character (e.g. an actual backslash, not double backslash). TEST_F(ParseConfigTest, escapedOptionDataTest) { - parser_context_->universe_ = Option::V4; + family_ = AF_INET; // We need to use double escapes here. The first backslash will // be consumed by C++ preprocessor, so the actual string will @@ -867,7 +865,7 @@ TEST_F(ParseConfigTest, optionDataCSVFormatWithOptionDef) { // The default universe is V6. We need to change it to use dhcp4 option // space. - parser_context_->universe_ = Option::V4; + family_ = AF_INET; int rcode = 0; ASSERT_NO_THROW(rcode = parseConfiguration(config)); ASSERT_EQ(0, rcode); @@ -931,7 +929,7 @@ TEST_F(ParseConfigTest, encapsulatedOptionData) { "}"; // Make sure that we're using correct universe. - parser_context_->universe_ = Option::V6; + family_ = AF_INET6; int rcode = 0; ASSERT_NO_THROW(rcode = parseConfiguration(config)); ASSERT_EQ(0, rcode); @@ -1203,7 +1201,7 @@ TEST_F(ParseConfigTest, optionDataNoSubOpion) { // The default universe is V6. We need to change it to use dhcp4 option // space. - parser_context_->universe_ = Option::V4; + family_ = AF_INET; int rcode = 0; ASSERT_NO_THROW(rcode = parseConfiguration(config)); EXPECT_EQ(0, rcode); @@ -2030,410 +2028,6 @@ TEST_F(ParseConfigTest, invalidD2Config) { } } -/// @brief DHCP Configuration Parser Context test fixture. -class ParserContextTest : public ::testing::Test { -public: - /// @brief Constructor - ParserContextTest() { } - - /// @brief Check that the storages of the specific type hold the - /// same value. - /// - /// This function assumes that the ref_values storage holds parameter - /// called 'foo'. - /// - /// @param ref_values A storage holding reference value. In the typical - /// case it is a storage held in the original context, which is assigned - /// to another context. - /// @param values A storage holding value to be checked. - /// @tparam ContainerType A type of the storage. - template - void checkValueEq(const boost::shared_ptr& ref_values, - const boost::shared_ptr& values) { - ASSERT_NO_THROW(values->getParam("foo")); - EXPECT_EQ(ref_values->getParam("foo"), values->getParam("foo")); - } - - /// @brief Check that the storages of the specific type hold the same - /// position of the parameter. - /// - /// @param name A name of the parameter to check. - /// @param ref_values A storage holding reference position. In the typical - /// case it is a storage held in the original context, which is assigned - /// to another context. - /// @param values A storage holding position to be checked. - /// @tparam ContainerType A type of the storage. - template - void checkPositionEq(const std::string& name, - const boost::shared_ptr& ref_values, - const boost::shared_ptr& values) { - // Verify that the position is correct. - EXPECT_EQ(ref_values->getPosition(name).line_, - values->getPosition(name).line_); - - EXPECT_EQ(ref_values->getPosition(name).pos_, - values->getPosition(name).pos_); - - EXPECT_EQ(ref_values->getPosition(name).file_, - values->getPosition(name).file_); - } - - /// @brief Check that the storages of the specific type hold different - /// value. - /// - /// This function assumes that the ref_values storage holds exactly - /// one parameter called 'foo'. - /// - /// @param ref_values A storage holding reference value. In the typical - /// case it is a storage held in the original context, which is assigned - /// to another context. - /// @param values A storage holding value to be checked. - /// @tparam ContainerType A type of the storage. - /// @tparam ValueType A type of the value in the container. - template - void checkValueNeq(const boost::shared_ptr& ref_values, - const boost::shared_ptr& values) { - ASSERT_NO_THROW(values->getParam("foo")); - EXPECT_NE(ref_values->getParam("foo"), values->getParam("foo")); - } - - /// @brief Check that the storages of the specific type hold different - /// position. - /// - /// @param name A name of the parameter to be checked. - /// @param ref_values A storage holding reference position. In the typical - /// case it is a storage held in the original context, which is assigned - /// to another context. - /// @param values A storage holding position to be checked. - /// @tparam ContainerType A type of the storage. - template - void checkPositionNeq(const std::string& name, - const boost::shared_ptr& ref_values, - const boost::shared_ptr& values) { - // At least one of the position fields must be different. - EXPECT_TRUE((ref_values->getPosition(name).line_ != - values->getPosition(name).line_) || - (ref_values->getPosition(name).pos_ != - values->getPosition(name).pos_) || - (ref_values->getPosition(name).file_ != - values->getPosition(name).file_)); - } - - /// @brief Test copy constructor or assignment operator when values - /// being copied are NULL. - /// - /// @param copy Indicates that copy constructor should be tested - /// (if true), or assignment operator (if false). - void testCopyAssignmentNull(const bool copy) { - ParserContext ctx(Option::V6); - // Release all pointers in the context. - ctx.boolean_values_.reset(); - ctx.uint32_values_.reset(); - ctx.string_values_.reset(); - ctx.hooks_libraries_.reset(); - - // Even if the fields of the context are NULL, it should get - // copied. - ParserContextPtr ctx_new(new ParserContext(Option::V6)); - if (copy) { - ASSERT_NO_THROW(ctx_new.reset(new ParserContext(ctx))); - } else { - *ctx_new = ctx; - } - - // The resulting context has its fields equal to NULL. - EXPECT_FALSE(ctx_new->boolean_values_); - EXPECT_FALSE(ctx_new->uint32_values_); - EXPECT_FALSE(ctx_new->string_values_); - EXPECT_FALSE(ctx_new->hooks_libraries_); - - } - - /// @brief Test copy constructor or assignment operator. - /// - /// @param copy Indicates that copy constructor should be tested (if true), - /// or assignment operator (if false). - void testCopyAssignment(const bool copy) { - // Create new context. It will be later copied/assigned to another - // context. - ParserContext ctx(Option::V6); - - // Set boolean parameter 'foo'. - ASSERT_TRUE(ctx.boolean_values_); - ctx.boolean_values_->setParam("foo", true, - Element::Position("kea.conf", 123, 234)); - - // Set various parameters to test that position is copied between - // contexts. - ctx.boolean_values_->setParam("pos0", true, - Element::Position("kea.conf", 1, 2)); - ctx.boolean_values_->setParam("pos1", true, - Element::Position("kea.conf", 10, 20)); - ctx.boolean_values_->setParam("pos2", true, - Element::Position("kea.conf", 100, 200)); - - // Set uint32 parameter 'foo'. - ASSERT_TRUE(ctx.uint32_values_); - ctx.uint32_values_->setParam("foo", 123, - Element::Position("kea.conf", 123, 234)); - - // Set various parameters to test that position is copied between - // contexts. - ctx.uint32_values_->setParam("pos0", 123, - Element::Position("kea.conf", 1, 2)); - ctx.uint32_values_->setParam("pos1", 123, - Element::Position("kea.conf", 10, 20)); - ctx.uint32_values_->setParam("pos2", 123, - Element::Position("kea.conf", 100, 200)); - - // Ser string parameter 'foo'. - ASSERT_TRUE(ctx.string_values_); - ctx.string_values_->setParam("foo", "some string", - Element::Position("kea.conf", 123, 234)); - - // Set various parameters to test that position is copied between - // contexts. - ctx.string_values_->setParam("pos0", "some string", - Element::Position("kea.conf", 1, 2)); - ctx.string_values_->setParam("pos1", "some string", - Element::Position("kea.conf", 10, 20)); - ctx.string_values_->setParam("pos2", "some string", - Element::Position("kea.conf", 100, 200)); - - - // Allocate container for hooks libraries and add one library name. - ctx.hooks_libraries_.reset(new std::vector()); - ctx.hooks_libraries_->push_back(make_pair("library1", ConstElementPtr())); - - // We will use ctx_new to assign another context to it or copy - // construct. - ParserContextPtr ctx_new(new ParserContext(Option::V4));; - if (copy) { - ctx_new.reset(new ParserContext(ctx)); - } else { - *ctx_new = ctx; - } - - // New context has the same boolean value. - ASSERT_TRUE(ctx_new->boolean_values_); - { - SCOPED_TRACE("Check that boolean values are equal in both" - " contexts"); - checkValueEq(ctx.boolean_values_, ctx_new->boolean_values_); - } - - // New context has the same boolean values' positions. - { - SCOPED_TRACE("Check that positions of boolean values are equal" - " in both contexts"); - checkPositionEq("pos0", ctx.boolean_values_, - ctx_new->boolean_values_); - checkPositionEq("pos1", ctx.boolean_values_, - ctx_new->boolean_values_); - checkPositionEq("pos2", ctx.boolean_values_, - ctx_new->boolean_values_); - } - - // New context has the same uint32 value. - ASSERT_TRUE(ctx_new->uint32_values_); - { - SCOPED_TRACE("Check that uint32_t values are equal in both" - " contexts"); - checkValueEq(ctx.uint32_values_, ctx_new->uint32_values_); - } - - // New context has the same uint32 values' positions. - { - SCOPED_TRACE("Check that positions of uint32 values are equal" - " in both contexts"); - checkPositionEq("pos0", ctx.uint32_values_, - ctx_new->uint32_values_); - checkPositionEq("pos1", ctx.uint32_values_, - ctx_new->uint32_values_); - checkPositionEq("pos2", ctx.uint32_values_, - ctx_new->uint32_values_); - } - - // New context has the same uint32 value position. - { - SCOPED_TRACE("Check that positions of uint32_t values are equal" - " in both contexts"); - checkPositionEq("foo", ctx.uint32_values_, ctx_new->uint32_values_); - } - - // New context has the same string value. - ASSERT_TRUE(ctx_new->string_values_); - { - SCOPED_TRACE("Check that string values are equal in both contexts"); - checkValueEq(ctx.string_values_, ctx_new->string_values_); - } - - // New context has the same string values' positions. - { - SCOPED_TRACE("Check that positions of string values are equal" - " in both contexts"); - checkPositionEq("pos0", ctx.string_values_, - ctx_new->string_values_); - checkPositionEq("pos1", ctx.string_values_, - ctx_new->string_values_); - checkPositionEq("pos2", ctx.string_values_, - ctx_new->string_values_); - } - - // New context has the same hooks library. - ASSERT_TRUE(ctx_new->hooks_libraries_); - { - ASSERT_EQ(1, ctx_new->hooks_libraries_->size()); - EXPECT_EQ("library1", (*ctx_new->hooks_libraries_)[0].first); - } - - // New context has the same universe. - EXPECT_EQ(ctx.universe_, ctx_new->universe_); - - // Change the value of the boolean parameter. This should not affect the - // corresponding value in the new context. - { - SCOPED_TRACE("Check that boolean value isn't changed when original" - " value and position is changed"); - ctx.boolean_values_->setParam("foo", false, - Element::Position("kea.conf", - 12, 10)); - checkValueNeq(ctx.boolean_values_, ctx_new->boolean_values_); - - } - - { - SCOPED_TRACE("Check that positions of the boolean parameters aren't" - " changed when the corresponding positions in the" - " original context are changed"); - // Modify file name. - ctx.boolean_values_->setParam("pos0", false, - Element::Position("foo.conf", - 1, 2)); - checkPositionNeq("pos0", ctx.boolean_values_, - ctx_new->boolean_values_); - // Modify line number. - ctx.boolean_values_->setParam("pos1", false, - Element::Position("kea.conf", - 11, 20)); - checkPositionNeq("pos1", ctx.boolean_values_, - ctx_new->boolean_values_); - // Modify position within a line. - ctx.boolean_values_->setParam("pos2", false, - Element::Position("kea.conf", - 101, 201)); - checkPositionNeq("pos2", ctx.boolean_values_, - ctx_new->boolean_values_); - - } - - // Change the value of the uint32_t parameter. This should not affect - // the corresponding value in the new context. - { - SCOPED_TRACE("Check that uint32_t value isn't changed when original" - " value and position is changed"); - ctx.uint32_values_->setParam("foo", 987, - Element::Position("kea.conf", 10, 11)); - checkValueNeq(ctx.uint32_values_, ctx_new->uint32_values_); - } - - { - SCOPED_TRACE("Check that positions of the uint32 parameters aren't" - " changed when the corresponding positions in the" - " original context are changed"); - // Modify file name. - ctx.uint32_values_->setParam("pos0", 123, - Element::Position("foo.conf", 1, 2)); - checkPositionNeq("pos0", ctx.uint32_values_, - ctx_new->uint32_values_); - // Modify line number. - ctx.uint32_values_->setParam("pos1", 123, - Element::Position("kea.conf", - 11, 20)); - checkPositionNeq("pos1", ctx.uint32_values_, - ctx_new->uint32_values_); - // Modify position within a line. - ctx.uint32_values_->setParam("pos2", 123, - Element::Position("kea.conf", - 101, 201)); - checkPositionNeq("pos2", ctx.uint32_values_, - ctx_new->uint32_values_); - - } - - // Change the value of the string parameter. This should not affect the - // corresponding value in the new context. - { - SCOPED_TRACE("Check that string value isn't changed when original" - " value and position is changed"); - ctx.string_values_->setParam("foo", "different string", - Element::Position("kea.conf", 10, 11)); - checkValueNeq(ctx.string_values_, ctx_new->string_values_); - } - - { - SCOPED_TRACE("Check that positions of the string parameters aren't" - " changed when the corresponding positions in the" - " original context are changed"); - // Modify file name. - ctx.string_values_->setParam("pos0", "some string", - Element::Position("foo.conf", 1, 2)); - checkPositionNeq("pos0", ctx.string_values_, - ctx_new->string_values_); - // Modify line number. - ctx.string_values_->setParam("pos1", "some string", - Element::Position("kea.conf", - 11, 20)); - checkPositionNeq("pos1", ctx.string_values_, - ctx_new->string_values_); - // Modify position within a line. - ctx.string_values_->setParam("pos2", "some string", - Element::Position("kea.conf", - 101, 201)); - checkPositionNeq("pos2", ctx.string_values_, - ctx_new->string_values_); - - } - - // Change the list of libraries. this should not affect the list in the - // new context. - ctx.hooks_libraries_->clear(); - ctx.hooks_libraries_->push_back(make_pair("library2", ConstElementPtr())); - ASSERT_EQ(1, ctx_new->hooks_libraries_->size()); - EXPECT_EQ("library1", (*ctx_new->hooks_libraries_)[0].first); - - // Change the universe. This should not affect the universe value in the - // new context. - ctx.universe_ = Option::V4; - EXPECT_EQ(Option::V6, ctx_new->universe_); - - } - -}; - -// Check that the assignment operator of the ParserContext class copies all -// fields correctly. -TEST_F(ParserContextTest, assignment) { - testCopyAssignment(false); -} - -// Check that the assignment operator of the ParserContext class copies all -// fields correctly when these fields are NULL. -TEST_F(ParserContextTest, assignmentNull) { - testCopyAssignmentNull(false); -} - -// Check that the context is copy constructed correctly. -TEST_F(ParserContextTest, copyConstruct) { - testCopyAssignment(true); -} - -// Check that the context is copy constructed correctly, when context fields -// are NULL. -TEST_F(ParserContextTest, copyConstructNull) { - testCopyAssignmentNull(true); -} - /// @brief Checks that a valid relay info structure for IPv4 can be handled TEST_F(ParseConfigTest, validRelayInfo4) {