mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-02 15:05:16 +00:00
[2491] Added a function to add boolean data field to an array.
This commit is contained in:
@@ -63,6 +63,15 @@ OptionCustom::addArrayDataField(const asiolink::IOAddress& address) {
|
|||||||
buffers_.push_back(buf);
|
buffers_.push_back(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
OptionCustom::addArrayDataField(const bool value) {
|
||||||
|
checkArrayType();
|
||||||
|
|
||||||
|
OptionBuffer buf;
|
||||||
|
OptionDataTypeUtil::writeBool(value, buf);
|
||||||
|
buffers_.push_back(buf);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
OptionCustom::checkArrayType() const {
|
OptionCustom::checkArrayType() const {
|
||||||
if (!definition_.getArrayType()) {
|
if (!definition_.getArrayType()) {
|
||||||
|
@@ -93,6 +93,11 @@ public:
|
|||||||
/// a buffer being created.
|
/// a buffer being created.
|
||||||
void addArrayDataField(const asiolink::IOAddress& address);
|
void addArrayDataField(const asiolink::IOAddress& address);
|
||||||
|
|
||||||
|
/// @brief Create new buffer and store boolean value in it.
|
||||||
|
///
|
||||||
|
/// @param value value to be stored in the created buffer.
|
||||||
|
void addArrayDataField(const bool value);
|
||||||
|
|
||||||
/// @brief Return a number of the data fields.
|
/// @brief Return a number of the data fields.
|
||||||
///
|
///
|
||||||
/// @return number of data fields held by the option.
|
/// @return number of data fields held by the option.
|
||||||
|
@@ -973,6 +973,9 @@ TEST_F(OptionCustomTest, setFqdnData) {
|
|||||||
EXPECT_EQ("example.com.", fqdn);
|
EXPECT_EQ("example.com.", fqdn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The purpose of this test is to verify that an option carrying
|
||||||
|
// an array of boolean values can be created with no values
|
||||||
|
// initially and that values can be later added to it.
|
||||||
TEST_F(OptionCustomTest, setBooleanDataArray) {
|
TEST_F(OptionCustomTest, setBooleanDataArray) {
|
||||||
OptionDefinition opt_def("OPTION_FOO", 1000, "boolean", true);
|
OptionDefinition opt_def("OPTION_FOO", 1000, "boolean", true);
|
||||||
|
|
||||||
@@ -984,7 +987,24 @@ TEST_F(OptionCustomTest, setBooleanDataArray) {
|
|||||||
);
|
);
|
||||||
ASSERT_TRUE(option);
|
ASSERT_TRUE(option);
|
||||||
|
|
||||||
|
// Initially, the array should contain no values.
|
||||||
ASSERT_EQ(0, option->getDataFieldsNum());
|
ASSERT_EQ(0, option->getDataFieldsNum());
|
||||||
|
|
||||||
|
// Add some boolean values to it.
|
||||||
|
ASSERT_NO_THROW(option->addArrayDataField(true));
|
||||||
|
ASSERT_NO_THROW(option->addArrayDataField(false));
|
||||||
|
ASSERT_NO_THROW(option->addArrayDataField(true));
|
||||||
|
|
||||||
|
// Verify that the new data fields can be added.
|
||||||
|
bool value0 = false;
|
||||||
|
ASSERT_NO_THROW(value0 = option->readBoolean(0));
|
||||||
|
EXPECT_TRUE(value0);
|
||||||
|
bool value1 = true;
|
||||||
|
ASSERT_NO_THROW(value1 = option->readBoolean(1));
|
||||||
|
EXPECT_FALSE(value1);
|
||||||
|
bool value2 = false;
|
||||||
|
ASSERT_NO_THROW(value2 = option->readBoolean(2));
|
||||||
|
EXPECT_TRUE(value2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The purpose of this test is to verify that an option comprising
|
/// The purpose of this test is to verify that an option comprising
|
||||||
|
Reference in New Issue
Block a user