2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 05:27:55 +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

@ -40,7 +40,7 @@ public:
/// @brief Initializes Pkt4,Pkt6 and options that can be useful for /// @brief Initializes Pkt4,Pkt6 and options that can be useful for
/// evaluation tests. /// evaluation tests.
EvaluateTest() { EvaluateTest() {
e_.clear(); e_.clear();
pkt4_.reset(new Pkt4(DHCPDISCOVER, 12345)); pkt4_.reset(new Pkt4(DHCPDISCOVER, 12345));
pkt6_.reset(new Pkt6(DHCPV6_SOLICIT, 12345)); pkt6_.reset(new Pkt6(DHCPV6_SOLICIT, 12345));
@ -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_);
}
}; };