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

Side by Side Diff: net/base/ip_endpoint_unittest.cc

Issue 1565303002: Change IPEndpoint::address() to return a net::IPAddress (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Android Created 4 years, 11 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
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/base/ip_endpoint.h" 5 #include "net/base/ip_endpoint.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <winsock2.h> 10 #include <winsock2.h>
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 74 }
75 }; 75 };
76 76
77 TEST_F(IPEndPointTest, Constructor) { 77 TEST_F(IPEndPointTest, Constructor) {
78 IPEndPoint endpoint; 78 IPEndPoint endpoint;
79 EXPECT_EQ(0, endpoint.port()); 79 EXPECT_EQ(0, endpoint.port());
80 80
81 for (uint16_t index = 0; index < test_count; ++index) { 81 for (uint16_t index = 0; index < test_count; ++index) {
82 IPEndPoint endpoint(tests[index].ip_address, 80); 82 IPEndPoint endpoint(tests[index].ip_address, 80);
83 EXPECT_EQ(80, endpoint.port()); 83 EXPECT_EQ(80, endpoint.port());
84 EXPECT_EQ(tests[index].ip_address, endpoint.address()); 84 EXPECT_EQ(tests[index].ip_address, endpoint.address_number());
85 } 85 }
86 } 86 }
87 87
88 TEST_F(IPEndPointTest, Assignment) { 88 TEST_F(IPEndPointTest, Assignment) {
89 for (uint16_t index = 0; index < test_count; ++index) { 89 for (uint16_t index = 0; index < test_count; ++index) {
90 IPEndPoint src(tests[index].ip_address, index); 90 IPEndPoint src(tests[index].ip_address, index);
91 IPEndPoint dest = src; 91 IPEndPoint dest = src;
92 92
93 EXPECT_EQ(src.port(), dest.port()); 93 EXPECT_EQ(src.port(), dest.port());
94 EXPECT_EQ(src.address(), dest.address()); 94 EXPECT_EQ(src.address_number(), dest.address_number());
95 } 95 }
96 } 96 }
97 97
98 TEST_F(IPEndPointTest, Copy) { 98 TEST_F(IPEndPointTest, Copy) {
99 for (uint16_t index = 0; index < test_count; ++index) { 99 for (uint16_t index = 0; index < test_count; ++index) {
100 IPEndPoint src(tests[index].ip_address, index); 100 IPEndPoint src(tests[index].ip_address, index);
101 IPEndPoint dest(src); 101 IPEndPoint dest(src);
102 102
103 EXPECT_EQ(src.port(), dest.port()); 103 EXPECT_EQ(src.port(), dest.port());
104 EXPECT_EQ(src.address(), dest.address()); 104 EXPECT_EQ(src.address_number(), dest.address_number());
105 } 105 }
106 } 106 }
107 107
108 TEST_F(IPEndPointTest, ToFromSockAddr) { 108 TEST_F(IPEndPointTest, ToFromSockAddr) {
109 for (uint16_t index = 0; index < test_count; ++index) { 109 for (uint16_t index = 0; index < test_count; ++index) {
110 IPEndPoint ip_endpoint(tests[index].ip_address, index); 110 IPEndPoint ip_endpoint(tests[index].ip_address, index);
111 111
112 // Convert to a sockaddr. 112 // Convert to a sockaddr.
113 SockaddrStorage storage; 113 SockaddrStorage storage;
114 EXPECT_TRUE(ip_endpoint.ToSockAddr(storage.addr, &storage.addr_len)); 114 EXPECT_TRUE(ip_endpoint.ToSockAddr(storage.addr, &storage.addr_len));
115 115
116 // Basic verification. 116 // Basic verification.
117 socklen_t expected_size = tests[index].ipv6 ? 117 socklen_t expected_size = tests[index].ipv6 ?
118 sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in); 118 sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in);
119 EXPECT_EQ(expected_size, storage.addr_len); 119 EXPECT_EQ(expected_size, storage.addr_len);
120 EXPECT_EQ(ip_endpoint.port(), GetPortFromSockaddr(storage.addr, 120 EXPECT_EQ(ip_endpoint.port(), GetPortFromSockaddr(storage.addr,
121 storage.addr_len)); 121 storage.addr_len));
122 122
123 // And convert back to an IPEndPoint. 123 // And convert back to an IPEndPoint.
124 IPEndPoint ip_endpoint2; 124 IPEndPoint ip_endpoint2;
125 EXPECT_TRUE(ip_endpoint2.FromSockAddr(storage.addr, storage.addr_len)); 125 EXPECT_TRUE(ip_endpoint2.FromSockAddr(storage.addr, storage.addr_len));
126 EXPECT_EQ(ip_endpoint.port(), ip_endpoint2.port()); 126 EXPECT_EQ(ip_endpoint.port(), ip_endpoint2.port());
127 EXPECT_EQ(ip_endpoint.address(), ip_endpoint2.address()); 127 EXPECT_EQ(ip_endpoint.address_number(), ip_endpoint2.address_number());
128 } 128 }
129 } 129 }
130 130
131 TEST_F(IPEndPointTest, ToSockAddrBufTooSmall) { 131 TEST_F(IPEndPointTest, ToSockAddrBufTooSmall) {
132 for (uint16_t index = 0; index < test_count; ++index) { 132 for (uint16_t index = 0; index < test_count; ++index) {
133 IPEndPoint ip_endpoint(tests[index].ip_address, index); 133 IPEndPoint ip_endpoint(tests[index].ip_address, index);
134 134
135 SockaddrStorage storage; 135 SockaddrStorage storage;
136 storage.addr_len = index; // size is too small! 136 storage.addr_len = index; // size is too small!
137 EXPECT_FALSE(ip_endpoint.ToSockAddr(storage.addr, &storage.addr_len)); 137 EXPECT_FALSE(ip_endpoint.ToSockAddr(storage.addr, &storage.addr_len));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 IPEndPoint endpoint(tests[index].ip_address, port); 196 IPEndPoint endpoint(tests[index].ip_address, port);
197 const std::string result = endpoint.ToString(); 197 const std::string result = endpoint.ToString();
198 EXPECT_EQ(tests[index].host_normalized + ":" + base::UintToString(port), 198 EXPECT_EQ(tests[index].host_normalized + ":" + base::UintToString(port),
199 result); 199 result);
200 } 200 }
201 } 201 }
202 202
203 } // namespace 203 } // namespace
204 204
205 } // namespace net 205 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698