|
@@ -24,6 +24,8 @@
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
+#include <arpa/inet.h>
|
|
|
+
|
|
|
using namespace std;
|
|
|
using namespace isc::dhcp;
|
|
|
|
|
@@ -127,6 +129,92 @@ TEST_F(TokenTest, string6) {
|
|
|
EXPECT_EQ("foo", values_.top());
|
|
|
}
|
|
|
|
|
|
+// This simple test checks that a TokenHexString, representing a constant
|
|
|
+// string coded in hexadecimal, can be used in Pkt4 evaluation.
|
|
|
+// (The actual packet is not used)
|
|
|
+TEST_F(TokenTest, hexstring4) {
|
|
|
+ TokenPtr empty;
|
|
|
+ TokenPtr bad;
|
|
|
+ TokenPtr bell;
|
|
|
+ TokenPtr foo;
|
|
|
+ TokenPtr cookie;
|
|
|
+
|
|
|
+ // Store constant empty hexstring "" ("") in the TokenHexString object.
|
|
|
+ ASSERT_NO_THROW(empty.reset(new TokenHexString("")));
|
|
|
+ // Store bad encoded hexstring "xabc" ("") in the TokenHexString object.
|
|
|
+ ASSERT_NO_THROW(bad.reset(new TokenHexString("xabc")));
|
|
|
+ // Store hexstring with an odd number of hexdigits "7" ("\a")
|
|
|
+ ASSERT_NO_THROW(bell.reset(new TokenHexString("7")));
|
|
|
+ // Store constant hexstring "666f6f" ("foo") in the TokenHexString object.
|
|
|
+ ASSERT_NO_THROW(foo.reset(new TokenHexString("666f6f")));
|
|
|
+ // Store constant hexstring "63825363" (DHCP_OPTIONS_COOKIE)
|
|
|
+ ASSERT_NO_THROW(cookie.reset(new TokenHexString("63825363")));
|
|
|
+
|
|
|
+ // Make sure that tokens can be evaluated without exceptions.
|
|
|
+ ASSERT_NO_THROW(empty->evaluate(*pkt4_, values_));
|
|
|
+ ASSERT_NO_THROW(bad->evaluate(*pkt4_, values_));
|
|
|
+ ASSERT_NO_THROW(bell->evaluate(*pkt4_, values_));
|
|
|
+ ASSERT_NO_THROW(foo->evaluate(*pkt4_, values_));
|
|
|
+ ASSERT_NO_THROW(cookie->evaluate(*pkt4_, values_));
|
|
|
+
|
|
|
+ // Check that the evaluation put its value on the values stack.
|
|
|
+ ASSERT_EQ(5, values_.size());
|
|
|
+ uint32_t expected = htonl(DHCP_OPTIONS_COOKIE);
|
|
|
+ EXPECT_EQ(4, values_.top().size());
|
|
|
+ EXPECT_EQ(0, std::memcmp(&expected, &values_.top()[0], 4));
|
|
|
+ values_.pop();
|
|
|
+ EXPECT_EQ("foo", values_.top());
|
|
|
+ values_.pop();
|
|
|
+ EXPECT_EQ("\a", values_.top());
|
|
|
+ values_.pop();
|
|
|
+ EXPECT_EQ("", values_.top());
|
|
|
+ values_.pop();
|
|
|
+ EXPECT_EQ("", values_.top());
|
|
|
+}
|
|
|
+
|
|
|
+// This simple test checks that a TokenHexString, representing a constant
|
|
|
+// string coded in hexadecimal, can be used in Pkt6 evaluation.
|
|
|
+// (The actual packet is not used)
|
|
|
+TEST_F(TokenTest, hexstring6) {
|
|
|
+ TokenPtr empty;
|
|
|
+ TokenPtr bad;
|
|
|
+ TokenPtr bell;
|
|
|
+ TokenPtr foo;
|
|
|
+ TokenPtr cookie;
|
|
|
+
|
|
|
+ // Store constant empty hexstring "" ("") in the TokenHexString object.
|
|
|
+ ASSERT_NO_THROW(empty.reset(new TokenHexString("")));
|
|
|
+ // Store bad encoded hexstring "xabc" ("") in the TokenHexString object.
|
|
|
+ ASSERT_NO_THROW(bad.reset(new TokenHexString("xabc")));
|
|
|
+ // Store hexstring with an odd number of hexdigits "7" ("\a")
|
|
|
+ ASSERT_NO_THROW(bell.reset(new TokenHexString("7")));
|
|
|
+ // Store constant hexstring "666f6f" ("foo") in the TokenHexString object.
|
|
|
+ ASSERT_NO_THROW(foo.reset(new TokenHexString("666f6f")));
|
|
|
+ // Store constant hexstring "63825363" (DHCP_OPTIONS_COOKIE)
|
|
|
+ ASSERT_NO_THROW(cookie.reset(new TokenHexString("63825363")));
|
|
|
+
|
|
|
+ // Make sure that tokens can be evaluated without exceptions.
|
|
|
+ ASSERT_NO_THROW(empty->evaluate(*pkt6_, values_));
|
|
|
+ ASSERT_NO_THROW(bad->evaluate(*pkt6_, values_));
|
|
|
+ ASSERT_NO_THROW(bell->evaluate(*pkt6_, values_));
|
|
|
+ ASSERT_NO_THROW(foo->evaluate(*pkt6_, values_));
|
|
|
+ ASSERT_NO_THROW(cookie->evaluate(*pkt6_, values_));
|
|
|
+
|
|
|
+ // Check that the evaluation put its value on the values stack.
|
|
|
+ ASSERT_EQ(5, values_.size());
|
|
|
+ uint32_t expected = htonl(DHCP_OPTIONS_COOKIE);
|
|
|
+ EXPECT_EQ(4, values_.top().size());
|
|
|
+ EXPECT_EQ(0, std::memcmp(&expected, &values_.top()[0], 4));
|
|
|
+ values_.pop();
|
|
|
+ EXPECT_EQ("foo", values_.top());
|
|
|
+ values_.pop();
|
|
|
+ EXPECT_EQ("\a", values_.top());
|
|
|
+ values_.pop();
|
|
|
+ EXPECT_EQ("", values_.top());
|
|
|
+ values_.pop();
|
|
|
+ EXPECT_EQ("", values_.top());
|
|
|
+}
|
|
|
+
|
|
|
// This test checks if a token representing an option value is able to extract
|
|
|
// the option from an IPv4 packet and properly store the option's value.
|
|
|
TEST_F(TokenTest, optionString4) {
|