Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Unified Diff: net/dns/dns_hosts_unittest.cc

Issue 415153002: ParseHosts: Allow commas as separators on Mac OS X (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make comma-handling OS-specific Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« net/dns/dns_hosts.cc ('K') | « net/dns/dns_hosts.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« net/dns/dns_hosts.cc ('K') | « net/dns/dns_hosts.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698