diff options
author | Razvan Becheriu <razvan@isc.org> | 2023-09-22 12:50:49 +0200 |
---|---|---|
committer | Razvan Becheriu <razvan@isc.org> | 2023-09-22 15:30:27 +0200 |
commit | a7a6191d73e7ef25c545c84e10c2c0028105fa34 (patch) | |
tree | 09f1c37cc5257236be38488475499e1f2a129ac3 /src/lib/eval | |
parent | [#3048] added the lcase and ucase operators (diff) | |
download | kea-a7a6191d73e7ef25c545c84e10c2c0028105fa34.tar.xz kea-a7a6191d73e7ef25c545c84e10c2c0028105fa34.zip |
[#3048] added more unittests
Diffstat (limited to 'src/lib/eval')
-rw-r--r-- | src/lib/eval/tests/context_unittest.cc | 42 | ||||
-rw-r--r-- | src/lib/eval/tests/token_unittest.cc | 56 |
2 files changed, 92 insertions, 6 deletions
diff --git a/src/lib/eval/tests/context_unittest.cc b/src/lib/eval/tests/context_unittest.cc index 2e91a418bc..959a5d49d1 100644 --- a/src/lib/eval/tests/context_unittest.cc +++ b/src/lib/eval/tests/context_unittest.cc @@ -1568,6 +1568,27 @@ TEST_F(EvalContextTest, lcase) { checkTokenEq(tmp4); } +// Test the parsing of complex lcase expression +TEST_F(EvalContextTest, lcaseComplex) { + EvalContext eval(Option::V4); + + EXPECT_NO_THROW(parsed_ = eval.parseString("lcase('12345~!@#$%^&*()_+LoWeR{}[];:<>/?\\67890\t \b\r\f') == " + "'12345~!@#$%^&*()_+lower{}[];:<>/?\\67890\t \b\r\f'")); + EXPECT_TRUE(parsed_); + + ASSERT_EQ(4, eval.expression.size()); + + TokenPtr tmp1 = eval.expression.at(0); + TokenPtr tmp2 = eval.expression.at(1); + TokenPtr tmp3 = eval.expression.at(2); + TokenPtr tmp4 = eval.expression.at(3); + + checkTokenString(tmp1, "12345~!@#$%^&*()_+LoWeR{}[];:<>/?\\67890\t \b\r\f"); + checkTokenLowerCase(tmp2, "12345~!@#$%^&*()_+lower{}[];:<>/?\\67890\t \b\r\f"); + checkTokenString(tmp3, "12345~!@#$%^&*()_+lower{}[];:<>/?\\67890\t \b\r\f"); + checkTokenEq(tmp4); +} + // Test the parsing of ucase expression TEST_F(EvalContextTest, ucase) { EvalContext eval(Option::V4); @@ -1588,6 +1609,27 @@ TEST_F(EvalContextTest, ucase) { checkTokenEq(tmp4); } +// Test the parsing of complex ucase expression +TEST_F(EvalContextTest, ucaseComplex) { + EvalContext eval(Option::V4); + + EXPECT_NO_THROW(parsed_ = eval.parseString("ucase('12345~!@#$%^&*()_+uPpEr{}[];:<>/?\\67890\t \b\r\f') == " + "'12345~!@#$%^&*()_+UPPER{}[];:<>/?\\67890\t \b\r\f'")); + EXPECT_TRUE(parsed_); + + ASSERT_EQ(4, eval.expression.size()); + + TokenPtr tmp1 = eval.expression.at(0); + TokenPtr tmp2 = eval.expression.at(1); + TokenPtr tmp3 = eval.expression.at(2); + TokenPtr tmp4 = eval.expression.at(3); + + checkTokenString(tmp1, "12345~!@#$%^&*()_+uPpEr{}[];:<>/?\\67890\t \b\r\f"); + checkTokenUpperCase(tmp2, "12345~!@#$%^&*()_+UPPER{}[];:<>/?\\67890\t \b\r\f"); + checkTokenString(tmp3, "12345~!@#$%^&*()_+UPPER{}[];:<>/?\\67890\t \b\r\f"); + checkTokenEq(tmp4); +} + // Test the parsing of an addrtotext expression TEST_F(EvalContextTest, addressToText) { { diff --git a/src/lib/eval/tests/token_unittest.cc b/src/lib/eval/tests/token_unittest.cc index 5edf655908..b01e238384 100644 --- a/src/lib/eval/tests/token_unittest.cc +++ b/src/lib/eval/tests/token_unittest.cc @@ -745,10 +745,10 @@ TEST_F(TokenTest, hexstring6) { EXPECT_TRUE(checkFile()); } -// This simple test checks that a TokenLowerCase, representing a constant lower -// case string, can be used in Pkt evaluation. (The actual packet is not used) +// This simple test checks that a TokenLowerCase, representing a string +// converted to lower case, can be used in Pkt evaluation. (The actual packet +// is not used) TEST_F(TokenTest, lcase) { - // Store constant string "lower" in the TokenLowerCase object. ASSERT_NO_THROW(t_.reset(new TokenLowerCase())); values_.push("LoWeR"); @@ -766,10 +766,32 @@ TEST_F(TokenTest, lcase) { EXPECT_TRUE(checkFile()); } -// This simple test checks that a TokenUpperCase, representing a constant upper -// case string, can be used in Pkt evaluation. (The actual packet is not used) +// This simple test checks that a TokenLowerCase, representing a complex string +// converted to lower case, can be used in Pkt evaluation. (The actual packet +// is not used) +TEST_F(TokenTest, lcaseComplex) { + ASSERT_NO_THROW(t_.reset(new TokenLowerCase())); + values_.push("12345~!@#$%^&*()_+LoWeR{}[];:<>/?\\67890\t \b\r\f"); + + // Make sure that the token can be evaluated without exceptions. + ASSERT_NO_THROW(t_->evaluate(*pkt6_, values_)); + + // Check that the evaluation put its value on the values stack. + ASSERT_EQ(1, values_.size()); + EXPECT_EQ("12345~!@#$%^&*()_+lower{}[];:<>/?\\67890\t \b\r\f", values_.top()); + + // Check that the debug output was correct. Add the strings + // to the test vector in the class and then call checkFile + // for comparison + addString("EVAL_DEBUG_LCASE Poping string '12345~!@#$%^&*()_+LoWeR{}[];:<>/?\\67890\t \b\r\f' " + "and pushing converted value to lower case '12345~!@#$%^&*()_+lower{}[];:<>/?\\67890\t \b\r\f'"); + EXPECT_TRUE(checkFile()); +} + +// This simple test checks that a TokenUpperCase, representing a string +// converted to upper case, can be used in Pkt evaluation. (The actual packet +// is not used) TEST_F(TokenTest, ucase) { - // Store constant string "UPPER" in the TokenUpperCase object. ASSERT_NO_THROW(t_.reset(new TokenUpperCase())); values_.push("uPpEr"); @@ -787,6 +809,28 @@ TEST_F(TokenTest, ucase) { EXPECT_TRUE(checkFile()); } +// This simple test checks that a TokenUpperCase, representing a complex string +// converted to upper case, can be used in Pkt evaluation. (The actual packet +// is not used) +TEST_F(TokenTest, ucaseComplex) { + ASSERT_NO_THROW(t_.reset(new TokenUpperCase())); + values_.push("12345~!@#$%^&*()_+uPpEr{}[];:<>/?\\67890\t \b\r\f"); + + // Make sure that the token can be evaluated without exceptions. + ASSERT_NO_THROW(t_->evaluate(*pkt6_, values_)); + + // Check that the evaluation put its value on the values stack. + ASSERT_EQ(1, values_.size()); + EXPECT_EQ("12345~!@#$%^&*()_+UPPER{}[];:<>/?\\67890\t \b\r\f", values_.top()); + + // Check that the debug output was correct. Add the strings + // to the test vector in the class and then call checkFile + // for comparison + addString("EVAL_DEBUG_UCASE Poping string '12345~!@#$%^&*()_+uPpEr{}[];:<>/?\\67890\t \b\r\f' " + "and pushing converted value to upper case '12345~!@#$%^&*()_+UPPER{}[];:<>/?\\67890\t \b\r\f'"); + EXPECT_TRUE(checkFile()); +} + // This test checks that a TokenIpAddress, representing an IP address as // a constant string, can be used in Pkt4/Pkt6 evaluation. // (The actual packet is not used) |