Fix issue 4061.

Issue was that the longest 0 detection wasn't done when there is only one 0 octet. The purpose of this detection is to make sure we don't also compression 0 octet sequences which are not longest.

BUG=4061
R=juberti@webrtc.org, pthatcher@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/33309004

Cr-Commit-Position: refs/heads/master@{#8397}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8397 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
guoweis@webrtc.org
2015-02-17 19:00:42 +00:00
parent 0abc6011b9
commit b08f4045ec
2 changed files with 36 additions and 3 deletions

View File

@ -59,4 +59,37 @@ TEST_F(Win32Test, WinPingTest) {
IPAddress(INADDR_LOOPBACK), 20, 50, 0, false));
}
TEST_F(Win32Test, IPv6AddressCompression) {
IPAddress ipv6;
// Zero compression should be done on the leftmost 0s when there are
// multiple longest series.
ASSERT_TRUE(IPFromString("2a00:8a00:a000:1190:0000:0001:000:252", &ipv6));
EXPECT_EQ("2a00:8a00:a000:1190::1:0:252", ipv6.ToString());
// Ensure the zero compression could handle multiple octects.
ASSERT_TRUE(IPFromString("0:0:0:0:0:0:0:1", &ipv6));
EXPECT_EQ("::1", ipv6.ToString());
// Make sure multiple 0 octects compressed.
ASSERT_TRUE(IPFromString("fe80:0:0:0:2aa:ff:fe9a:4ca2", &ipv6));
EXPECT_EQ("fe80::2aa:ff:fe9a:4ca2", ipv6.ToString());
// Test zero compression at the end of string.
ASSERT_TRUE(IPFromString("2a00:8a00:a000:1190:0000:0001:000:00", &ipv6));
EXPECT_EQ("2a00:8a00:a000:1190:0:1::", ipv6.ToString());
// Test zero compression at the beginning of string.
ASSERT_TRUE(IPFromString("0:0:000:1190:0000:0001:000:00", &ipv6));
EXPECT_EQ("::1190:0:1:0:0", ipv6.ToString());
// Test zero compression only done once.
ASSERT_TRUE(IPFromString("0:1:000:1190:0000:0001:000:01", &ipv6));
EXPECT_EQ("::1:0:1190:0:1:0:1", ipv6.ToString());
// Make sure noncompressable IPv6 is the same.
ASSERT_TRUE(IPFromString("1234:5678:abcd:1234:5678:abcd:1234:5678", &ipv6));
EXPECT_EQ("1234:5678:abcd:1234:5678:abcd:1234:5678", ipv6.ToString());
}
} // namespace rtc