Index: net/dns/dns_hosts_unittest.cc |
diff --git a/net/dns/dns_hosts_unittest.cc b/net/dns/dns_hosts_unittest.cc |
index c0e8805fc47dfdf97de79e6c48746650fb27e811..f258bbec0e95e233808dc4ad2214ce987ad8b664 100644 |
--- a/net/dns/dns_hosts_unittest.cc |
+++ b/net/dns/dns_hosts_unittest.cc |
@@ -64,6 +64,59 @@ TEST(DnsHostsTest, ParseHosts) { |
ASSERT_EQ(expected, hosts); |
} |
+TEST(DnsHostsTest, ParseHosts_CommaIsToken) { |
mmenke
2014/07/24 21:32:30
Bit of a pain, but should probably have one that m
Deprecated (see juliatuttle)
2014/07/25 19:34:44
So make one that's conditional on Mac and tests th
mmenke
2014/07/25 19:38:46
What I suggest is run the test everywhere, but hav
|
+ std::string contents = |
+ "127.0.0.1 comma1,comma2"; |
mmenke
2014/07/24 21:32:30
This fits on one line.
mmenke
2014/07/24 21:32:30
Also should probably make it const and use kConstN
Deprecated (see juliatuttle)
2014/07/25 19:34:44
Done.
Deprecated (see juliatuttle)
2014/07/25 19:34:44
Done.
|
+ |
+ const struct { |
+ const char* host; |
+ AddressFamily family; |
+ const char* ip; |
+ } entries[] = { |
mmenke
2014/07/24 21:32:30
Should also probably use const naming scheme here.
Deprecated (see juliatuttle)
2014/07/25 19:34:44
Done.
|
+ { "comma1,comma2", ADDRESS_FAMILY_IPV4, "127.0.0.1" }, |
+ }; |
+ |
+ DnsHosts expected; |
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(entries); ++i) { |
+ DnsHostsKey key(entries[i].host, entries[i].family); |
+ IPAddressNumber& ip = expected[key]; |
+ ASSERT_TRUE(ip.empty()); |
+ ASSERT_TRUE(ParseIPLiteralToNumber(entries[i].ip, &ip)); |
+ ASSERT_EQ(ip.size(), (entries[i].family == ADDRESS_FAMILY_IPV4) ? 4u : 16u); |
+ } |
mmenke
2014/07/24 21:32:30
Suggest making this block a function.
Deprecated (see juliatuttle)
2014/07/25 19:34:44
Done.
|
+ |
+ DnsHosts hosts; |
+ ParseHostsWithCommaMode(contents, &hosts, PARSE_HOSTS_COMMA_IS_TOKEN); |
+ ASSERT_EQ(expected, hosts); |
+} |
+ |
+TEST(DnsHostsTest, ParseHosts_CommaIsWhitespace) { |
+ std::string contents = |
+ "127.0.0.1 comma1,comma2"; |
+ |
+ const struct { |
+ const char* host; |
+ AddressFamily family; |
+ const char* ip; |
+ } entries[] = { |
+ { "comma1", ADDRESS_FAMILY_IPV4, "127.0.0.1" }, |
+ { "comma2", ADDRESS_FAMILY_IPV4, "127.0.0.1" }, |
+ }; |
+ |
+ DnsHosts expected; |
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(entries); ++i) { |
+ DnsHostsKey key(entries[i].host, entries[i].family); |
+ IPAddressNumber& ip = expected[key]; |
+ ASSERT_TRUE(ip.empty()); |
+ ASSERT_TRUE(ParseIPLiteralToNumber(entries[i].ip, &ip)); |
+ ASSERT_EQ(ip.size(), (entries[i].family == ADDRESS_FAMILY_IPV4) ? 4u : 16u); |
+ } |
+ |
+ DnsHosts hosts; |
+ ParseHostsWithCommaMode(contents, &hosts, PARSE_HOSTS_COMMA_IS_WHITESPACE); |
+ ASSERT_EQ(expected, hosts); |
+} |
+ |
TEST(DnsHostsTest, HostsParser_Empty) { |
DnsHosts hosts; |
ParseHosts("", &hosts); |