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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« net/dns/dns_hosts.cc ('K') | « net/dns/dns_hosts.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/dns/dns_hosts.h" 5 #include "net/dns/dns_hosts.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace net { 9 namespace net {
10 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 ASSERT_TRUE(ip.empty()); 57 ASSERT_TRUE(ip.empty());
58 ASSERT_TRUE(ParseIPLiteralToNumber(entries[i].ip, &ip)); 58 ASSERT_TRUE(ParseIPLiteralToNumber(entries[i].ip, &ip));
59 ASSERT_EQ(ip.size(), (entries[i].family == ADDRESS_FAMILY_IPV4) ? 4u : 16u); 59 ASSERT_EQ(ip.size(), (entries[i].family == ADDRESS_FAMILY_IPV4) ? 4u : 16u);
60 } 60 }
61 61
62 DnsHosts hosts; 62 DnsHosts hosts;
63 ParseHosts(contents, &hosts); 63 ParseHosts(contents, &hosts);
64 ASSERT_EQ(expected, hosts); 64 ASSERT_EQ(expected, hosts);
65 } 65 }
66 66
67 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
68 std::string contents =
69 "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.
70
71 const struct {
72 const char* host;
73 AddressFamily family;
74 const char* ip;
75 } 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.
76 { "comma1,comma2", ADDRESS_FAMILY_IPV4, "127.0.0.1" },
77 };
78
79 DnsHosts expected;
80 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(entries); ++i) {
81 DnsHostsKey key(entries[i].host, entries[i].family);
82 IPAddressNumber& ip = expected[key];
83 ASSERT_TRUE(ip.empty());
84 ASSERT_TRUE(ParseIPLiteralToNumber(entries[i].ip, &ip));
85 ASSERT_EQ(ip.size(), (entries[i].family == ADDRESS_FAMILY_IPV4) ? 4u : 16u);
86 }
mmenke 2014/07/24 21:32:30 Suggest making this block a function.
Deprecated (see juliatuttle) 2014/07/25 19:34:44 Done.
87
88 DnsHosts hosts;
89 ParseHostsWithCommaMode(contents, &hosts, PARSE_HOSTS_COMMA_IS_TOKEN);
90 ASSERT_EQ(expected, hosts);
91 }
92
93 TEST(DnsHostsTest, ParseHosts_CommaIsWhitespace) {
94 std::string contents =
95 "127.0.0.1 comma1,comma2";
96
97 const struct {
98 const char* host;
99 AddressFamily family;
100 const char* ip;
101 } entries[] = {
102 { "comma1", ADDRESS_FAMILY_IPV4, "127.0.0.1" },
103 { "comma2", ADDRESS_FAMILY_IPV4, "127.0.0.1" },
104 };
105
106 DnsHosts expected;
107 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(entries); ++i) {
108 DnsHostsKey key(entries[i].host, entries[i].family);
109 IPAddressNumber& ip = expected[key];
110 ASSERT_TRUE(ip.empty());
111 ASSERT_TRUE(ParseIPLiteralToNumber(entries[i].ip, &ip));
112 ASSERT_EQ(ip.size(), (entries[i].family == ADDRESS_FAMILY_IPV4) ? 4u : 16u);
113 }
114
115 DnsHosts hosts;
116 ParseHostsWithCommaMode(contents, &hosts, PARSE_HOSTS_COMMA_IS_WHITESPACE);
117 ASSERT_EQ(expected, hosts);
118 }
119
67 TEST(DnsHostsTest, HostsParser_Empty) { 120 TEST(DnsHostsTest, HostsParser_Empty) {
68 DnsHosts hosts; 121 DnsHosts hosts;
69 ParseHosts("", &hosts); 122 ParseHosts("", &hosts);
70 EXPECT_EQ(0u, hosts.size()); 123 EXPECT_EQ(0u, hosts.size());
71 } 124 }
72 125
73 TEST(DnsHostsTest, HostsParser_OnlyWhitespace) { 126 TEST(DnsHostsTest, HostsParser_OnlyWhitespace) {
74 DnsHosts hosts; 127 DnsHosts hosts;
75 ParseHosts(" ", &hosts); 128 ParseHosts(" ", &hosts);
76 EXPECT_EQ(0u, hosts.size()); 129 EXPECT_EQ(0u, hosts.size());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 TEST(DnsHostsTest, HostsParser_EndsWithNewlineAndToken) { 168 TEST(DnsHostsTest, HostsParser_EndsWithNewlineAndToken) {
116 DnsHosts hosts; 169 DnsHosts hosts;
117 ParseHosts("127.0.0.1 localhost\ntoken", &hosts); 170 ParseHosts("127.0.0.1 localhost\ntoken", &hosts);
118 EXPECT_EQ(1u, hosts.size()); 171 EXPECT_EQ(1u, hosts.size());
119 } 172 }
120 173
121 } // namespace 174 } // namespace
122 175
123 } // namespace net 176 } // namespace net
124 177
OLDNEW
« 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