mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-29 13:07:50 +00:00
[#1928] Copy assignment for class dictionary
This commit is contained in:
parent
7e77245c57
commit
611fed36be
@ -361,6 +361,19 @@ ClientClassDictionary::toElement() const {
|
|||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClientClassDictionary&
|
||||||
|
ClientClassDictionary::operator=(const ClientClassDictionary& rhs) {
|
||||||
|
if (this != &rhs) {
|
||||||
|
list_->clear();
|
||||||
|
map_->clear();
|
||||||
|
for (auto cclass : *(rhs.list_)) {
|
||||||
|
ClientClassDefPtr copy(new ClientClassDef(*cclass));
|
||||||
|
addClass(copy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (*this);
|
||||||
|
}
|
||||||
|
|
||||||
std::list<std::string>
|
std::list<std::string>
|
||||||
builtinNames = {
|
builtinNames = {
|
||||||
// DROP is not in this list because it is special but not built-in.
|
// DROP is not in this list because it is special but not built-in.
|
||||||
|
@ -391,6 +391,12 @@ public:
|
|||||||
return (!equals(other));
|
return (!equals(other));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Copy assignment operator.
|
||||||
|
///
|
||||||
|
/// @param rhs Client class dictionary to be copied from.
|
||||||
|
/// @return Instance copy.
|
||||||
|
ClientClassDictionary& operator=(const ClientClassDictionary& rhs);
|
||||||
|
|
||||||
/// @brief Unparse a configuration object
|
/// @brief Unparse a configuration object
|
||||||
///
|
///
|
||||||
/// @return a pointer to unparsed configuration
|
/// @return a pointer to unparsed configuration
|
||||||
|
@ -431,6 +431,45 @@ TEST(ClientClassDictionary, copyAndEquality) {
|
|||||||
EXPECT_TRUE(*dictionary != *dictionary2);
|
EXPECT_TRUE(*dictionary != *dictionary2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify that client class dictionaries are deep-copied.
|
||||||
|
TEST(ClientClassDictionary, copy) {
|
||||||
|
ClientClassDictionary dictionary;
|
||||||
|
ExpressionPtr expr;
|
||||||
|
CfgOptionPtr options;
|
||||||
|
|
||||||
|
// Get a client class dictionary and fill it.
|
||||||
|
ASSERT_NO_THROW(dictionary.addClass("one", expr, "", false,
|
||||||
|
false, options));
|
||||||
|
ASSERT_NO_THROW(dictionary.addClass("two", expr, "", false,
|
||||||
|
false, options));
|
||||||
|
ASSERT_NO_THROW(dictionary.addClass("three", expr, "", false,
|
||||||
|
false, options));
|
||||||
|
|
||||||
|
// Make a copy with a copy constructor. Expect it to be a deep copy.
|
||||||
|
ClientClassDictionary dictionary_copy(dictionary);
|
||||||
|
ASSERT_NO_THROW(dictionary.removeClass("one"));
|
||||||
|
ASSERT_NO_THROW(dictionary.removeClass("two"));
|
||||||
|
ASSERT_NO_THROW(dictionary.removeClass("three"));
|
||||||
|
EXPECT_TRUE(dictionary.empty());
|
||||||
|
EXPECT_FALSE(dictionary_copy.empty());
|
||||||
|
|
||||||
|
// Refill the client class dictionary.
|
||||||
|
ASSERT_NO_THROW(dictionary.addClass("one", expr, "", false,
|
||||||
|
false, options));
|
||||||
|
ASSERT_NO_THROW(dictionary.addClass("two", expr, "", false,
|
||||||
|
false, options));
|
||||||
|
ASSERT_NO_THROW(dictionary.addClass("three", expr, "", false,
|
||||||
|
false, options));
|
||||||
|
|
||||||
|
// Make a copy with operator=. Expect it to be a deep copy.
|
||||||
|
dictionary_copy = dictionary;
|
||||||
|
ASSERT_NO_THROW(dictionary.removeClass("one"));
|
||||||
|
ASSERT_NO_THROW(dictionary.removeClass("two"));
|
||||||
|
ASSERT_NO_THROW(dictionary.removeClass("three"));
|
||||||
|
EXPECT_TRUE(dictionary.empty());
|
||||||
|
EXPECT_FALSE(dictionary_copy.empty());
|
||||||
|
}
|
||||||
|
|
||||||
// Tests dependency.
|
// Tests dependency.
|
||||||
TEST(ClientClassDictionary, dependency) {
|
TEST(ClientClassDictionary, dependency) {
|
||||||
ClientClassDictionaryPtr dictionary(new ClientClassDictionary());
|
ClientClassDictionaryPtr dictionary(new ClientClassDictionary());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user