mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-31 05:55:28 +00:00
[5097] Added an unit test and 2 examples
This commit is contained in:
@@ -24,7 +24,11 @@
|
||||
# Define a single subnet.
|
||||
"subnet6": [
|
||||
{
|
||||
"pools": [ { "pool": "2001:db8:1::/80" } ],
|
||||
"pools": [
|
||||
{
|
||||
"pool": "2001:db8:1::/80",
|
||||
"user-context": { "charging": true }
|
||||
} ],
|
||||
"subnet": "2001:db8:1::/64",
|
||||
"interface": "ethX"
|
||||
}
|
||||
|
@@ -39,6 +39,8 @@
|
||||
# addresses from the other pool, or the clients obtaining
|
||||
# stateless configuration will be assigned subnet specific value
|
||||
# of option 12, i.e. 2001:db8:1:0:ff00::1.
|
||||
# For DHCPv6 subnets can have prefix delegation pools too so
|
||||
# a pd-pools with an option-data is defined too.
|
||||
"subnet6": [
|
||||
{
|
||||
"option-data": [
|
||||
@@ -65,6 +67,19 @@
|
||||
"pool": "2001:db8:1::500 - 2001:db8:2::1000"
|
||||
}
|
||||
],
|
||||
"pd-pools": [
|
||||
{
|
||||
"prefix": "2001:2b8:2::",
|
||||
"prefix-len": 56,
|
||||
"delegated-len": 64,
|
||||
"option-data": [
|
||||
{
|
||||
"code": 12,
|
||||
"data": "3001:cafe::12:"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"subnet": "2001:db8:1::/64",
|
||||
"interface": "ethX"
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
|
||||
namespace isc {
|
||||
namespace data {
|
||||
|
@@ -1,9 +1,10 @@
|
||||
// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
|
||||
// Copyright (C) 2016-2017 Internet Systems Consortium, Inc. ("ISC")
|
||||
//
|
||||
// This Source Code Form is subject to the terms of the Mozilla Public
|
||||
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cc/simple_parser.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
@@ -54,6 +55,18 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class SimpleParserClassTest : public SimpleParser {
|
||||
public:
|
||||
/// @brief Instantiation of extractInt for uint8_t
|
||||
///
|
||||
/// @param name name of the parameter for error report
|
||||
/// @param value value of the parameter
|
||||
uint8_t extractUint8(const std::string& name, ConstElementPtr value) const {
|
||||
return (extractInt<uint8_t, isc::OutOfRange>(name, value));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// This test checks if the parameters can be inherited from the global
|
||||
// scope to the subnet scope.
|
||||
TEST_F(SimpleParserTest, deriveParams) {
|
||||
@@ -130,3 +143,25 @@ TEST_F(SimpleParserTest, setListDefaults) {
|
||||
checkIntegerValue(third, "rebind-timer", 1800);
|
||||
checkIntegerValue(third, "renew-timer", 900);
|
||||
}
|
||||
|
||||
// This test exercises the extractInt template
|
||||
TEST_F(SimpleParserTest, extractInt) {
|
||||
|
||||
SimpleParserClassTest parser;
|
||||
|
||||
// extractInt checks if it is an integer
|
||||
ConstElementPtr not_int(new StringElement("xyz"));
|
||||
EXPECT_THROW(parser.extractUint8("foo", not_int), TypeError);
|
||||
|
||||
// extractInt checks bounds
|
||||
ConstElementPtr negative(new IntElement(-1));
|
||||
EXPECT_THROW(parser.extractUint8("foo", negative), isc::OutOfRange);
|
||||
ConstElementPtr too_large(new IntElement(1024));
|
||||
EXPECT_THROW(parser.extractUint8("foo", too_large),isc::OutOfRange);
|
||||
|
||||
// checks if extractInt can return the expected value
|
||||
ConstElementPtr hundred(new IntElement(100));
|
||||
uint8_t val = 0;
|
||||
EXPECT_NO_THROW(val = parser.extractUint8("foo", hundred));
|
||||
EXPECT_EQ(100, val);
|
||||
}
|
||||
|
Reference in New Issue
Block a user