2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-31 05:55:28 +00:00

[2491] Added a function to add boolean data field to an array.

This commit is contained in:
Marcin Siodelski
2012-12-03 13:26:14 +01:00
parent 5c50504446
commit 6b59d1bc4f
3 changed files with 34 additions and 0 deletions

View File

@@ -63,6 +63,15 @@ OptionCustom::addArrayDataField(const asiolink::IOAddress& address) {
buffers_.push_back(buf);
}
void
OptionCustom::addArrayDataField(const bool value) {
checkArrayType();
OptionBuffer buf;
OptionDataTypeUtil::writeBool(value, buf);
buffers_.push_back(buf);
}
void
OptionCustom::checkArrayType() const {
if (!definition_.getArrayType()) {

View File

@@ -93,6 +93,11 @@ public:
/// a buffer being created.
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.
///
/// @return number of data fields held by the option.

View File

@@ -973,6 +973,9 @@ TEST_F(OptionCustomTest, setFqdnData) {
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) {
OptionDefinition opt_def("OPTION_FOO", 1000, "boolean", true);
@@ -984,7 +987,24 @@ TEST_F(OptionCustomTest, setBooleanDataArray) {
);
ASSERT_TRUE(option);
// Initially, the array should contain no values.
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