2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 21:45:37 +00:00

[4094] Addressed comments (comments, complex test)

This commit is contained in:
Francis Dupont
2015-11-05 03:32:00 +01:00
parent 4ba6b71ae8
commit e15edffe3e
2 changed files with 37 additions and 3 deletions

View File

@@ -23,8 +23,8 @@ namespace dhcp {
/// @brief Evaluate a RPN expression for a v4 or v6 packet and return /// @brief Evaluate a RPN expression for a v4 or v6 packet and return
/// a true or false decision /// a true or false decision
/// ///
/// @param expr the RPN expression, i.e., a vector (stack) of parsed tokens /// @param expr the RPN expression, i.e., a vector of parsed tokens
/// @param pkt The v4 or v6 packet (can be ignored) /// @param pkt The v4 or v6 packet
/// @return the boolean decision /// @return the boolean decision
/// @throw EvalStackError if there is not exactly one element on the value /// @throw EvalStackError if there is not exactly one element on the value
/// stack at the end of the evaluation /// stack at the end of the evaluation

View File

@@ -209,4 +209,38 @@ TEST_F(EvaluateTest, packet) {
EXPECT_FALSE(result_); EXPECT_FALSE(result_);
} }
// A test using substring on an option.
TEST_F(EvaluateTest, complex) {
TokenPtr toption;
TokenPtr tstart;
TokenPtr tlength;
TokenPtr tsubstring;
TokenPtr tstring;
TokenPtr tequal;
// Get the option, i.e., "hundred[46]"
ASSERT_NO_THROW(toption.reset(new TokenOption(100)));
e_.push_back(toption);
// Get substring("hundred[46]", 0, 7), i.e., "hundred"
ASSERT_NO_THROW(tstart.reset(new TokenString("0")));
e_.push_back(tstart);
ASSERT_NO_THROW(tlength.reset(new TokenString("7")));
e_.push_back(tlength);
ASSERT_NO_THROW(tsubstring.reset(new TokenSubstring()));
e_.push_back(tsubstring);
// Compare with "hundred"
ASSERT_NO_THROW(tstring.reset(new TokenString("hundred")));
e_.push_back(tstring);
ASSERT_NO_THROW(tequal.reset(new TokenEqual()));
e_.push_back(tequal);
// Should return true for v4 and v6 packets
ASSERT_NO_THROW(result_ = evaluate(e_, *pkt4_));
EXPECT_TRUE(result_);
ASSERT_NO_THROW(result_ = evaluate(e_, *pkt6_));
EXPECT_TRUE(result_);
}
}; };