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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
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"
11 11
12 #if !defined(OS_ANDROID) 12 #if !defined(OS_ANDROID)
13 13
14 namespace net { 14 namespace net {
15 namespace { 15 namespace {
16 16
17 // MAXNS is normally 3, but let's test 4 if possible. 17 // MAXNS is normally 3, but let's test 4 if possible.
18 const char* kNameserversIPv4[] = { 18 const char* kNameserversIPv4[] = {
19 "8.8.8.8", 19 "8.8.8.8", "192.168.1.1", "63.1.2.4", "1.0.0.1",
20 "192.168.1.1",
21 "63.1.2.4",
22 "1.0.0.1",
23 }; 20 };
24 21
25 #if defined(OS_LINUX) 22 #if defined(OS_LINUX)
26 const char* kNameserversIPv6[] = { 23 const char* kNameserversIPv6[] = {
27 NULL, 24 NULL, "2001:DB8:0::42", NULL, "::FFFF:129.144.52.38",
28 "2001:DB8:0::42",
29 NULL,
30 "::FFFF:129.144.52.38",
31 }; 25 };
32 #endif 26 #endif
33 27
34 // Fills in |res| with sane configuration. 28 // Fills in |res| with sane configuration.
35 void InitializeResState(res_state res) { 29 void InitializeResState(res_state res) {
36 memset(res, 0, sizeof(*res)); 30 memset(res, 0, sizeof(*res));
37 res->options = RES_INIT | RES_RECURSE | RES_DEFNAMES | RES_DNSRCH | 31 res->options =
38 RES_ROTATE; 32 RES_INIT | RES_RECURSE | RES_DEFNAMES | RES_DNSRCH | RES_ROTATE;
39 res->ndots = 2; 33 res->ndots = 2;
40 res->retrans = 4; 34 res->retrans = 4;
41 res->retry = 7; 35 res->retry = 7;
42 36
43 const char kDnsrch[] = "chromium.org" "\0" "example.com"; 37 const char kDnsrch[] =
38 "chromium.org"
39 "\0"
40 "example.com";
44 memcpy(res->defdname, kDnsrch, sizeof(kDnsrch)); 41 memcpy(res->defdname, kDnsrch, sizeof(kDnsrch));
45 res->dnsrch[0] = res->defdname; 42 res->dnsrch[0] = res->defdname;
46 res->dnsrch[1] = res->defdname + sizeof("chromium.org"); 43 res->dnsrch[1] = res->defdname + sizeof("chromium.org");
47 44
48 for (unsigned i = 0; i < arraysize(kNameserversIPv4) && i < MAXNS; ++i) { 45 for (unsigned i = 0; i < arraysize(kNameserversIPv4) && i < MAXNS; ++i) {
49 struct sockaddr_in sa; 46 struct sockaddr_in sa;
50 sa.sin_family = AF_INET; 47 sa.sin_family = AF_INET;
51 sa.sin_port = base::HostToNet16(NS_DEFAULTPORT + i); 48 sa.sin_port = base::HostToNet16(NS_DEFAULTPORT + i);
52 inet_pton(AF_INET, kNameserversIPv4[i], &sa.sin_addr); 49 inet_pton(AF_INET, kNameserversIPv4[i], &sa.sin_addr);
53 res->nsaddr_list[i] = sa; 50 res->nsaddr_list[i] = sa;
54 ++res->nscount; 51 ++res->nscount;
55 } 52 }
56 53
57 #if defined(OS_LINUX) 54 #if defined(OS_LINUX)
58 // Install IPv6 addresses, replacing the corresponding IPv4 addresses. 55 // Install IPv6 addresses, replacing the corresponding IPv4 addresses.
59 unsigned nscount6 = 0; 56 unsigned nscount6 = 0;
60 for (unsigned i = 0; i < arraysize(kNameserversIPv6) && i < MAXNS; ++i) { 57 for (unsigned i = 0; i < arraysize(kNameserversIPv6) && i < MAXNS; ++i) {
61 if (!kNameserversIPv6[i]) 58 if (!kNameserversIPv6[i])
62 continue; 59 continue;
63 // Must use malloc to mimick res_ninit. 60 // Must use malloc to mimick res_ninit.
64 struct sockaddr_in6 *sa6; 61 struct sockaddr_in6* sa6;
65 sa6 = (struct sockaddr_in6 *)malloc(sizeof(*sa6)); 62 sa6 = (struct sockaddr_in6*)malloc(sizeof(*sa6));
66 sa6->sin6_family = AF_INET6; 63 sa6->sin6_family = AF_INET6;
67 sa6->sin6_port = base::HostToNet16(NS_DEFAULTPORT - i); 64 sa6->sin6_port = base::HostToNet16(NS_DEFAULTPORT - i);
68 inet_pton(AF_INET6, kNameserversIPv6[i], &sa6->sin6_addr); 65 inet_pton(AF_INET6, kNameserversIPv6[i], &sa6->sin6_addr);
69 res->_u._ext.nsaddrs[i] = sa6; 66 res->_u._ext.nsaddrs[i] = sa6;
70 memset(&res->nsaddr_list[i], 0, sizeof res->nsaddr_list[i]); 67 memset(&res->nsaddr_list[i], 0, sizeof res->nsaddr_list[i]);
71 ++nscount6; 68 ++nscount6;
72 } 69 }
73 res->_u._ext.nscount6 = nscount6; 70 res->_u._ext.nscount6 = nscount6;
74 #endif 71 #endif
75 } 72 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 sa.sin_addr.s_addr = 0xDEADBEEF; 148 sa.sin_addr.s_addr = 0xDEADBEEF;
152 res.nsaddr_list[0] = sa; 149 res.nsaddr_list[0] = sa;
153 EXPECT_EQ(internal::CONFIG_PARSE_POSIX_OK, 150 EXPECT_EQ(internal::CONFIG_PARSE_POSIX_OK,
154 internal::ConvertResStateToDnsConfig(res, &config)); 151 internal::ConvertResStateToDnsConfig(res, &config));
155 } 152 }
156 153
157 } // namespace 154 } // namespace
158 } // namespace net 155 } // namespace net
159 156
160 #endif // !OS_ANDROID 157 #endif // !OS_ANDROID
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698