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

Side by Side Diff: net/dns/dns_hosts_unittest.cc

Issue 662553002: Convert ARRAYSIZE_UNSAFE -> arraysize in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « net/cookies/cookie_util_unittest.cc ('k') | net/dns/dns_response_unittest.cc » ('j') | 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 { "ip6-localnet", ADDRESS_FAMILY_IPV6, "fe00::0" }, 59 { "ip6-localnet", ADDRESS_FAMILY_IPV6, "fe00::0" },
60 { "company", ADDRESS_FAMILY_IPV6, "2048::1" }, 60 { "company", ADDRESS_FAMILY_IPV6, "2048::1" },
61 { "example", ADDRESS_FAMILY_IPV6, "2048::2" }, 61 { "example", ADDRESS_FAMILY_IPV6, "2048::2" },
62 { "cache1", ADDRESS_FAMILY_IPV4, "127.0.0.1" }, 62 { "cache1", ADDRESS_FAMILY_IPV4, "127.0.0.1" },
63 { "cache2", ADDRESS_FAMILY_IPV4, "127.0.0.1" }, 63 { "cache2", ADDRESS_FAMILY_IPV4, "127.0.0.1" },
64 { "cache4", ADDRESS_FAMILY_IPV4, "127.0.0.1" }, 64 { "cache4", ADDRESS_FAMILY_IPV4, "127.0.0.1" },
65 { "cache5", ADDRESS_FAMILY_IPV4, "127.0.0.2" }, 65 { "cache5", ADDRESS_FAMILY_IPV4, "127.0.0.2" },
66 }; 66 };
67 67
68 DnsHosts expected_hosts, actual_hosts; 68 DnsHosts expected_hosts, actual_hosts;
69 PopulateExpectedHosts(kEntries, ARRAYSIZE_UNSAFE(kEntries), &expected_hosts); 69 PopulateExpectedHosts(kEntries, arraysize(kEntries), &expected_hosts);
70 ParseHosts(kContents, &actual_hosts); 70 ParseHosts(kContents, &actual_hosts);
71 ASSERT_EQ(expected_hosts, actual_hosts); 71 ASSERT_EQ(expected_hosts, actual_hosts);
72 } 72 }
73 73
74 TEST(DnsHostsTest, ParseHosts_CommaIsToken) { 74 TEST(DnsHostsTest, ParseHosts_CommaIsToken) {
75 const std::string kContents = "127.0.0.1 comma1,comma2"; 75 const std::string kContents = "127.0.0.1 comma1,comma2";
76 76
77 const ExpectedHostsEntry kEntries[] = { 77 const ExpectedHostsEntry kEntries[] = {
78 { "comma1,comma2", ADDRESS_FAMILY_IPV4, "127.0.0.1" }, 78 { "comma1,comma2", ADDRESS_FAMILY_IPV4, "127.0.0.1" },
79 }; 79 };
80 80
81 DnsHosts expected_hosts, actual_hosts; 81 DnsHosts expected_hosts, actual_hosts;
82 PopulateExpectedHosts(kEntries, ARRAYSIZE_UNSAFE(kEntries), &expected_hosts); 82 PopulateExpectedHosts(kEntries, arraysize(kEntries), &expected_hosts);
83 ParseHostsWithCommaModeForTesting( 83 ParseHostsWithCommaModeForTesting(
84 kContents, &actual_hosts, PARSE_HOSTS_COMMA_IS_TOKEN); 84 kContents, &actual_hosts, PARSE_HOSTS_COMMA_IS_TOKEN);
85 ASSERT_EQ(expected_hosts, actual_hosts); 85 ASSERT_EQ(expected_hosts, actual_hosts);
86 } 86 }
87 87
88 TEST(DnsHostsTest, ParseHosts_CommaIsWhitespace) { 88 TEST(DnsHostsTest, ParseHosts_CommaIsWhitespace) {
89 std::string kContents = "127.0.0.1 comma1,comma2"; 89 std::string kContents = "127.0.0.1 comma1,comma2";
90 90
91 const ExpectedHostsEntry kEntries[] = { 91 const ExpectedHostsEntry kEntries[] = {
92 { "comma1", ADDRESS_FAMILY_IPV4, "127.0.0.1" }, 92 { "comma1", ADDRESS_FAMILY_IPV4, "127.0.0.1" },
93 { "comma2", ADDRESS_FAMILY_IPV4, "127.0.0.1" }, 93 { "comma2", ADDRESS_FAMILY_IPV4, "127.0.0.1" },
94 }; 94 };
95 95
96 DnsHosts expected_hosts, actual_hosts; 96 DnsHosts expected_hosts, actual_hosts;
97 PopulateExpectedHosts(kEntries, ARRAYSIZE_UNSAFE(kEntries), &expected_hosts); 97 PopulateExpectedHosts(kEntries, arraysize(kEntries), &expected_hosts);
98 ParseHostsWithCommaModeForTesting( 98 ParseHostsWithCommaModeForTesting(
99 kContents, &actual_hosts, PARSE_HOSTS_COMMA_IS_WHITESPACE); 99 kContents, &actual_hosts, PARSE_HOSTS_COMMA_IS_WHITESPACE);
100 ASSERT_EQ(expected_hosts, actual_hosts); 100 ASSERT_EQ(expected_hosts, actual_hosts);
101 } 101 }
102 102
103 // Test that the right comma mode is used on each platform. 103 // Test that the right comma mode is used on each platform.
104 TEST(DnsHostsTest, ParseHosts_CommaModeByPlatform) { 104 TEST(DnsHostsTest, ParseHosts_CommaModeByPlatform) {
105 std::string kContents = "127.0.0.1 comma1,comma2"; 105 std::string kContents = "127.0.0.1 comma1,comma2";
106 106
107 #if defined(OS_MACOSX) 107 #if defined(OS_MACOSX)
108 const ExpectedHostsEntry kEntries[] = { 108 const ExpectedHostsEntry kEntries[] = {
109 { "comma1", ADDRESS_FAMILY_IPV4, "127.0.0.1" }, 109 { "comma1", ADDRESS_FAMILY_IPV4, "127.0.0.1" },
110 { "comma2", ADDRESS_FAMILY_IPV4, "127.0.0.1" }, 110 { "comma2", ADDRESS_FAMILY_IPV4, "127.0.0.1" },
111 }; 111 };
112 #else 112 #else
113 const ExpectedHostsEntry kEntries[] = { 113 const ExpectedHostsEntry kEntries[] = {
114 { "comma1,comma2", ADDRESS_FAMILY_IPV4, "127.0.0.1" }, 114 { "comma1,comma2", ADDRESS_FAMILY_IPV4, "127.0.0.1" },
115 }; 115 };
116 #endif 116 #endif
117 117
118 DnsHosts expected_hosts, actual_hosts; 118 DnsHosts expected_hosts, actual_hosts;
119 PopulateExpectedHosts(kEntries, ARRAYSIZE_UNSAFE(kEntries), &expected_hosts); 119 PopulateExpectedHosts(kEntries, arraysize(kEntries), &expected_hosts);
120 ParseHosts(kContents, &actual_hosts); 120 ParseHosts(kContents, &actual_hosts);
121 ASSERT_EQ(expected_hosts, actual_hosts); 121 ASSERT_EQ(expected_hosts, actual_hosts);
122 } 122 }
123 123
124 TEST(DnsHostsTest, HostsParser_Empty) { 124 TEST(DnsHostsTest, HostsParser_Empty) {
125 DnsHosts hosts; 125 DnsHosts hosts;
126 ParseHosts("", &hosts); 126 ParseHosts("", &hosts);
127 EXPECT_EQ(0u, hosts.size()); 127 EXPECT_EQ(0u, hosts.size());
128 } 128 }
129 129
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 TEST(DnsHostsTest, HostsParser_EndsWithNewlineAndToken) { 172 TEST(DnsHostsTest, HostsParser_EndsWithNewlineAndToken) {
173 DnsHosts hosts; 173 DnsHosts hosts;
174 ParseHosts("127.0.0.1 localhost\ntoken", &hosts); 174 ParseHosts("127.0.0.1 localhost\ntoken", &hosts);
175 EXPECT_EQ(1u, hosts.size()); 175 EXPECT_EQ(1u, hosts.size());
176 } 176 }
177 177
178 } // namespace 178 } // namespace
179 179
180 } // namespace net 180 } // namespace net
181 181
OLDNEW
« no previous file with comments | « net/cookies/cookie_util_unittest.cc ('k') | net/dns/dns_response_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698