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

Unified Diff: webrtc/p2p/base/stun_unittest.cc

Issue 2757893003: Add MakeUnique from chromium and change StunMessage::AddAttribute to take a unique_ptr. (Closed)
Patch Set: add ptr_util.h to rtc_base_approved build target Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/p2p/base/stun.cc ('k') | webrtc/p2p/base/stunrequest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/stun_unittest.cc
diff --git a/webrtc/p2p/base/stun_unittest.cc b/webrtc/p2p/base/stun_unittest.cc
index f12fa82cde5583c18ffa591735d9029469a5cba2..efc11b240874f137918945baebcf84cdf72d916a 100644
--- a/webrtc/p2p/base/stun_unittest.cc
+++ b/webrtc/p2p/base/stun_unittest.cc
@@ -10,13 +10,14 @@
#include <string>
-#include "webrtc/p2p/base/stun.h"
#include "webrtc/base/arraysize.h"
#include "webrtc/base/bytebuffer.h"
#include "webrtc/base/gunit.h"
#include "webrtc/base/logging.h"
#include "webrtc/base/messagedigest.h"
+#include "webrtc/base/ptr_util.h"
#include "webrtc/base/socketaddress.h"
+#include "webrtc/p2p/base/stun.h"
namespace cricket {
@@ -822,14 +823,12 @@ TEST_F(StunTest, SetIPv4XorAddressAttributeOwner) {
TEST_F(StunTest, CreateIPv6AddressAttribute) {
rtc::IPAddress test_ip(kIPv6TestAddress2);
- StunAddressAttribute* addr =
- StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS);
+ auto addr = StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS);
rtc::SocketAddress test_addr(test_ip, kTestMessagePort2);
addr->SetAddress(test_addr);
- CheckStunAddressAttribute(addr, STUN_ADDRESS_IPV6,
- kTestMessagePort2, test_ip);
- delete addr;
+ CheckStunAddressAttribute(addr.get(), STUN_ADDRESS_IPV6, kTestMessagePort2,
+ test_ip);
}
TEST_F(StunTest, CreateIPv4AddressAttribute) {
@@ -837,36 +836,29 @@ TEST_F(StunTest, CreateIPv4AddressAttribute) {
test_in_addr.s_addr = 0xBEB0B0BE;
rtc::IPAddress test_ip(test_in_addr);
- StunAddressAttribute* addr =
- StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS);
+ auto addr = StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS);
rtc::SocketAddress test_addr(test_ip, kTestMessagePort2);
addr->SetAddress(test_addr);
- CheckStunAddressAttribute(addr, STUN_ADDRESS_IPV4,
- kTestMessagePort2, test_ip);
- delete addr;
+ CheckStunAddressAttribute(addr.get(), STUN_ADDRESS_IPV4, kTestMessagePort2,
+ test_ip);
}
// Test that we don't care what order we set the parts of an address
TEST_F(StunTest, CreateAddressInArbitraryOrder) {
- StunAddressAttribute* addr =
- StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS);
+ auto addr = StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS);
// Port first
addr->SetPort(kTestMessagePort1);
addr->SetIP(rtc::IPAddress(kIPv4TestAddress1));
ASSERT_EQ(kTestMessagePort1, addr->port());
ASSERT_EQ(rtc::IPAddress(kIPv4TestAddress1), addr->ipaddr());
- StunAddressAttribute* addr2 =
- StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS);
+ auto addr2 = StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS);
// IP first
addr2->SetIP(rtc::IPAddress(kIPv4TestAddress1));
addr2->SetPort(kTestMessagePort2);
ASSERT_EQ(kTestMessagePort2, addr2->port());
ASSERT_EQ(rtc::IPAddress(kIPv4TestAddress1), addr2->ipaddr());
-
- delete addr;
- delete addr2;
}
TEST_F(StunTest, WriteMessageWithIPv6AddressAttribute) {
@@ -881,11 +873,10 @@ TEST_F(StunTest, WriteMessageWithIPv6AddressAttribute) {
kStunTransactionIdLength));
CheckStunTransactionID(msg, kTestTransactionId1, kStunTransactionIdLength);
- StunAddressAttribute* addr =
- StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS);
+ auto addr = StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS);
rtc::SocketAddress test_addr(test_ip, kTestMessagePort2);
addr->SetAddress(test_addr);
- msg.AddAttribute(addr);
+ msg.AddAttribute(std::move(addr));
CheckStunHeader(msg, STUN_BINDING_REQUEST, (size - 20));
@@ -911,11 +902,10 @@ TEST_F(StunTest, WriteMessageWithIPv4AddressAttribute) {
kStunTransactionIdLength));
CheckStunTransactionID(msg, kTestTransactionId1, kStunTransactionIdLength);
- StunAddressAttribute* addr =
- StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS);
+ auto addr = StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS);
rtc::SocketAddress test_addr(test_ip, kTestMessagePort4);
addr->SetAddress(test_addr);
- msg.AddAttribute(addr);
+ msg.AddAttribute(std::move(addr));
CheckStunHeader(msg, STUN_BINDING_RESPONSE, (size - 20));
@@ -941,11 +931,10 @@ TEST_F(StunTest, WriteMessageWithIPv6XorAddressAttribute) {
kStunTransactionIdLength));
CheckStunTransactionID(msg, kTestTransactionId2, kStunTransactionIdLength);
- StunAddressAttribute* addr =
- StunAttribute::CreateXorAddress(STUN_ATTR_XOR_MAPPED_ADDRESS);
+ auto addr = StunAttribute::CreateXorAddress(STUN_ATTR_XOR_MAPPED_ADDRESS);
rtc::SocketAddress test_addr(test_ip, kTestMessagePort1);
addr->SetAddress(test_addr);
- msg.AddAttribute(addr);
+ msg.AddAttribute(std::move(addr));
CheckStunHeader(msg, STUN_BINDING_RESPONSE, (size - 20));
@@ -972,11 +961,10 @@ TEST_F(StunTest, WriteMessageWithIPv4XoreAddressAttribute) {
kStunTransactionIdLength));
CheckStunTransactionID(msg, kTestTransactionId1, kStunTransactionIdLength);
- StunAddressAttribute* addr =
- StunAttribute::CreateXorAddress(STUN_ATTR_XOR_MAPPED_ADDRESS);
+ auto addr = StunAttribute::CreateXorAddress(STUN_ATTR_XOR_MAPPED_ADDRESS);
rtc::SocketAddress test_addr(test_ip, kTestMessagePort3);
addr->SetAddress(test_addr);
- msg.AddAttribute(addr);
+ msg.AddAttribute(std::move(addr));
CheckStunHeader(msg, STUN_BINDING_RESPONSE, (size - 20));
@@ -1073,10 +1061,10 @@ TEST_F(StunTest, WriteMessageWithAnErrorCodeAttribute) {
std::string(reinterpret_cast<const char*>(kTestTransactionId1),
kStunTransactionIdLength));
CheckStunTransactionID(msg, kTestTransactionId1, kStunTransactionIdLength);
- StunErrorCodeAttribute* errorcode = StunAttribute::CreateErrorCode();
+ auto errorcode = StunAttribute::CreateErrorCode();
errorcode->SetCode(kTestErrorCode);
errorcode->SetReason(kTestErrorReason);
- msg.AddAttribute(errorcode);
+ msg.AddAttribute(std::move(errorcode));
CheckStunHeader(msg, STUN_BINDING_ERROR_RESPONSE, (size - 20));
rtc::ByteBufferWriter out;
@@ -1095,11 +1083,11 @@ TEST_F(StunTest, WriteMessageWithAUInt16ListAttribute) {
std::string(reinterpret_cast<const char*>(kTestTransactionId2),
kStunTransactionIdLength));
CheckStunTransactionID(msg, kTestTransactionId2, kStunTransactionIdLength);
- StunUInt16ListAttribute* list = StunAttribute::CreateUnknownAttributes();
+ auto list = StunAttribute::CreateUnknownAttributes();
list->AddType(0x1U);
list->AddType(0x1000U);
list->AddType(0xAB0CU);
- msg.AddAttribute(list);
+ msg.AddAttribute(std::move(list));
CheckStunHeader(msg, STUN_BINDING_REQUEST, (size - 20));
rtc::ByteBufferWriter out;
@@ -1118,9 +1106,9 @@ TEST_F(StunTest, WriteMessageWithOriginAttribute) {
msg.SetTransactionID(
std::string(reinterpret_cast<const char*>(kTestTransactionId1),
kStunTransactionIdLength));
- StunByteStringAttribute* origin =
- new StunByteStringAttribute(STUN_ATTR_ORIGIN, kTestOrigin);
- msg.AddAttribute(origin);
+ auto origin =
+ rtc::MakeUnique<StunByteStringAttribute>(STUN_ATTR_ORIGIN, kTestOrigin);
+ msg.AddAttribute(std::move(origin));
rtc::ByteBufferWriter out;
EXPECT_TRUE(msg.Write(&out));
@@ -1389,29 +1377,27 @@ TEST_F(StunTest, ReadRelayMessage) {
EXPECT_EQ(13, addr->port());
EXPECT_EQ(legacy_ip, addr->ipaddr());
- StunAddressAttribute* addr2 =
- StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS);
+ auto addr2 = StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS);
addr2->SetPort(13);
addr2->SetIP(legacy_ip);
- msg2.AddAttribute(addr2);
+ msg2.AddAttribute(std::move(addr2));
const StunByteStringAttribute* bytes = msg.GetByteString(STUN_ATTR_USERNAME);
ASSERT_TRUE(bytes != NULL);
EXPECT_EQ(12U, bytes->length());
EXPECT_EQ("abcdefghijkl", bytes->GetString());
- StunByteStringAttribute* bytes2 =
- StunAttribute::CreateByteString(STUN_ATTR_USERNAME);
+ auto bytes2 = StunAttribute::CreateByteString(STUN_ATTR_USERNAME);
bytes2->CopyBytes("abcdefghijkl");
- msg2.AddAttribute(bytes2);
+ msg2.AddAttribute(std::move(bytes2));
const StunUInt32Attribute* uval = msg.GetUInt32(STUN_ATTR_LIFETIME);
ASSERT_TRUE(uval != NULL);
EXPECT_EQ(11U, uval->value());
- StunUInt32Attribute* uval2 = StunAttribute::CreateUInt32(STUN_ATTR_LIFETIME);
+ auto uval2 = StunAttribute::CreateUInt32(STUN_ATTR_LIFETIME);
uval2->SetValue(11);
- msg2.AddAttribute(uval2);
+ msg2.AddAttribute(std::move(uval2));
bytes = msg.GetByteString(STUN_ATTR_MAGIC_COOKIE);
ASSERT_TRUE(bytes != NULL);
@@ -1424,7 +1410,7 @@ TEST_F(StunTest, ReadRelayMessage) {
bytes2 = StunAttribute::CreateByteString(STUN_ATTR_MAGIC_COOKIE);
bytes2->CopyBytes(reinterpret_cast<const char*>(TURN_MAGIC_COOKIE_VALUE),
sizeof(TURN_MAGIC_COOKIE_VALUE));
- msg2.AddAttribute(bytes2);
+ msg2.AddAttribute(std::move(bytes2));
uval = msg.GetUInt32(STUN_ATTR_BANDWIDTH);
ASSERT_TRUE(uval != NULL);
@@ -1432,7 +1418,7 @@ TEST_F(StunTest, ReadRelayMessage) {
uval2 = StunAttribute::CreateUInt32(STUN_ATTR_BANDWIDTH);
uval2->SetValue(6);
- msg2.AddAttribute(uval2);
+ msg2.AddAttribute(std::move(uval2));
addr = msg.GetAddress(STUN_ATTR_DESTINATION_ADDRESS);
ASSERT_TRUE(addr != NULL);
@@ -1443,7 +1429,7 @@ TEST_F(StunTest, ReadRelayMessage) {
addr2 = StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS);
addr2->SetPort(13);
addr2->SetIP(legacy_ip);
- msg2.AddAttribute(addr2);
+ msg2.AddAttribute(std::move(addr2));
addr = msg.GetAddress(STUN_ATTR_SOURCE_ADDRESS2);
ASSERT_TRUE(addr != NULL);
@@ -1454,7 +1440,7 @@ TEST_F(StunTest, ReadRelayMessage) {
addr2 = StunAttribute::CreateAddress(STUN_ATTR_SOURCE_ADDRESS2);
addr2->SetPort(13);
addr2->SetIP(legacy_ip);
- msg2.AddAttribute(addr2);
+ msg2.AddAttribute(std::move(addr2));
bytes = msg.GetByteString(STUN_ATTR_DATA);
ASSERT_TRUE(bytes != NULL);
@@ -1463,7 +1449,7 @@ TEST_F(StunTest, ReadRelayMessage) {
bytes2 = StunAttribute::CreateByteString(STUN_ATTR_DATA);
bytes2->CopyBytes("abcdefg");
- msg2.AddAttribute(bytes2);
+ msg2.AddAttribute(std::move(bytes2));
rtc::ByteBufferWriter out;
EXPECT_TRUE(msg.Write(&out));
« no previous file with comments | « webrtc/p2p/base/stun.cc ('k') | webrtc/p2p/base/stunrequest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698