]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3048] added more unittests
authorRazvan Becheriu <razvan@isc.org>
Fri, 22 Sep 2023 10:50:49 +0000 (13:50 +0300)
committerRazvan Becheriu <razvan@isc.org>
Fri, 22 Sep 2023 13:30:27 +0000 (16:30 +0300)
ChangeLog
src/lib/eval/tests/context_unittest.cc
src/lib/eval/tests/token_unittest.cc

index 044baa8a510a0af9cfb68d8ea299f195222ec18a..316579d38775e756a7b77e1068d423df6d5ed397 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2181.  [func]          razvan
+       Added additional tokens which evaluate string expressions:
+       "lcase" which converts to lower case and "ucase" which
+       converts to upper case.
+       (Gitlab #3048)
+
 2180.  [build]         andrei
        Apart from enabling log4cplus's own logging, and adding more
        sanity checks in DNS code, the --enable-debug configure flag
index 2e91a418bcd03e5e9ced0af1fd9a29b07e31e933..959a5d49d1daf8aaffb3ec143a088e75c6b57c8b 100644 (file)
@@ -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) {
     {
index 5edf6559085b8e054d2d58e63c25be7badc8d06f..b01e238384b84df734101eb5210829a5d0fe1034 100644 (file)
@@ -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)