This source file includes following definitions.
- IncludeNUL
- TEST_F
- TEST_F
#include "net/base/dns_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
class DNSUtilTest : public testing::Test {
};
static std::string IncludeNUL(const char* in) {
return std::string(in, strlen(in) + 1);
}
TEST_F(DNSUtilTest, DNSDomainFromDot) {
std::string out;
EXPECT_FALSE(DNSDomainFromDot("", &out));
EXPECT_FALSE(DNSDomainFromDot(".", &out));
EXPECT_FALSE(DNSDomainFromDot("..", &out));
EXPECT_TRUE(DNSDomainFromDot("com", &out));
EXPECT_EQ(out, IncludeNUL("\003com"));
EXPECT_TRUE(DNSDomainFromDot("google.com", &out));
EXPECT_EQ(out, IncludeNUL("\x006google\003com"));
EXPECT_TRUE(DNSDomainFromDot("www.google.com", &out));
EXPECT_EQ(out, IncludeNUL("\003www\006google\003com"));
EXPECT_TRUE(DNSDomainFromDot("123456789a123456789a123456789a123456789a123456789a123456789a123", &out));
EXPECT_EQ(out, IncludeNUL("\077123456789a123456789a123456789a123456789a123456789a123456789a123"));
EXPECT_FALSE(DNSDomainFromDot("123456789a123456789a123456789a123456789a123456789a123456789a1234", &out));
EXPECT_TRUE(DNSDomainFromDot("123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123", &out));
EXPECT_EQ(out, IncludeNUL("\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\011123456789\003123"));
EXPECT_FALSE(DNSDomainFromDot("123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.1234", &out));
EXPECT_TRUE(DNSDomainFromDot("www.google.com.", &out));
EXPECT_EQ(out, IncludeNUL("\003www\006google\003com"));
EXPECT_TRUE(DNSDomainFromDot(".google.com", &out));
EXPECT_EQ(out, IncludeNUL("\006google\003com"));
EXPECT_TRUE(DNSDomainFromDot("www..google.com", &out));
EXPECT_EQ(out, IncludeNUL("\003www\006google\003com"));
}
TEST_F(DNSUtilTest, DNSDomainToString) {
EXPECT_EQ("", DNSDomainToString(IncludeNUL("")));
EXPECT_EQ("foo", DNSDomainToString(IncludeNUL("\003foo")));
EXPECT_EQ("foo.bar", DNSDomainToString(IncludeNUL("\003foo\003bar")));
EXPECT_EQ("foo.bar.uk",
DNSDomainToString(IncludeNUL("\003foo\003bar\002uk")));
EXPECT_EQ("foo.bar", DNSDomainToString("\003foo\003bar"));
EXPECT_EQ("", DNSDomainToString(IncludeNUL("\x80")));
EXPECT_EQ("", DNSDomainToString("\x06"));
}
}