|
@@ -5,12 +5,17 @@
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
#include <config.h>
|
|
|
+#include <fstream>
|
|
|
#include <eval/token.h>
|
|
|
#include <dhcp/pkt4.h>
|
|
|
#include <dhcp/pkt6.h>
|
|
|
#include <dhcp/dhcp4.h>
|
|
|
#include <dhcp/dhcp6.h>
|
|
|
#include <dhcp/option_string.h>
|
|
|
+#include <log/logger_manager.h>
|
|
|
+#include <log/logger_name.h>
|
|
|
+#include <log/logger_support.h>
|
|
|
+#include <testutils/log_utils.h>
|
|
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
@@ -21,6 +26,8 @@
|
|
|
using namespace std;
|
|
|
using namespace isc::dhcp;
|
|
|
using namespace isc::asiolink;
|
|
|
+using namespace isc::log;
|
|
|
+using namespace isc::dhcp::test;
|
|
|
|
|
|
namespace {
|
|
|
|
|
@@ -28,7 +35,8 @@ namespace {
|
|
|
///
|
|
|
/// This class provides several convenience objects to be used during testing
|
|
|
/// of the Token family of classes.
|
|
|
-class TokenTest : public ::testing::Test {
|
|
|
+
|
|
|
+class TokenTest : public LogContentTest {
|
|
|
public:
|
|
|
|
|
|
/// @brief Initializes Pkt4,Pkt6 and options that can be useful for
|
|
@@ -229,6 +237,7 @@ public:
|
|
|
}
|
|
|
|
|
|
/// @todo: Add more option types here
|
|
|
+
|
|
|
};
|
|
|
|
|
|
// This tests the toBool() conversions
|
|
@@ -262,6 +271,12 @@ TEST_F(TokenTest, string4) {
|
|
|
// Check that the evaluation put its value on the values stack.
|
|
|
ASSERT_EQ(1, values_.size());
|
|
|
EXPECT_EQ("foo", 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_STRING Pushing text string 'foo'");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This simple test checks that a TokenString, representing a constant string,
|
|
@@ -277,6 +292,12 @@ TEST_F(TokenTest, string6) {
|
|
|
// Check that the evaluation put its value on the values stack.
|
|
|
ASSERT_EQ(1, values_.size());
|
|
|
EXPECT_EQ("foo", 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_STRING Pushing text string 'foo'");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This simple test checks that a TokenHexString, representing a constant
|
|
@@ -306,7 +327,8 @@ TEST_F(TokenTest, hexstring4) {
|
|
|
// Store constant hexstring "0x63825363" (DHCP_OPTIONS_COOKIE).
|
|
|
ASSERT_NO_THROW(cookie.reset(new TokenHexString("0x63825363")));
|
|
|
|
|
|
- // Make sure that tokens can be evaluated without exceptions.
|
|
|
+ // Make sure that tokens can be evaluated without exceptions,
|
|
|
+ // and verify the debug output
|
|
|
ASSERT_NO_THROW(empty->evaluate(*pkt4_, values_));
|
|
|
ASSERT_NO_THROW(bad->evaluate(*pkt4_, values_));
|
|
|
ASSERT_NO_THROW(nodigit->evaluate(*pkt4_, values_));
|
|
@@ -332,6 +354,18 @@ TEST_F(TokenTest, hexstring4) {
|
|
|
EXPECT_EQ("", values_.top());
|
|
|
values_.pop();
|
|
|
EXPECT_EQ("", 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_HEXSTRING Pushing hex string 0x");
|
|
|
+ addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x");
|
|
|
+ addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x");
|
|
|
+ addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x");
|
|
|
+ addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x07");
|
|
|
+ addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x666F6F");
|
|
|
+ addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x63825363");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This simple test checks that a TokenHexString, representing a constant
|
|
@@ -387,6 +421,18 @@ TEST_F(TokenTest, hexstring6) {
|
|
|
EXPECT_EQ("", values_.top());
|
|
|
values_.pop();
|
|
|
EXPECT_EQ("", 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_HEXSTRING Pushing hex string 0x");
|
|
|
+ addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x");
|
|
|
+ addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x");
|
|
|
+ addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x");
|
|
|
+ addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x07");
|
|
|
+ addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x666F6F");
|
|
|
+ addString("EVAL_DEBUG_HEXSTRING Pushing hex string 0x63825363");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks that a TokenIpAddress, representing an IP address as
|
|
@@ -432,6 +478,16 @@ TEST_F(TokenTest, ipaddress) {
|
|
|
uint8_t expected4[] = { 10, 0, 0, 1 };
|
|
|
EXPECT_EQ(4, values_.top().size());
|
|
|
EXPECT_EQ(0, memcmp(expected4, &values_.top()[0], 4));
|
|
|
+
|
|
|
+ // 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_IPADDRESS Pushing IPAddress 0x0A000001");
|
|
|
+ addString("EVAL_DEBUG_IPADDRESS Pushing IPAddress "
|
|
|
+ "0x20010DB8000000000000000000000001");
|
|
|
+ addString("EVAL_DEBUG_IPADDRESS Pushing IPAddress 0x");
|
|
|
+ addString("EVAL_DEBUG_IPADDRESS Pushing IPAddress 0x");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks if a token representing an option value is able to extract
|
|
@@ -460,6 +516,13 @@ TEST_F(TokenTest, optionString4) {
|
|
|
|
|
|
// Then the content of the option 100.
|
|
|
EXPECT_EQ("hundred4", 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_OPTION Pushing option 100 with value 'hundred4'");
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 101 with value ''");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks if a token representing option value is able to extract
|
|
@@ -489,6 +552,13 @@ TEST_F(TokenTest, optionHexString4) {
|
|
|
|
|
|
// Then the content of the option 100.
|
|
|
EXPECT_EQ("hundred4", 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_OPTION Pushing option 100 with value 0x68756E6472656434");
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 101 with value 0x");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks if a token representing an option value is able to check
|
|
@@ -511,6 +581,13 @@ TEST_F(TokenTest, optionExistsString4) {
|
|
|
EXPECT_EQ("false", values_.top());
|
|
|
values_.pop();
|
|
|
EXPECT_EQ("true", 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_OPTION Pushing option 100 with value 'true'");
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 101 with value 'false'");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks if a token representing an option value is able to extract
|
|
@@ -539,6 +616,13 @@ TEST_F(TokenTest, optionString6) {
|
|
|
|
|
|
// Then the content of the option 100.
|
|
|
EXPECT_EQ("hundred6", 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_OPTION Pushing option 100 with value 'hundred6'");
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 101 with value ''");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks if a token representing an option value is able to extract
|
|
@@ -568,6 +652,13 @@ TEST_F(TokenTest, optionHexString6) {
|
|
|
|
|
|
// Then the content of the option 100.
|
|
|
EXPECT_EQ("hundred6", 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_OPTION Pushing option 100 with value 0x68756E6472656436");
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 101 with value 0x");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks if a token representing an option value is able to check
|
|
@@ -590,6 +681,13 @@ TEST_F(TokenTest, optionExistsString6) {
|
|
|
EXPECT_EQ("false", values_.top());
|
|
|
values_.pop();
|
|
|
EXPECT_EQ("true", 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_OPTION Pushing option 100 with value 'true'");
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 101 with value 'false'");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks that the existing relay4 option can be found.
|
|
@@ -610,6 +708,12 @@ TEST_F(TokenTest, relay4Option) {
|
|
|
// The option should be found and relay4[13] should evaluate to the
|
|
|
// content of that sub-option, i.e. "thirteen"
|
|
|
EXPECT_EQ("thirteen", 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_OPTION Pushing option 13 with value 'thirteen'");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks that the code properly handles cases when
|
|
@@ -631,6 +735,12 @@ TEST_F(TokenTest, relay4OptionNoSuboption) {
|
|
|
// The option should NOT be found (there is no sub-option 15),
|
|
|
// so the expression should evaluate to ""
|
|
|
EXPECT_EQ("", 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_OPTION Pushing option 15 with value ''");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks that the code properly handles cases when
|
|
@@ -651,6 +761,12 @@ TEST_F(TokenTest, relay4OptionNoRai) {
|
|
|
// The option should NOT be found (there is no sub-option 13),
|
|
|
// so the expression should evaluate to ""
|
|
|
EXPECT_EQ("", 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_OPTION Pushing option 13 with value ''");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks that only the RAI is searched for the requested
|
|
@@ -707,6 +823,16 @@ TEST_F(TokenTest, relay4RAIOnly) {
|
|
|
EXPECT_NO_THROW(t_->evaluate(*pkt4_, values_));
|
|
|
ASSERT_EQ(1, values_.size());
|
|
|
EXPECT_EQ("false", 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_OPTION Pushing option 13 with value 'thirteen'");
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 1 with value 'one'");
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 70 with value ''");
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 1 with value 'true'");
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 70 with value 'false'");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// Verifies if the DHCPv4 packet fields can be extracted.
|
|
@@ -787,6 +913,18 @@ TEST_F(TokenTest, pkt4Fields) {
|
|
|
clearStack();
|
|
|
ASSERT_NO_THROW(t_.reset(new TokenPkt4(TokenPkt4::HLEN)));
|
|
|
EXPECT_THROW(t_->evaluate(*pkt6_, values_), EvalTypeError);
|
|
|
+
|
|
|
+ // 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_PKT4 Pushing PKT4 field mac with value 0x01020304050607");
|
|
|
+ addString("EVAL_DEBUG_PKT4 Pushing PKT4 field hlen with value 0x00000007");
|
|
|
+ addString("EVAL_DEBUG_PKT4 Pushing PKT4 field htype with value 0x0000007B");
|
|
|
+ addString("EVAL_DEBUG_PKT4 Pushing PKT4 field giaddr with value 0xC0000201");
|
|
|
+ addString("EVAL_DEBUG_PKT4 Pushing PKT4 field ciaddr with value 0xC0000202");
|
|
|
+ addString("EVAL_DEBUG_PKT4 Pushing PKT4 field yiaddr with value 0xC0000203");
|
|
|
+ addString("EVAL_DEBUG_PKT4 Pushing PKT4 field siaddr with value 0xC0000204");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks if a token representing an == operator is able to
|
|
@@ -818,6 +956,13 @@ TEST_F(TokenTest, optionEqualFalse) {
|
|
|
// result of "foo" == "bar" comparision.
|
|
|
ASSERT_EQ(1, values_.size());
|
|
|
EXPECT_EQ("false", 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_EQUAL Popping 0x626172 and 0x666F6F "
|
|
|
+ "pushing result 'false'");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks if a token representing an == operator is able to
|
|
@@ -834,6 +979,13 @@ TEST_F(TokenTest, optionEqualTrue) {
|
|
|
// result of "foo" == "foo" comparision.
|
|
|
ASSERT_EQ(1, values_.size());
|
|
|
EXPECT_EQ("true", 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_EQUAL Popping 0x666F6F and 0x666F6F "
|
|
|
+ "pushing result 'true'");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks if a token representing a not is able to
|
|
@@ -867,6 +1019,13 @@ TEST_F(TokenTest, operatorNot) {
|
|
|
EXPECT_NO_THROW(t_->evaluate(*pkt4_, values_));
|
|
|
ASSERT_EQ(1, values_.size());
|
|
|
EXPECT_EQ("true", 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_NOT Popping 'true' pushing 'false'");
|
|
|
+ addString("EVAL_DEBUG_NOT Popping 'false' pushing 'true'");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks if a token representing an and is able to
|
|
@@ -907,7 +1066,7 @@ TEST_F(TokenTest, operatorAndFalse) {
|
|
|
ASSERT_EQ(1, values_.size());
|
|
|
EXPECT_EQ("false", values_.top());
|
|
|
|
|
|
- // After true and false, checks false and true
|
|
|
+ // After true and false, check false and true
|
|
|
values_.push("true");
|
|
|
EXPECT_NO_THROW(t_->evaluate(*pkt4_, values_));
|
|
|
ASSERT_EQ(1, values_.size());
|
|
@@ -918,6 +1077,14 @@ TEST_F(TokenTest, operatorAndFalse) {
|
|
|
EXPECT_NO_THROW(t_->evaluate(*pkt4_, values_));
|
|
|
ASSERT_EQ(1, values_.size());
|
|
|
EXPECT_EQ("false", 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_AND Popping 'false' and 'true' pushing 'false'");
|
|
|
+ addString("EVAL_DEBUG_AND Popping 'true' and 'false' pushing 'false'");
|
|
|
+ addString("EVAL_DEBUG_AND Popping 'false' and 'false' pushing 'false'");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks if a token representing an and is able to
|
|
@@ -933,6 +1100,12 @@ TEST_F(TokenTest, operatorAndTrue) {
|
|
|
// After evaluation there should be a single "true" value
|
|
|
ASSERT_EQ(1, values_.size());
|
|
|
EXPECT_EQ("true", 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_AND Popping 'true' and 'true' pushing 'true'");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks if a token representing an or is able to
|
|
@@ -972,6 +1145,12 @@ TEST_F(TokenTest, operatorOrFalse) {
|
|
|
// After evaluation there should be a single "false" value
|
|
|
ASSERT_EQ(1, values_.size());
|
|
|
EXPECT_EQ("false", 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_OR Popping 'false' and 'false' pushing 'false'");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks if a token representing an == operator is able to
|
|
@@ -999,9 +1178,15 @@ TEST_F(TokenTest, operatorOrTrue) {
|
|
|
EXPECT_NO_THROW(t_->evaluate(*pkt4_, values_));
|
|
|
ASSERT_EQ(1, values_.size());
|
|
|
EXPECT_EQ("true", 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_OR Popping 'true' and 'false' pushing 'true'");
|
|
|
+ addString("EVAL_DEBUG_OR Popping 'false' and 'true' pushing 'true'");
|
|
|
+ addString("EVAL_DEBUG_OR Popping 'true' and 'true' pushing 'true'");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
+}
|
|
|
|
|
|
// This test checks if a token representing a substring request
|
|
|
// throws an exception if there aren't enough values on the stack.
|
|
@@ -1028,6 +1213,13 @@ TEST_F(TokenTest, substringNotEnoughValues) {
|
|
|
// one after the evaluate
|
|
|
ASSERT_EQ(1, values_.size());
|
|
|
EXPECT_EQ("", 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_SUBSTRING_EMPTY Popping length 0, start 0, "
|
|
|
+ "string 0x pushing result 0x");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// Test getting the whole string in different ways
|
|
@@ -1043,6 +1235,19 @@ TEST_F(TokenTest, substringWholeString) {
|
|
|
|
|
|
// Get the whole string counting from the back
|
|
|
verifySubstringEval("foobar", "-6", "all", "foobar");
|
|
|
+
|
|
|
+ // 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_SUBSTRING Popping length 6, start 0, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x666F6F626172");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length all, start 0, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x666F6F626172");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length 123456, start 0, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x666F6F626172");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length all, start -6, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x666F6F626172");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// Test getting a suffix, in this case the last 3 characters
|
|
@@ -1051,6 +1256,19 @@ TEST_F(TokenTest, substringTrailer) {
|
|
|
verifySubstringEval("foobar", "3", "all", "bar");
|
|
|
verifySubstringEval("foobar", "-3", "all", "bar");
|
|
|
verifySubstringEval("foobar", "-3", "123", "bar");
|
|
|
+
|
|
|
+ // 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_SUBSTRING Popping length 3, start 3, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x626172");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length all, start 3, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x626172");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length all, start -3, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x626172");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length 123, start -3, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x626172");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// Test getting the middle of the string in different ways
|
|
@@ -1059,6 +1277,19 @@ TEST_F(TokenTest, substringMiddle) {
|
|
|
verifySubstringEval("foobar", "-5", "4", "ooba");
|
|
|
verifySubstringEval("foobar", "-1", "-4", "ooba");
|
|
|
verifySubstringEval("foobar", "5", "-4", "ooba");
|
|
|
+
|
|
|
+ // 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_SUBSTRING Popping length 4, start 1, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x6F6F6261");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length 4, start -5, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x6F6F6261");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length -4, start -1, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x6F6F6261");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length -4, start 5, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x6F6F6261");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// Test getting the last letter in different ways
|
|
@@ -1069,6 +1300,23 @@ TEST_F(TokenTest, substringLastLetter) {
|
|
|
verifySubstringEval("foobar", "-1", "all", "r");
|
|
|
verifySubstringEval("foobar", "-1", "1", "r");
|
|
|
verifySubstringEval("foobar", "-1", "5", "r");
|
|
|
+
|
|
|
+ // 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_SUBSTRING Popping length all, start 5, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x72");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length 1, start 5, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x72");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length 5, start 5, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x72");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length all, start -1, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x72");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length 1, start -1, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x72");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length 5, start -1, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x72");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// Test we get only what is available if we ask for a longer string
|
|
@@ -1084,6 +1332,27 @@ TEST_F(TokenTest, substringLength) {
|
|
|
verifySubstringEval("foobar", "4", "4", "ar");
|
|
|
verifySubstringEval("foobar", "5", "4", "r");
|
|
|
verifySubstringEval("foobar", "6", "4", "");
|
|
|
+
|
|
|
+ // 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_SUBSTRING Popping length -4, start 0, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length -4, start 1, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x66");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length -4, start 2, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x666F");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length -4, start 3, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x666F6F");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length 4, start 3, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x626172");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length 4, start 4, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x6172");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length 4, start 5, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x72");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING_RANGE Popping length 4, start 6, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// Test that we get nothing if the starting postion is out of the string
|
|
@@ -1097,6 +1366,23 @@ TEST_F(TokenTest, substringStartingPosition) {
|
|
|
verifySubstringEval("foobar", "6", "1", "");
|
|
|
verifySubstringEval("foobar", "6", "-11", "");
|
|
|
verifySubstringEval("foobar", "6", "all", "");
|
|
|
+
|
|
|
+ // 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_SUBSTRING_RANGE Popping length 1, start -7, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING_RANGE Popping length -11, start -7, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING_RANGE Popping length all, start -7, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING_RANGE Popping length 1, start 6, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING_RANGE Popping length -11, start 6, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING_RANGE Popping length all, start 6, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// Check what happens if we use strings that aren't numbers for start or length
|
|
@@ -1109,6 +1395,9 @@ TEST_F(TokenTest, substringBadParams) {
|
|
|
verifySubstringEval("foobar", "0", "0ick", "", true);
|
|
|
verifySubstringEval("foobar", "0", "ick0", "", true);
|
|
|
verifySubstringEval("foobar", "0", "allaboard", "", true);
|
|
|
+
|
|
|
+ // These should result in a throw which should generate it's own
|
|
|
+ // log entry
|
|
|
}
|
|
|
|
|
|
// lastly check that we don't get anything if the string is empty or
|
|
@@ -1116,6 +1405,15 @@ TEST_F(TokenTest, substringBadParams) {
|
|
|
TEST_F(TokenTest, substringReturnEmpty) {
|
|
|
verifySubstringEval("", "0", "all", "");
|
|
|
verifySubstringEval("foobar", "0", "0", "");
|
|
|
+
|
|
|
+ // 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_SUBSTRING_EMPTY Popping length all, start 0, "
|
|
|
+ "string 0x pushing result 0x");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length 0, start 0, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// Check if we can use the substring and equal tokens together
|
|
@@ -1137,8 +1435,6 @@ TEST_F(TokenTest, substringEquals) {
|
|
|
values_.push("ooba");
|
|
|
|
|
|
// The substring values
|
|
|
- // Subsring requires three values on the stack, try
|
|
|
- // with 0, 1 and 2 all should throw an exception
|
|
|
values_.push("foobar");
|
|
|
values_.push("1");
|
|
|
values_.push("4");
|
|
@@ -1160,8 +1456,6 @@ TEST_F(TokenTest, substringEquals) {
|
|
|
values_.push("foob");
|
|
|
|
|
|
// The substring values
|
|
|
- // Subsring requires three values on the stack, try
|
|
|
- // with 0, 1 and 2 all should throw an exception
|
|
|
values_.push("foobar");
|
|
|
values_.push("1");
|
|
|
values_.push("4");
|
|
@@ -1175,6 +1469,18 @@ TEST_F(TokenTest, substringEquals) {
|
|
|
ASSERT_EQ(1, values_.size());
|
|
|
EXPECT_EQ("false", 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_SUBSTRING Popping length 4, start 1, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x6F6F6261");
|
|
|
+ addString("EVAL_DEBUG_EQUAL Popping 0x6F6F6261 and 0x6F6F6261 "
|
|
|
+ "pushing result 'true'");
|
|
|
+ addString("EVAL_DEBUG_SUBSTRING Popping length 4, start 1, "
|
|
|
+ "string 0x666F6F626172 pushing result 0x6F6F6261");
|
|
|
+ addString("EVAL_DEBUG_EQUAL Popping 0x6F6F6261 and 0x666F6F62 "
|
|
|
+ "pushing result 'false'");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks if a token representing a concat request
|
|
@@ -1197,6 +1503,13 @@ TEST_F(TokenTest, concat) {
|
|
|
// Check the result
|
|
|
ASSERT_EQ(1, values_.size());
|
|
|
EXPECT_EQ("foobar", 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_CONCAT Popping 0x626172 and 0x666F6F "
|
|
|
+ "pushing 0x666F6F626172");
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks if we can properly extract the link and peer
|
|
@@ -1250,6 +1563,29 @@ TEST_F(TokenTest, relay6Field) {
|
|
|
|
|
|
// be tidy
|
|
|
clearStack();
|
|
|
+
|
|
|
+ // 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_RELAY6 Pushing PKT6 relay field linkaddr nest 0 "
|
|
|
+ "with value 0x00000000000000000000000000000000");
|
|
|
+ addString("EVAL_DEBUG_RELAY6 Pushing PKT6 relay field peeraddr nest 0 "
|
|
|
+ "with value 0x00000000000000000000000000000000");
|
|
|
+ addString("EVAL_DEBUG_RELAY6 Pushing PKT6 relay field linkaddr nest 1 "
|
|
|
+ "with value 0x00010000000000000000000000000001");
|
|
|
+ addString("EVAL_DEBUG_RELAY6 Pushing PKT6 relay field peeraddr nest 1 "
|
|
|
+ "with value 0x00010000000000000000000000000002");
|
|
|
+ addString("EVAL_DEBUG_RELAY6_RANGE Pushing PKT6 relay field linkaddr nest 2 "
|
|
|
+ "with value 0x");
|
|
|
+
|
|
|
+ addString("EVAL_DEBUG_RELAY6 Pushing PKT6 relay field linkaddr nest 1 "
|
|
|
+ "with value 0x00010000000000000000000000000001");
|
|
|
+ addString("EVAL_DEBUG_IPADDRESS Pushing IPAddress "
|
|
|
+ "0x00010000000000000000000000000001");
|
|
|
+ addString("EVAL_DEBUG_EQUAL Popping 0x00010000000000000000000000000001 "
|
|
|
+ "and 0x00010000000000000000000000000001 pushing result 'true'");
|
|
|
+
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// This test checks if we can properly extract an option
|
|
@@ -1283,6 +1619,23 @@ TEST_F(TokenTest, relay6Option) {
|
|
|
|
|
|
// Level 2, no encapsulation so no options
|
|
|
verifyRelay6Option(2, 100, TokenOption::TEXTUAL, "");
|
|
|
+
|
|
|
+ // 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_OPTION Pushing option 100 with value 'hundred.zero'");
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 100 with value 'true'");
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 101 with value 'hundredone.zero'");
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 102 with value ''");
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 102 with value 'false'");
|
|
|
+
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 100 with value 'hundred.one'");
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 101 with value ''");
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 102 with value 'hundredtwo.one'");
|
|
|
+
|
|
|
+ addString("EVAL_DEBUG_OPTION Pushing option 100 with value ''");
|
|
|
+
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
|
|
|
// Verifies if the DHCPv6 packet fields can be extracted.
|
|
@@ -1309,4 +1662,13 @@ TEST_F(TokenTest, pkt6Fields) {
|
|
|
clearStack();
|
|
|
ASSERT_NO_THROW(t_.reset(new TokenPkt6(TokenPkt6::TRANSID)));
|
|
|
EXPECT_THROW(t_->evaluate(*pkt4_, values_), EvalTypeError);
|
|
|
+
|
|
|
+ // 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_PKT6 Pushing PKT6 field msgtype with value 0x00000001");
|
|
|
+ addString("EVAL_DEBUG_PKT6 Pushing PKT6 field transid with value 0x00003039");
|
|
|
+
|
|
|
+ EXPECT_TRUE(checkFile());
|
|
|
}
|
|
|
+};
|