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

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

Issue 9716020: Add base::HostToNetXX() & NetToHostXX(), and use them to replace htonX() & ntohX() in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 8 years, 8 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/base/net_util_unittest.cc ('k') | net/dns/dns_query.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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 66
67 const char* ip4addr[3] = { 67 const char* ip4addr[3] = {
68 "8.8.8.8", 68 "8.8.8.8",
69 "192.168.1.1", 69 "192.168.1.1",
70 "63.1.2.4", 70 "63.1.2.4",
71 }; 71 };
72 72
73 for (int i = 0; i < 3; ++i) { 73 for (int i = 0; i < 3; ++i) {
74 struct sockaddr_in sa; 74 struct sockaddr_in sa;
75 sa.sin_family = AF_INET; 75 sa.sin_family = AF_INET;
76 sa.sin_port = htons(NS_DEFAULTPORT + i - generation); 76 sa.sin_port = base::HostToNet16(NS_DEFAULTPORT + i - generation);
77 inet_pton(AF_INET, ip4addr[i], &sa.sin_addr); 77 inet_pton(AF_INET, ip4addr[i], &sa.sin_addr);
78 res->nsaddr_list[i] = sa; 78 res->nsaddr_list[i] = sa;
79 } 79 }
80 res->nscount = 3; 80 res->nscount = 3;
81 81
82 #if defined(OS_LINUX) 82 #if defined(OS_LINUX)
83 const char* ip6addr[2] = { 83 const char* ip6addr[2] = {
84 "2001:db8:0::42", 84 "2001:db8:0::42",
85 "::FFFF:129.144.52.38", 85 "::FFFF:129.144.52.38",
86 }; 86 };
87 87
88 for (int i = 0; i < 2; ++i) { 88 for (int i = 0; i < 2; ++i) {
89 // Must use malloc to mimick res_ninit. 89 // Must use malloc to mimick res_ninit.
90 struct sockaddr_in6 *sa6; 90 struct sockaddr_in6 *sa6;
91 sa6 = (struct sockaddr_in6 *)malloc(sizeof(*sa6)); 91 sa6 = (struct sockaddr_in6 *)malloc(sizeof(*sa6));
92 sa6->sin6_family = AF_INET6; 92 sa6->sin6_family = AF_INET6;
93 sa6->sin6_port = htons(NS_DEFAULTPORT - i); 93 sa6->sin6_port = base::HostToNet16(NS_DEFAULTPORT - i);
94 inet_pton(AF_INET6, ip6addr[i], &sa6->sin6_addr); 94 inet_pton(AF_INET6, ip6addr[i], &sa6->sin6_addr);
95 res->_u._ext.nsaddrs[i] = sa6; 95 res->_u._ext.nsaddrs[i] = sa6;
96 } 96 }
97 res->_u._ext.nscount6 = 2; 97 res->_u._ext.nscount6 = 2;
98 #endif 98 #endif
99 } 99 }
100 100
101 void CloseResState(res_state res) { 101 void CloseResState(res_state res) {
102 #if defined(OS_LINUX) 102 #if defined(OS_LINUX)
103 for (int i = 0; i < res->_u._ext.nscount6; ++i) { 103 for (int i = 0; i < res->_u._ext.nscount6; ++i) {
(...skipping 16 matching lines...) Expand all
120 CompareConfig(res[i], config[i]); 120 CompareConfig(res[i], config[i]);
121 CloseResState(&res[i]); 121 CloseResState(&res[i]);
122 } 122 }
123 EXPECT_TRUE(config[0].Equals(config[0])); 123 EXPECT_TRUE(config[0].Equals(config[0]));
124 EXPECT_FALSE(config[0].Equals(config[1])); 124 EXPECT_FALSE(config[0].Equals(config[1]));
125 EXPECT_FALSE(config[1].Equals(config[0])); 125 EXPECT_FALSE(config[1].Equals(config[0]));
126 } 126 }
127 127
128 } // namespace 128 } // namespace
129 } // namespace net 129 } // namespace net
130
131
OLDNEW
« no previous file with comments | « net/base/net_util_unittest.cc ('k') | net/dns/dns_query.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698