summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/libjingle/source/talk/p2p/base/stun_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/libjingle/source/talk/p2p/base/stun_unittest.cc')
-rw-r--r--chromium/third_party/libjingle/source/talk/p2p/base/stun_unittest.cc99
1 files changed, 25 insertions, 74 deletions
diff --git a/chromium/third_party/libjingle/source/talk/p2p/base/stun_unittest.cc b/chromium/third_party/libjingle/source/talk/p2p/base/stun_unittest.cc
index 6a5bcd9bbb9..71d87500e99 100644
--- a/chromium/third_party/libjingle/source/talk/p2p/base/stun_unittest.cc
+++ b/chromium/third_party/libjingle/source/talk/p2p/base/stun_unittest.cc
@@ -50,8 +50,7 @@ class StunTest : public ::testing::Test {
ASSERT_EQ(length, msg.transaction_id().size());
ASSERT_EQ(length == kStunTransactionIdLength + 4, msg.IsLegacy());
ASSERT_EQ(length == kStunTransactionIdLength, !msg.IsLegacy());
- ASSERT_EQ(0, std::memcmp(msg.transaction_id().c_str(),
- expectedID, length));
+ ASSERT_EQ(0, memcmp(msg.transaction_id().c_str(), expectedID, length));
}
void CheckStunAddressAttribute(const StunAddressAttribute* addr,
@@ -64,13 +63,11 @@ class StunTest : public ::testing::Test {
if (addr->family() == STUN_ADDRESS_IPV4) {
in_addr v4_address = expected_address.ipv4_address();
in_addr stun_address = addr->ipaddr().ipv4_address();
- ASSERT_EQ(0, std::memcmp(&v4_address, &stun_address,
- sizeof(stun_address)));
+ ASSERT_EQ(0, memcmp(&v4_address, &stun_address, sizeof(stun_address)));
} else if (addr->family() == STUN_ADDRESS_IPV6) {
in6_addr v6_address = expected_address.ipv6_address();
in6_addr stun_address = addr->ipaddr().ipv6_address();
- ASSERT_EQ(0, std::memcmp(&v6_address, &stun_address,
- sizeof(stun_address)));
+ ASSERT_EQ(0, memcmp(&v6_address, &stun_address, sizeof(stun_address)));
} else {
ASSERT_TRUE(addr->family() == STUN_ADDRESS_IPV6 ||
addr->family() == STUN_ADDRESS_IPV4);
@@ -211,37 +208,6 @@ static const unsigned char kStunMessageWithErrorAttribute[] = {
0x69, 0x7a, 0x65, 0x64
};
-// Message with an address attribute with an unknown address family,
-// and a byte string attribute. Check that we quit reading after the
-// bogus address family and don't read the username attribute.
-static const unsigned char kStunMessageWithInvalidAddressFamily[] = {
- 0x01, 0x01, 0x00, 0x18, // binding response, length 24
- 0x21, 0x12, 0xa4, 0x42, // magic cookie
- 0x29, 0x1f, 0xcd, 0x7c, // transaction ID
- 0xba, 0x58, 0xab, 0xd7,
- 0xf2, 0x41, 0x01, 0x00,
- 0x00, 0x01, 0x00, 0x08, // Mapped address, 4 byte length
- 0x00, 0x09, 0xfe, 0xed, // Bogus address family (port unimportant).
- 0xac, 0x17, 0x44, 0xe6, // Should be skipped.
- 0x00, 0x06, 0x00, 0x08, // Username attribute (length 8)
- 0x61, 0x62, 0x63, 0x64, // abcdefgh
- 0x65, 0x66, 0x67, 0x68
-};
-
-// Message with an address attribute with an invalid address length.
-// Should fail to be read.
-static const unsigned char kStunMessageWithInvalidAddressLength[] = {
- 0x01, 0x01, 0x00, 0x18, // binding response, length 24
- 0x21, 0x12, 0xa4, 0x42, // magic cookie
- 0x29, 0x1f, 0xcd, 0x7c, // transaction ID
- 0xba, 0x58, 0xab, 0xd7,
- 0xf2, 0x41, 0x01, 0x00,
- 0x00, 0x01, 0x00, 0x0c, // Mapped address, 12 byte length
- 0x00, 0x01, 0xfe, 0xed, // Claims to be AF_INET.
- 0xac, 0x17, 0x44, 0xe6,
- 0x00, 0x06, 0x00, 0x08
-};
-
// Sample messages with an invalid length Field
// The actual length in bytes of the invalid messages (including STUN header)
@@ -514,19 +480,10 @@ const in6_addr kIPv6TestAddress2 = { { { 0x24, 0x01, 0xfa, 0x00,
0x06, 0x0c, 0xce, 0xff,
0xfe, 0x1f, 0x61, 0xa4 } } };
-// This is kIPv6TestAddress1 xor-ed with kTestTransactionID2.
-const in6_addr kIPv6XoredTestAddress = { { { 0x05, 0x13, 0x5e, 0x42,
- 0xe3, 0xad, 0x56, 0xe1,
- 0xc2, 0x30, 0x99, 0x9d,
- 0xaa, 0xed, 0x01, 0xc3 } } };
-
#ifdef POSIX
const in_addr kIPv4TestAddress1 = { 0xe64417ac };
-// This is kIPv4TestAddress xored with the STUN magic cookie.
-const in_addr kIPv4XoredTestAddress = { 0x8d05e0a4 };
#elif defined WIN32
// Windows in_addr has a union with a uchar[] array first.
-const in_addr kIPv4XoredTestAddress = { { 0x8d, 0x05, 0xe0, 0xa4 } };
const in_addr kIPv4TestAddress1 = { { 0x0ac, 0x017, 0x044, 0x0e6 } };
#endif
const char kTestUserName1[] = "abcdefgh";
@@ -788,9 +745,8 @@ TEST_F(StunTest, SetIPv6XorAddressAttributeOwner) {
EXPECT_TRUE(addr->Write(&correct_buf));
EXPECT_TRUE(addr2.Write(&wrong_buf));
// But when written out, the buffers should look different.
- ASSERT_NE(0, std::memcmp(correct_buf.Data(),
- wrong_buf.Data(),
- wrong_buf.Length()));
+ ASSERT_NE(0,
+ memcmp(correct_buf.Data(), wrong_buf.Data(), wrong_buf.Length()));
// And when reading a known good value, the address should be wrong.
addr2.Read(&correct_buf);
ASSERT_NE(addr->ipaddr(), addr2.ipaddr());
@@ -836,9 +792,8 @@ TEST_F(StunTest, SetIPv4XorAddressAttributeOwner) {
EXPECT_TRUE(addr->Write(&correct_buf));
EXPECT_TRUE(addr2.Write(&wrong_buf));
// The same address data should be written.
- ASSERT_EQ(0, std::memcmp(correct_buf.Data(),
- wrong_buf.Data(),
- wrong_buf.Length()));
+ ASSERT_EQ(0,
+ memcmp(correct_buf.Data(), wrong_buf.Data(), wrong_buf.Length()));
// And an attribute should be able to un-XOR an address belonging to a message
// with a different transaction ID.
EXPECT_TRUE(addr2.Read(&correct_buf));
@@ -927,9 +882,7 @@ TEST_F(StunTest, WriteMessageWithIPv6AddressAttribute) {
int len1 = static_cast<int>(out.Length());
std::string bytes;
out.ReadString(&bytes, len1);
- ASSERT_EQ(0, std::memcmp(bytes.c_str(),
- kStunMessageWithIPv6MappedAddress,
- len1));
+ ASSERT_EQ(0, memcmp(bytes.c_str(), kStunMessageWithIPv6MappedAddress, len1));
}
TEST_F(StunTest, WriteMessageWithIPv4AddressAttribute) {
@@ -958,9 +911,7 @@ TEST_F(StunTest, WriteMessageWithIPv4AddressAttribute) {
int len1 = static_cast<int>(out.Length());
std::string bytes;
out.ReadString(&bytes, len1);
- ASSERT_EQ(0, std::memcmp(bytes.c_str(),
- kStunMessageWithIPv4MappedAddress,
- len1));
+ ASSERT_EQ(0, memcmp(bytes.c_str(), kStunMessageWithIPv4MappedAddress, len1));
}
TEST_F(StunTest, WriteMessageWithIPv6XorAddressAttribute) {
@@ -989,9 +940,8 @@ TEST_F(StunTest, WriteMessageWithIPv6XorAddressAttribute) {
int len1 = static_cast<int>(out.Length());
std::string bytes;
out.ReadString(&bytes, len1);
- ASSERT_EQ(0, std::memcmp(bytes.c_str(),
- kStunMessageWithIPv6XorMappedAddress,
- len1));
+ ASSERT_EQ(0,
+ memcmp(bytes.c_str(), kStunMessageWithIPv6XorMappedAddress, len1));
}
TEST_F(StunTest, WriteMessageWithIPv4XoreAddressAttribute) {
@@ -1020,9 +970,8 @@ TEST_F(StunTest, WriteMessageWithIPv4XoreAddressAttribute) {
int len1 = static_cast<int>(out.Length());
std::string bytes;
out.ReadString(&bytes, len1);
- ASSERT_EQ(0, std::memcmp(bytes.c_str(),
- kStunMessageWithIPv4XorMappedAddress,
- len1));
+ ASSERT_EQ(0,
+ memcmp(bytes.c_str(), kStunMessageWithIPv4XorMappedAddress, len1));
}
TEST_F(StunTest, ReadByteStringAttribute) {
@@ -1107,7 +1056,7 @@ TEST_F(StunTest, WriteMessageWithAnErrorCodeAttribute) {
EXPECT_TRUE(msg.Write(&out));
ASSERT_EQ(size, out.Length());
// No padding.
- ASSERT_EQ(0, std::memcmp(out.Data(), kStunMessageWithErrorAttribute, size));
+ ASSERT_EQ(0, memcmp(out.Data(), kStunMessageWithErrorAttribute, size));
}
TEST_F(StunTest, WriteMessageWithAUInt16ListAttribute) {
@@ -1130,8 +1079,8 @@ TEST_F(StunTest, WriteMessageWithAUInt16ListAttribute) {
EXPECT_TRUE(msg.Write(&out));
ASSERT_EQ(size, out.Length());
// Check everything up to the padding.
- ASSERT_EQ(0, std::memcmp(out.Data(), kStunMessageWithUInt16ListAttribute,
- size - 2));
+ ASSERT_EQ(0,
+ memcmp(out.Data(), kStunMessageWithUInt16ListAttribute, size - 2));
}
// Test that we fail to read messages with invalid lengths.
@@ -1238,7 +1187,7 @@ TEST_F(StunTest, AddMessageIntegrity) {
const StunByteStringAttribute* mi_attr =
msg.GetByteString(STUN_ATTR_MESSAGE_INTEGRITY);
EXPECT_EQ(20U, mi_attr->length());
- EXPECT_EQ(0, std::memcmp(
+ EXPECT_EQ(0, memcmp(
mi_attr->bytes(), kCalculatedHmac1, sizeof(kCalculatedHmac1)));
talk_base::ByteBuffer buf1;
@@ -1256,8 +1205,8 @@ TEST_F(StunTest, AddMessageIntegrity) {
const StunByteStringAttribute* mi_attr2 =
msg2.GetByteString(STUN_ATTR_MESSAGE_INTEGRITY);
EXPECT_EQ(20U, mi_attr2->length());
- EXPECT_EQ(0, std::memcmp(
- mi_attr2->bytes(), kCalculatedHmac2, sizeof(kCalculatedHmac2)));
+ EXPECT_EQ(
+ 0, memcmp(mi_attr2->bytes(), kCalculatedHmac2, sizeof(kCalculatedHmac2)));
talk_base::ByteBuffer buf3;
EXPECT_TRUE(msg2.Write(&buf3));
@@ -1401,8 +1350,10 @@ TEST_F(StunTest, ReadRelayMessage) {
bytes = msg.GetByteString(STUN_ATTR_MAGIC_COOKIE);
ASSERT_TRUE(bytes != NULL);
EXPECT_EQ(4U, bytes->length());
- EXPECT_EQ(0, std::memcmp(bytes->bytes(), TURN_MAGIC_COOKIE_VALUE,
- sizeof(TURN_MAGIC_COOKIE_VALUE)));
+ EXPECT_EQ(0,
+ memcmp(bytes->bytes(),
+ TURN_MAGIC_COOKIE_VALUE,
+ sizeof(TURN_MAGIC_COOKIE_VALUE)));
bytes2 = StunAttribute::CreateByteString(STUN_ATTR_MAGIC_COOKIE);
bytes2->CopyBytes(reinterpret_cast<const char*>(TURN_MAGIC_COOKIE_VALUE),
@@ -1454,7 +1405,7 @@ TEST_F(StunTest, ReadRelayMessage) {
size_t len1 = out.Length();
std::string outstring;
out.ReadString(&outstring, len1);
- EXPECT_EQ(0, std::memcmp(outstring.c_str(), input, len1));
+ EXPECT_EQ(0, memcmp(outstring.c_str(), input, len1));
talk_base::ByteBuffer out2;
EXPECT_TRUE(msg2.Write(&out2));
@@ -1462,7 +1413,7 @@ TEST_F(StunTest, ReadRelayMessage) {
size_t len2 = out2.Length();
std::string outstring2;
out2.ReadString(&outstring2, len2);
- EXPECT_EQ(0, std::memcmp(outstring2.c_str(), input, len2));
+ EXPECT_EQ(0, memcmp(outstring2.c_str(), input, len2));
}
} // namespace cricket