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

Side by Side Diff: ppapi/tests/test_net_address_private.cc

Issue 9307115: PPB_NetAddress_Private: add getter methods for sockaddr. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 10 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) 2011 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 "ppapi/tests/test_net_address_private.h" 5 #include "ppapi/tests/test_net_address_private.h"
6 6
7 #include <string.h>
8
7 #include "ppapi/cpp/private/net_address_private.h" 9 #include "ppapi/cpp/private/net_address_private.h"
8 #include "ppapi/c/private/ppb_net_address_private.h" 10 #include "ppapi/c/private/ppb_net_address_private.h"
9 #include "ppapi/tests/test_utils.h" 11 #include "ppapi/tests/test_utils.h"
10 #include "ppapi/tests/testing_instance.h" 12 #include "ppapi/tests/testing_instance.h"
11 13
12 // Other than |GetAnyAddress()|, there's no way to actually get 14 // Other than |GetAnyAddress()|, there's no way to actually get
13 // |PP_NetAddress_Private| structs from just this interface. We'll cheat and 15 // |PP_NetAddress_Private| structs from just this interface. We'll cheat and
14 // synthesize some. 16 // synthesize some.
15 17
16 #if defined(PPAPI_POSIX) 18 #if defined(PPAPI_POSIX)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 return NetAddressPrivate::IsAvailable(); 75 return NetAddressPrivate::IsAvailable();
74 } 76 }
75 77
76 void TestNetAddressPrivate::RunTests(const std::string& filter) { 78 void TestNetAddressPrivate::RunTests(const std::string& filter) {
77 RUN_TEST(AreEqual, filter); 79 RUN_TEST(AreEqual, filter);
78 RUN_TEST(AreHostsEqual, filter); 80 RUN_TEST(AreHostsEqual, filter);
79 RUN_TEST(Describe, filter); 81 RUN_TEST(Describe, filter);
80 RUN_TEST(ReplacePort, filter); 82 RUN_TEST(ReplacePort, filter);
81 RUN_TEST(GetAnyAddress, filter); 83 RUN_TEST(GetAnyAddress, filter);
82 RUN_TEST(DescribeIPv6, filter); 84 RUN_TEST(DescribeIPv6, filter);
85 RUN_TEST(GetFamily, filter);
86 RUN_TEST(GetPort, filter);
87 RUN_TEST(GetAddress, filter);
83 } 88 }
84 89
85 std::string TestNetAddressPrivate::TestAreEqual() { 90 std::string TestNetAddressPrivate::TestAreEqual() {
86 // No comparisons should ever be done with invalid addresses. 91 // No comparisons should ever be done with invalid addresses.
87 PP_NetAddress_Private invalid = PP_NetAddress_Private(); 92 PP_NetAddress_Private invalid = PP_NetAddress_Private();
88 ASSERT_FALSE(NetAddressPrivate::AreEqual(invalid, invalid)); 93 ASSERT_FALSE(NetAddressPrivate::AreEqual(invalid, invalid));
89 94
90 PP_NetAddress_Private localhost_80 = MakeIPv4NetAddress("127.0.0.1", 80); 95 PP_NetAddress_Private localhost_80 = MakeIPv4NetAddress("127.0.0.1", 80);
91 ASSERT_TRUE(NetAddressPrivate::AreEqual(localhost_80, localhost_80)); 96 ASSERT_TRUE(NetAddressPrivate::AreEqual(localhost_80, localhost_80));
92 ASSERT_FALSE(NetAddressPrivate::AreEqual(localhost_80, invalid)); 97 ASSERT_FALSE(NetAddressPrivate::AreEqual(localhost_80, invalid));
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 test_cases[i].port, 242 test_cases[i].port,
238 test_cases[i].scope); 243 test_cases[i].scope);
239 ASSERT_EQ(test_cases[i].expected_without_port, 244 ASSERT_EQ(test_cases[i].expected_without_port,
240 NetAddressPrivate::Describe(addr, false)); 245 NetAddressPrivate::Describe(addr, false));
241 ASSERT_EQ(test_cases[i].expected_with_port, 246 ASSERT_EQ(test_cases[i].expected_with_port,
242 NetAddressPrivate::Describe(addr, true)); 247 NetAddressPrivate::Describe(addr, true));
243 } 248 }
244 249
245 PASS(); 250 PASS();
246 } 251 }
252
253 std::string TestNetAddressPrivate::TestGetFamily() {
254 PP_NetAddress_Private ipv4 = MakeIPv4NetAddress("127.0.0.1", 80);
255 ASSERT_EQ(NetAddressPrivate::GetFamily(ipv4), AF_INET);
256
257 uint16_t ipv6_address[8] = { 0x1234, 0xabcd, 0, 0, 0xff, 0, 0, 0xcdef };
258 PP_NetAddress_Private ipv6 = MakeIPv6NetAddress(ipv6_address,
259 123,
260 0);
261 ASSERT_EQ(NetAddressPrivate::GetFamily(ipv6), AF_INET6);
262
263 PASS();
264 }
265
266 std::string TestNetAddressPrivate::TestGetPort() {
267 PP_NetAddress_Private localhost_80 = MakeIPv4NetAddress("127.0.0.1", 80);
268 ASSERT_EQ(NetAddressPrivate::GetPort(localhost_80), 80);
269
270 uint16_t ipv6_address[8] = { 0x1234, 0xabcd, 0, 0, 0xff, 0, 0, 0xcdef };
271
272 PP_NetAddress_Private port_123 = MakeIPv6NetAddress(ipv6_address, 123, 0);
273 ASSERT_EQ(NetAddressPrivate::GetPort(port_123), 123);
274
275 PP_NetAddress_Private port_FFFF = MakeIPv6NetAddress(ipv6_address,
276 0xFFFF,
277 0);
278 ASSERT_EQ(NetAddressPrivate::GetPort(port_FFFF), 0xFFFF);
279
280 PASS();
281 }
282
283 std::string TestNetAddressPrivate::TestGetAddress() {
284 const int addr_storage_len = 16;
285 unsigned char addr_storage[addr_storage_len];
286
287 const char* ipv4_addr = "127.0.0.1";
288 uint32_t ipv4_addr_long = inet_addr(ipv4_addr);
289 PP_NetAddress_Private localhost_80 = MakeIPv4NetAddress(ipv4_addr, 80);
290 memset(addr_storage, 0, addr_storage_len);
291 ASSERT_TRUE(NetAddressPrivate::GetAddress(localhost_80,
292 addr_storage,
293 addr_storage_len));
294 ASSERT_EQ(memcmp(addr_storage, &ipv4_addr_long, 4), 0);
295
296 // Insufficient storage for address.
297 ASSERT_FALSE(NetAddressPrivate::GetAddress(localhost_80,
298 addr_storage,
299 1));
300
301 uint16_t ipv6_address[8] = { 0x1234, 0xabcd, 0, 0, 0xff, 0, 0, 0xcdef };
302 PP_NetAddress_Private ipv6_addr = MakeIPv6NetAddress(ipv6_address,
303 123,
304 0);
305
306 // Ensure the ipv6 address is transformed properly into network order.
307 for (int i = 0; i < 8; i++)
308 ipv6_address[i] = htons(ipv6_address[i]);
309
310 memset(addr_storage, 0, addr_storage_len);
311 ASSERT_TRUE(NetAddressPrivate::GetAddress(ipv6_addr,
312 addr_storage,
313 addr_storage_len));
314 ASSERT_EQ(memcmp(addr_storage, ipv6_address, 16), 0);
315
316 // Insufficient storage for address.
317 ASSERT_FALSE(NetAddressPrivate::GetAddress(ipv6_addr,
318 addr_storage,
319 1));
320
321 PASS();
322 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_net_address_private.h ('k') | ppapi/tests/test_net_address_private_untrusted.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698