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

Side by Side Diff: webrtc/base/ipaddress_unittest.cc

Issue 1516163003: Add "x"s in the end of a stripped IPv6 address string. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixed typo. Rebase. Created 5 years 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
« no previous file with comments | « webrtc/base/ipaddress.cc ('k') | webrtc/base/socketaddress_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 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/base/gunit.h" 11 #include "webrtc/base/gunit.h"
12 #include "webrtc/base/ipaddress.h" 12 #include "webrtc/base/ipaddress.h"
13 13
14 namespace rtc { 14 namespace rtc {
15 15
16 static const unsigned int kIPv4AddrSize = 4; 16 static const unsigned int kIPv4AddrSize = 4;
17 static const unsigned int kIPv6AddrSize = 16; 17 static const unsigned int kIPv6AddrSize = 16;
18 static const unsigned int kIPv4RFC1918Addr = 0xC0A80701; 18 static const unsigned int kIPv4RFC1918Addr = 0xC0A80701;
19 static const unsigned int kIPv4PublicAddr = 0x01020304; 19 static const unsigned int kIPv4PublicAddr = 0x01020304;
20 static const in6_addr kIPv6LinkLocalAddr = {{{0xfe, 0x80, 0x00, 0x00, 20 static const in6_addr kIPv6LinkLocalAddr = {{{0xfe, 0x80, 0x00, 0x00,
21 0x00, 0x00, 0x00, 0x00, 21 0x00, 0x00, 0x00, 0x00,
22 0xbe, 0x30, 0x5b, 0xff, 22 0xbe, 0x30, 0x5b, 0xff,
23 0xfe, 0xe5, 0x00, 0xc3}}}; 23 0xfe, 0xe5, 0x00, 0xc3}}};
24 static const in6_addr kIPv6PublicAddr = {{{0x24, 0x01, 0xfa, 0x00, 24 static const in6_addr kIPv6PublicAddr = {{{0x24, 0x01, 0xfa, 0x00,
25 0x00, 0x04, 0x10, 0x00, 25 0x00, 0x04, 0x10, 0x00,
26 0xbe, 0x30, 0x5b, 0xff, 26 0xbe, 0x30, 0x5b, 0xff,
27 0xfe, 0xe5, 0x00, 0xc3}}}; 27 0xfe, 0xe5, 0x00, 0xc3}}};
28 static const in6_addr kIPv6PublicAddr2 = {{{0x24, 0x01, 0x00, 0x00,
29 0x00, 0x00, 0x10, 0x00,
30 0xbe, 0x30, 0x5b, 0xff,
31 0xfe, 0xe5, 0x00, 0xc3}}};
28 static const in6_addr kIPv4MappedAnyAddr = {{{0x00, 0x00, 0x00, 0x00, 32 static const in6_addr kIPv4MappedAnyAddr = {{{0x00, 0x00, 0x00, 0x00,
29 0x00, 0x00, 0x00, 0x00, 33 0x00, 0x00, 0x00, 0x00,
30 0x00, 0x00, 0xff, 0xff, 34 0x00, 0x00, 0xff, 0xff,
31 0x00, 0x00, 0x00, 0x00}}}; 35 0x00, 0x00, 0x00, 0x00}}};
32 static const in6_addr kIPv4MappedRFC1918Addr = {{{0x00, 0x00, 0x00, 0x00, 36 static const in6_addr kIPv4MappedRFC1918Addr = {{{0x00, 0x00, 0x00, 0x00,
33 0x00, 0x00, 0x00, 0x00, 37 0x00, 0x00, 0x00, 0x00,
34 0x00, 0x00, 0xff, 0xff, 38 0x00, 0x00, 0xff, 0xff,
35 0xc0, 0xa8, 0x07, 0x01}}}; 39 0xc0, 0xa8, 0x07, 0x01}}};
36 static const in6_addr kIPv4MappedPublicAddr = {{{0x00, 0x00, 0x00, 0x00, 40 static const in6_addr kIPv4MappedPublicAddr = {{{0x00, 0x00, 0x00, 0x00,
37 0x00, 0x00, 0x00, 0x00, 41 0x00, 0x00, 0x00, 0x00,
38 0x00, 0x00, 0xff, 0xff, 42 0x00, 0x00, 0xff, 0xff,
39 0x01, 0x02, 0x03, 0x04}}}; 43 0x01, 0x02, 0x03, 0x04}}};
40 44
41 static const std::string kIPv4AnyAddrString = "0.0.0.0"; 45 static const std::string kIPv4AnyAddrString = "0.0.0.0";
42 static const std::string kIPv4LoopbackAddrString = "127.0.0.1"; 46 static const std::string kIPv4LoopbackAddrString = "127.0.0.1";
43 static const std::string kIPv4RFC1918AddrString = "192.168.7.1"; 47 static const std::string kIPv4RFC1918AddrString = "192.168.7.1";
44 static const std::string kIPv4PublicAddrString = "1.2.3.4"; 48 static const std::string kIPv4PublicAddrString = "1.2.3.4";
45 static const std::string kIPv4PublicAddrAnonymizedString = "1.2.3.x"; 49 static const std::string kIPv4PublicAddrAnonymizedString = "1.2.3.x";
46 static const std::string kIPv6AnyAddrString = "::"; 50 static const std::string kIPv6AnyAddrString = "::";
47 static const std::string kIPv6LoopbackAddrString = "::1"; 51 static const std::string kIPv6LoopbackAddrString = "::1";
48 static const std::string kIPv6LinkLocalAddrString = "fe80::be30:5bff:fee5:c3"; 52 static const std::string kIPv6LinkLocalAddrString = "fe80::be30:5bff:fee5:c3";
49 static const std::string kIPv6EuiAddrString = 53 static const std::string kIPv6EuiAddrString =
50 "2620:0:1008:1201:a248:1cff:fe98:360"; 54 "2620:0:1008:1201:a248:1cff:fe98:360";
51 static const std::string kIPv6TemporaryAddrString = 55 static const std::string kIPv6TemporaryAddrString =
52 "2620:0:1008:1201:2089:6dda:385e:80c0"; 56 "2620:0:1008:1201:2089:6dda:385e:80c0";
53 static const std::string kIPv6PublicAddrString = 57 static const std::string kIPv6PublicAddrString =
54 "2401:fa00:4:1000:be30:5bff:fee5:c3"; 58 "2401:fa00:4:1000:be30:5bff:fee5:c3";
55 static const std::string kIPv6PublicAddrAnonymizedString = "2401:fa00:4::"; 59 static const std::string kIPv6PublicAddr2String =
60 "2401::1000:be30:5bff:fee5:c3";
61 static const std::string kIPv6PublicAddrAnonymizedString =
62 "2401:fa00:4:x:x:x:x:x";
63 static const std::string kIPv6PublicAddr2AnonymizedString =
64 "2401::x:x:x:x:x";
56 static const std::string kIPv4MappedAnyAddrString = "::ffff:0:0"; 65 static const std::string kIPv4MappedAnyAddrString = "::ffff:0:0";
57 static const std::string kIPv4MappedRFC1918AddrString = "::ffff:c0a8:701"; 66 static const std::string kIPv4MappedRFC1918AddrString = "::ffff:c0a8:701";
58 static const std::string kIPv4MappedLoopbackAddrString = "::ffff:7f00:1"; 67 static const std::string kIPv4MappedLoopbackAddrString = "::ffff:7f00:1";
59 static const std::string kIPv4MappedPublicAddrString = "::ffff:102:0304"; 68 static const std::string kIPv4MappedPublicAddrString = "::ffff:102:0304";
60 static const std::string kIPv4MappedV4StyleAddrString = "::ffff:192.168.7.1"; 69 static const std::string kIPv4MappedV4StyleAddrString = "::ffff:192.168.7.1";
61 70
62 static const std::string kIPv4BrokenString1 = "192.168.7."; 71 static const std::string kIPv4BrokenString1 = "192.168.7.";
63 static const std::string kIPv4BrokenString2 = "192.168.7.1.1"; 72 static const std::string kIPv4BrokenString2 = "192.168.7.1.1";
64 static const std::string kIPv4BrokenString3 = "192.168.7.1:80"; 73 static const std::string kIPv4BrokenString3 = "192.168.7.1:80";
65 static const std::string kIPv4BrokenString4 = "192.168.7.ONE"; 74 static const std::string kIPv4BrokenString4 = "192.168.7.ONE";
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 EXPECT_FALSE(IPIs6Bone(teredo_addr)); 891 EXPECT_FALSE(IPIs6Bone(teredo_addr));
883 EXPECT_FALSE(IPIs6To4(teredo_addr)); 892 EXPECT_FALSE(IPIs6To4(teredo_addr));
884 EXPECT_FALSE(IPIsULA(teredo_addr)); 893 EXPECT_FALSE(IPIsULA(teredo_addr));
885 EXPECT_FALSE(IPIsV4Compatibility(teredo_addr)); 894 EXPECT_FALSE(IPIsV4Compatibility(teredo_addr));
886 EXPECT_FALSE(IPIsV4Mapped(teredo_addr)); 895 EXPECT_FALSE(IPIsV4Mapped(teredo_addr));
887 } 896 }
888 897
889 TEST(IPAddressTest, TestToSensitiveString) { 898 TEST(IPAddressTest, TestToSensitiveString) {
890 IPAddress addr_v4 = IPAddress(kIPv4PublicAddr); 899 IPAddress addr_v4 = IPAddress(kIPv4PublicAddr);
891 IPAddress addr_v6 = IPAddress(kIPv6PublicAddr); 900 IPAddress addr_v6 = IPAddress(kIPv6PublicAddr);
901 IPAddress addr_v6_2 = IPAddress(kIPv6PublicAddr2);
892 EXPECT_EQ(kIPv4PublicAddrString, addr_v4.ToString()); 902 EXPECT_EQ(kIPv4PublicAddrString, addr_v4.ToString());
893 EXPECT_EQ(kIPv6PublicAddrString, addr_v6.ToString()); 903 EXPECT_EQ(kIPv6PublicAddrString, addr_v6.ToString());
904 EXPECT_EQ(kIPv6PublicAddr2String, addr_v6_2.ToString());
894 #if defined(NDEBUG) 905 #if defined(NDEBUG)
895 EXPECT_EQ(kIPv4PublicAddrAnonymizedString, addr_v4.ToSensitiveString()); 906 EXPECT_EQ(kIPv4PublicAddrAnonymizedString, addr_v4.ToSensitiveString());
896 EXPECT_EQ(kIPv6PublicAddrAnonymizedString, addr_v6.ToSensitiveString()); 907 EXPECT_EQ(kIPv6PublicAddrAnonymizedString, addr_v6.ToSensitiveString());
908 EXPECT_EQ(kIPv6PublicAddr2AnonymizedString, addr_v6_2.ToSensitiveString());
897 #else 909 #else
898 EXPECT_EQ(kIPv4PublicAddrString, addr_v4.ToSensitiveString()); 910 EXPECT_EQ(kIPv4PublicAddrString, addr_v4.ToSensitiveString());
899 EXPECT_EQ(kIPv6PublicAddrString, addr_v6.ToSensitiveString()); 911 EXPECT_EQ(kIPv6PublicAddrString, addr_v6.ToSensitiveString());
912 EXPECT_EQ(kIPv6PublicAddr2String, addr_v6_2.ToSensitiveString());
900 #endif // defined(NDEBUG) 913 #endif // defined(NDEBUG)
901 } 914 }
902 915
903 TEST(IPAddressTest, TestInterfaceAddress) { 916 TEST(IPAddressTest, TestInterfaceAddress) {
904 in6_addr addr; 917 in6_addr addr;
905 InterfaceAddress addr1(kIPv6PublicAddr, 918 InterfaceAddress addr1(kIPv6PublicAddr,
906 IPV6_ADDRESS_FLAG_TEMPORARY); 919 IPV6_ADDRESS_FLAG_TEMPORARY);
907 EXPECT_EQ(addr1.ipv6_flags(), IPV6_ADDRESS_FLAG_TEMPORARY); 920 EXPECT_EQ(addr1.ipv6_flags(), IPV6_ADDRESS_FLAG_TEMPORARY);
908 EXPECT_EQ(addr1.family(), AF_INET6); 921 EXPECT_EQ(addr1.family(), AF_INET6);
909 922
(...skipping 21 matching lines...) Expand all
931 IPAddress *paddr1 = &addr1; 944 IPAddress *paddr1 = &addr1;
932 IPAddress *paddr4 = &addr4; 945 IPAddress *paddr4 = &addr4;
933 EXPECT_EQ(*paddr1, *paddr4); 946 EXPECT_EQ(*paddr1, *paddr4);
934 947
935 InterfaceAddress addr5(kIPv6LinkLocalAddr, 948 InterfaceAddress addr5(kIPv6LinkLocalAddr,
936 IPV6_ADDRESS_FLAG_TEMPORARY); 949 IPV6_ADDRESS_FLAG_TEMPORARY);
937 EXPECT_NE(addr1, addr5); 950 EXPECT_NE(addr1, addr5);
938 } 951 }
939 952
940 } // namespace rtc 953 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/ipaddress.cc ('k') | webrtc/base/socketaddress_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698