mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-01 14:35:29 +00:00
[4313] Added TokenOption::getRepresention()
This commit is contained in:
@@ -72,24 +72,32 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// @brief checks if the given token is an option with the expected code
|
/// @brief checks if the given token is an option with the expected code
|
||||||
void checkTokenOption(const TokenPtr& token, uint16_t expected_code) {
|
/// and representation type
|
||||||
|
void checkTokenOption(const TokenPtr& token,
|
||||||
|
uint16_t expected_code,
|
||||||
|
TokenOption::RepresentationType expected_repr) {
|
||||||
ASSERT_TRUE(token);
|
ASSERT_TRUE(token);
|
||||||
boost::shared_ptr<TokenOption> opt =
|
boost::shared_ptr<TokenOption> opt =
|
||||||
boost::dynamic_pointer_cast<TokenOption>(token);
|
boost::dynamic_pointer_cast<TokenOption>(token);
|
||||||
ASSERT_TRUE(opt);
|
ASSERT_TRUE(opt);
|
||||||
|
|
||||||
EXPECT_EQ(expected_code, opt->getCode());
|
EXPECT_EQ(expected_code, opt->getCode());
|
||||||
|
EXPECT_EQ(expected_repr, opt->getRepresentation());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief check if the given token is relay4 with the expected code
|
/// @brief check if the given token is relay4 with the expected code
|
||||||
void checkTokenRelay4(const TokenPtr& token, uint16_t code) {
|
/// and representation type
|
||||||
|
void checkTokenRelay4(const TokenPtr& token,
|
||||||
|
uint16_t expected_code,
|
||||||
|
TokenOption::RepresentationType expected_repr) {
|
||||||
ASSERT_TRUE(token);
|
ASSERT_TRUE(token);
|
||||||
boost::shared_ptr<TokenRelay4Option> relay4 =
|
boost::shared_ptr<TokenRelay4Option> relay4 =
|
||||||
boost::dynamic_pointer_cast<TokenRelay4Option>(token);
|
boost::dynamic_pointer_cast<TokenRelay4Option>(token);
|
||||||
EXPECT_TRUE(relay4);
|
EXPECT_TRUE(relay4);
|
||||||
|
|
||||||
if (relay4) {
|
if (relay4) {
|
||||||
EXPECT_EQ(code, relay4->getCode());
|
EXPECT_EQ(expected_code, relay4->getCode());
|
||||||
|
EXPECT_EQ(expected_repr, relay4->getRepresentation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,7 +234,7 @@ TEST_F(EvalContextTest, option) {
|
|||||||
EXPECT_NO_THROW(parsed_ = eval.parseString("option[123].text == 'foo'"));
|
EXPECT_NO_THROW(parsed_ = eval.parseString("option[123].text == 'foo'"));
|
||||||
EXPECT_TRUE(parsed_);
|
EXPECT_TRUE(parsed_);
|
||||||
ASSERT_EQ(3, eval.expression.size());
|
ASSERT_EQ(3, eval.expression.size());
|
||||||
checkTokenOption(eval.expression.at(0), 123);
|
checkTokenOption(eval.expression.at(0), 123, TokenOption::TEXTUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test parsing of an option identified by name.
|
// Test parsing of an option identified by name.
|
||||||
@@ -237,7 +245,7 @@ TEST_F(EvalContextTest, optionWithName) {
|
|||||||
EXPECT_NO_THROW(parsed_ = eval.parseString("option[host-name].text == 'foo'"));
|
EXPECT_NO_THROW(parsed_ = eval.parseString("option[host-name].text == 'foo'"));
|
||||||
EXPECT_TRUE(parsed_);
|
EXPECT_TRUE(parsed_);
|
||||||
ASSERT_EQ(3, eval.expression.size());
|
ASSERT_EQ(3, eval.expression.size());
|
||||||
checkTokenOption(eval.expression.at(0), 12);
|
checkTokenOption(eval.expression.at(0), 12, TokenOption::TEXTUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test parsing of an option existence
|
// Test parsing of an option existence
|
||||||
@@ -247,7 +255,7 @@ TEST_F(EvalContextTest, optionExists) {
|
|||||||
EXPECT_NO_THROW(parsed_ = eval.parseString("option[100].exists"));
|
EXPECT_NO_THROW(parsed_ = eval.parseString("option[100].exists"));
|
||||||
EXPECT_TRUE(parsed_);
|
EXPECT_TRUE(parsed_);
|
||||||
ASSERT_EQ(1, eval.expression.size());
|
ASSERT_EQ(1, eval.expression.size());
|
||||||
checkTokenOption(eval.expression.at(0), 100);
|
checkTokenOption(eval.expression.at(0), 100, TokenOption::EXISTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test checking that whitespace can surround option name.
|
// Test checking that whitespace can surround option name.
|
||||||
@@ -258,7 +266,7 @@ TEST_F(EvalContextTest, optionWithNameAndWhitespace) {
|
|||||||
EXPECT_NO_THROW(parsed_ = eval.parseString("option[ host-name ].text == 'foo'"));
|
EXPECT_NO_THROW(parsed_ = eval.parseString("option[ host-name ].text == 'foo'"));
|
||||||
EXPECT_TRUE(parsed_);
|
EXPECT_TRUE(parsed_);
|
||||||
ASSERT_EQ(3, eval.expression.size());
|
ASSERT_EQ(3, eval.expression.size());
|
||||||
checkTokenOption(eval.expression.at(0), 12);
|
checkTokenOption(eval.expression.at(0), 12, TokenOption::TEXTUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test checking that newlines can surround option name.
|
// Test checking that newlines can surround option name.
|
||||||
@@ -270,7 +278,7 @@ TEST_F(EvalContextTest, optionWithNameAndNewline) {
|
|||||||
eval.parseString("option[\n host-name \n ].text == \n'foo'"));
|
eval.parseString("option[\n host-name \n ].text == \n'foo'"));
|
||||||
EXPECT_TRUE(parsed_);
|
EXPECT_TRUE(parsed_);
|
||||||
ASSERT_EQ(3, eval.expression.size());
|
ASSERT_EQ(3, eval.expression.size());
|
||||||
checkTokenOption(eval.expression.at(0), 12);
|
checkTokenOption(eval.expression.at(0), 12, TokenOption::TEXTUAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test parsing of an option represented as hexadecimal string.
|
// Test parsing of an option represented as hexadecimal string.
|
||||||
@@ -280,7 +288,7 @@ TEST_F(EvalContextTest, optionHex) {
|
|||||||
EXPECT_NO_THROW(parsed_ = eval.parseString("option[123].hex == 0x666F6F"));
|
EXPECT_NO_THROW(parsed_ = eval.parseString("option[123].hex == 0x666F6F"));
|
||||||
EXPECT_TRUE(parsed_);
|
EXPECT_TRUE(parsed_);
|
||||||
ASSERT_EQ(3, eval.expression.size());
|
ASSERT_EQ(3, eval.expression.size());
|
||||||
checkTokenOption(eval.expression.at(0), 123);
|
checkTokenOption(eval.expression.at(0), 123, TokenOption::HEXADECIMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This test checks that the relay4[code].hex can be used in expressions.
|
// This test checks that the relay4[code].hex can be used in expressions.
|
||||||
@@ -296,7 +304,7 @@ TEST_F(EvalContextTest, relay4Option) {
|
|||||||
TokenPtr tmp2 = eval.expression.at(1);
|
TokenPtr tmp2 = eval.expression.at(1);
|
||||||
TokenPtr tmp3 = eval.expression.at(2);
|
TokenPtr tmp3 = eval.expression.at(2);
|
||||||
|
|
||||||
checkTokenRelay4(tmp1, 13);
|
checkTokenRelay4(tmp1, 13, TokenOption::HEXADECIMAL);
|
||||||
checkTokenString(tmp2, "thirteen");
|
checkTokenString(tmp2, "thirteen");
|
||||||
checkTokenEq(tmp3);
|
checkTokenEq(tmp3);
|
||||||
}
|
}
|
||||||
@@ -308,7 +316,7 @@ TEST_F(EvalContextTest, relay4Exists) {
|
|||||||
EXPECT_NO_THROW(parsed_ = eval.parseString("relay4[13].exists"));
|
EXPECT_NO_THROW(parsed_ = eval.parseString("relay4[13].exists"));
|
||||||
EXPECT_TRUE(parsed_);
|
EXPECT_TRUE(parsed_);
|
||||||
ASSERT_EQ(1, eval.expression.size());
|
ASSERT_EQ(1, eval.expression.size());
|
||||||
checkTokenRelay4(eval.expression.at(0), 13);
|
checkTokenRelay4(eval.expression.at(0), 13, TokenOption::EXISTS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that relay4[13] is not usable in v6
|
// Verify that relay4[13] is not usable in v6
|
||||||
|
@@ -211,6 +211,16 @@ public:
|
|||||||
return (option_code_);
|
return (option_code_);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief Returns representation-type
|
||||||
|
///
|
||||||
|
/// This method is used in testing to determine if the parser had
|
||||||
|
/// instantiated TokenOption with correct parameters.
|
||||||
|
///
|
||||||
|
/// @return representation-type of the option this token expects to use.
|
||||||
|
RepresentationType getRepresentation() const {
|
||||||
|
return (representation_type_);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// @brief Attempts to retrieve an option
|
/// @brief Attempts to retrieve an option
|
||||||
///
|
///
|
||||||
|
Reference in New Issue
Block a user