mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 05:27:55 +00:00
[4093] Support for option[123].hex operator.
This commit is contained in:
parent
eb932d6809
commit
00effa23d3
@ -123,6 +123,12 @@ string_expr : STRING
|
||||
TokenPtr opt(new TokenOption(numeric_code, TokenOption::TEXTUAL));
|
||||
ctx.expression.push_back(opt);
|
||||
}
|
||||
| OPTION "[" INTEGER "]" DOTHEX
|
||||
{
|
||||
uint16_t numeric_code = convert_option_code($3, @3, ctx);
|
||||
TokenPtr opt(new TokenOption(numeric_code, TokenOption::HEXADECIMAL));
|
||||
ctx.expression.push_back(opt);
|
||||
}
|
||||
| SUBSTRING "(" string_expr "," start_expr "," length_expr ")"
|
||||
{
|
||||
TokenPtr sub(new TokenSubstring());
|
||||
|
@ -209,6 +209,16 @@ TEST_F(EvalContextTest, option) {
|
||||
checkTokenOption(eval.expression.at(0), 123);
|
||||
}
|
||||
|
||||
// Test parsing of an option represented as hexadecimal string.
|
||||
TEST_F(EvalContextTest, optionHex) {
|
||||
EvalContext eval;
|
||||
|
||||
EXPECT_NO_THROW(parsed_ = eval.parseString("option[123].hex == 0x666F6F"));
|
||||
EXPECT_TRUE(parsed_);
|
||||
ASSERT_EQ(3, eval.expression.size());
|
||||
checkTokenOption(eval.expression.at(0), 123);
|
||||
}
|
||||
|
||||
// Test the parsing of a substring expression
|
||||
TEST_F(EvalContextTest, substring) {
|
||||
EvalContext eval;
|
||||
|
@ -209,6 +209,25 @@ TEST_F(EvaluateTest, packet) {
|
||||
EXPECT_FALSE(result_);
|
||||
}
|
||||
|
||||
// A test which compares option value represented in hexadecimal format.
|
||||
TEST_F(EvaluateTest, optionHex) {
|
||||
TokenPtr toption;
|
||||
TokenPtr tstring;
|
||||
TokenPtr tequal;
|
||||
|
||||
ASSERT_NO_THROW(toption.reset(new TokenOption(100, TokenOption::HEXADECIMAL)));
|
||||
e_.push_back(toption);
|
||||
ASSERT_NO_THROW(tstring.reset(new TokenString("0x68756E6472656434")));
|
||||
e_.push_back(tstring);
|
||||
ASSERT_NO_THROW(tequal.reset(new TokenEqual()));
|
||||
e_.push_back(tequal);
|
||||
|
||||
ASSERT_NO_THROW(result_ = evaluate(e_, *pkt4_));
|
||||
EXPECT_TRUE(result_);
|
||||
ASSERT_NO_THROW(result_ = evaluate(e_, *pkt6_));
|
||||
EXPECT_FALSE(result_);
|
||||
}
|
||||
|
||||
// A test using substring on an option.
|
||||
TEST_F(EvaluateTest, complex) {
|
||||
TokenPtr toption;
|
||||
|
Loading…
x
Reference in New Issue
Block a user