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

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

Issue 10543168: [net/dns] Instrument DnsConfigService to measure performance and failures. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 8 years, 6 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
« no previous file with comments | « net/dns/dns_config_service_posix.cc ('k') | net/dns/dns_config_service_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 <resolv.h> 5 #include <resolv.h>
6 6
7 #include "base/sys_byteorder.h" 7 #include "base/sys_byteorder.h"
8 #include "net/dns/dns_config_service_posix.h" 8 #include "net/dns/dns_config_service_posix.h"
9 9
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 12 matching lines...) Expand all
23 const char* kNameserversIPv6[] = { 23 const char* kNameserversIPv6[] = {
24 NULL, 24 NULL,
25 "2001:DB8:0::42", 25 "2001:DB8:0::42",
26 NULL, 26 NULL,
27 "::FFFF:129.144.52.38", 27 "::FFFF:129.144.52.38",
28 }; 28 };
29 29
30 // Fills in |res| with sane configuration. 30 // Fills in |res| with sane configuration.
31 void InitializeResState(res_state res) { 31 void InitializeResState(res_state res) {
32 memset(res, 0, sizeof(*res)); 32 memset(res, 0, sizeof(*res));
33 res->options = RES_INIT | RES_ROTATE; 33 res->options = RES_INIT | RES_RECURSE | RES_DEFNAMES | RES_DNSRCH |
34 RES_ROTATE;
34 res->ndots = 2; 35 res->ndots = 2;
35 res->retrans = 4; 36 res->retrans = 4;
36 res->retry = 7; 37 res->retry = 7;
37 38
38 const char kDnsrch[] = "chromium.org" "\0" "example.com"; 39 const char kDnsrch[] = "chromium.org" "\0" "example.com";
39 memcpy(res->defdname, kDnsrch, sizeof(kDnsrch)); 40 memcpy(res->defdname, kDnsrch, sizeof(kDnsrch));
40 res->dnsrch[0] = res->defdname; 41 res->dnsrch[0] = res->defdname;
41 res->dnsrch[1] = res->defdname + sizeof("chromium.org"); 42 res->dnsrch[1] = res->defdname + sizeof("chromium.org");
42 43
43 for (unsigned i = 0; i < arraysize(kNameserversIPv4) && i < MAXNS; ++i) { 44 for (unsigned i = 0; i < arraysize(kNameserversIPv4) && i < MAXNS; ++i) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 config->nameservers[i] = IPEndPoint(ip, NS_DEFAULTPORT - i); 106 config->nameservers[i] = IPEndPoint(ip, NS_DEFAULTPORT - i);
106 } 107 }
107 #endif 108 #endif
108 } 109 }
109 110
110 TEST(DnsConfigServicePosixTest, ConvertResStateToDnsConfig) { 111 TEST(DnsConfigServicePosixTest, ConvertResStateToDnsConfig) {
111 struct __res_state res; 112 struct __res_state res;
112 DnsConfig config; 113 DnsConfig config;
113 EXPECT_FALSE(config.IsValid()); 114 EXPECT_FALSE(config.IsValid());
114 InitializeResState(&res); 115 InitializeResState(&res);
115 ASSERT_TRUE(internal::ConvertResStateToDnsConfig(res, &config)); 116 ASSERT_EQ(internal::CONFIG_PARSE_POSIX_OK,
117 internal::ConvertResStateToDnsConfig(res, &config));
116 CloseResState(&res); 118 CloseResState(&res);
117 EXPECT_TRUE(config.IsValid()); 119 EXPECT_TRUE(config.IsValid());
118 120
119 DnsConfig expected_config; 121 DnsConfig expected_config;
120 EXPECT_FALSE(expected_config.EqualsIgnoreHosts(config)); 122 EXPECT_FALSE(expected_config.EqualsIgnoreHosts(config));
121 InitializeExpectedConfig(&expected_config); 123 InitializeExpectedConfig(&expected_config);
122 EXPECT_TRUE(expected_config.EqualsIgnoreHosts(config)); 124 EXPECT_TRUE(expected_config.EqualsIgnoreHosts(config));
123 } 125 }
124 126
125 TEST(DnsConfigServicePosixTest, RejectEmptyNameserver) { 127 TEST(DnsConfigServicePosixTest, RejectEmptyNameserver) {
126 struct __res_state res = {}; 128 struct __res_state res = {};
127 res.options = RES_INIT; 129 res.options = RES_INIT | RES_RECURSE | RES_DEFNAMES | RES_DNSRCH;
128 const char kDnsrch[] = "chromium.org"; 130 const char kDnsrch[] = "chromium.org";
129 memcpy(res.defdname, kDnsrch, sizeof(kDnsrch)); 131 memcpy(res.defdname, kDnsrch, sizeof(kDnsrch));
130 res.dnsrch[0] = res.defdname; 132 res.dnsrch[0] = res.defdname;
131 133
132 struct sockaddr_in sa = {}; 134 struct sockaddr_in sa = {};
133 sa.sin_family = AF_INET; 135 sa.sin_family = AF_INET;
134 sa.sin_port = base::HostToNet16(NS_DEFAULTPORT); 136 sa.sin_port = base::HostToNet16(NS_DEFAULTPORT);
135 sa.sin_addr.s_addr = INADDR_ANY; 137 sa.sin_addr.s_addr = INADDR_ANY;
136 res.nsaddr_list[0] = sa; 138 res.nsaddr_list[0] = sa;
137 sa.sin_addr.s_addr = 0xCAFE1337; 139 sa.sin_addr.s_addr = 0xCAFE1337;
138 res.nsaddr_list[1] = sa; 140 res.nsaddr_list[1] = sa;
139 res.nscount = 2; 141 res.nscount = 2;
140 142
141 DnsConfig config; 143 DnsConfig config;
142 EXPECT_FALSE(internal::ConvertResStateToDnsConfig(res, &config)); 144 EXPECT_EQ(internal::CONFIG_PARSE_POSIX_NULL_ADDRESS,
145 internal::ConvertResStateToDnsConfig(res, &config));
143 146
144 sa.sin_addr.s_addr = 0xDEADBEEF; 147 sa.sin_addr.s_addr = 0xDEADBEEF;
145 res.nsaddr_list[0] = sa; 148 res.nsaddr_list[0] = sa;
146 EXPECT_TRUE(internal::ConvertResStateToDnsConfig(res, &config)); 149 EXPECT_EQ(internal::CONFIG_PARSE_POSIX_OK,
150 internal::ConvertResStateToDnsConfig(res, &config));
147 } 151 }
148 152
149 } // namespace 153 } // namespace
150 } // namespace net 154 } // namespace net
OLDNEW
« no previous file with comments | « net/dns/dns_config_service_posix.cc ('k') | net/dns/dns_config_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698