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

Unified Diff: webrtc/base/copyonwritebuffer_unittest.cc

Issue 2328553002: Make CopyOnWriteBuffer keep capacity (Closed)
Patch Set: Created 4 years, 3 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
« webrtc/base/copyonwritebuffer.h ('K') | « webrtc/base/copyonwritebuffer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/copyonwritebuffer_unittest.cc
diff --git a/webrtc/base/copyonwritebuffer_unittest.cc b/webrtc/base/copyonwritebuffer_unittest.cc
index dbf59f7718f2779f0dff9bc0c3c26d79918a00c5..93070ef47fc7407deeac75d4d8c8385951f9c37f 100644
--- a/webrtc/base/copyonwritebuffer_unittest.cc
+++ b/webrtc/base/copyonwritebuffer_unittest.cc
@@ -149,6 +149,47 @@ TEST(CopyOnWriteBufferTest, TestSetDataEmpty) {
EXPECT_EQ(buf.data(), nullptr);
}
+TEST(CopyOnWriteBufferTest, SetDataSmallerCapacityCauseNoReallocation) {
kwiberg-webrtc 2016/09/09 08:55:14 "Causes". Or even better, "DoesntCause"
danilchap 2016/09/09 11:21:17 Done.
+ CopyOnWriteBuffer buf1(kTestData, 3, 10);
+ const uint8_t* raw = buf1.cdata();
kwiberg-webrtc 2016/09/09 08:55:14 You can make the pointer const too.
danilchap 2016/09/09 11:21:17 Done.
+
+ buf1.SetData(kTestData, 2, 5);
+
+ EXPECT_EQ(2U, buf1.size());
kwiberg-webrtc 2016/09/09 08:55:13 Lower-case "u".
danilchap 2016/09/09 11:21:17 for local consistency, Done. but globally prefer u
kwiberg-webrtc 2016/09/09 12:59:14 OK.
+ EXPECT_LE(5U, buf1.capacity());
+ EXPECT_EQ(raw, buf1.cdata());
+}
+
+TEST(CopyOnWriteBufferTest, SetDataSmallerCapacityOnShared) {
+ CopyOnWriteBuffer buf1(kTestData, 3, 10);
+ CopyOnWriteBuffer buf2(buf1);
+ EnsureBuffersShareData(buf1, buf2);
+
+ buf2.SetData(kTestData, 2, 5);
+
+ EnsureBuffersDontShareData(buf1, buf2);
+ EXPECT_EQ(2U, buf2.size());
+ EXPECT_LE(5U, buf2.capacity());
+}
+
+TEST(CopyOnWriteBufferTest, SetDataLargerCapacity) {
+ CopyOnWriteBuffer buf1(kTestData, 3, 10);
+
+ buf1.SetData(kTestData, 2, 15);
+
+ EXPECT_EQ(2U, buf1.size());
+ EXPECT_LE(15U, buf1.capacity());
+}
+
+TEST(CopyOnWriteBufferTest, SetDataOnEmpty) {
+ CopyOnWriteBuffer buf1;
+
+ buf1.SetData(kTestData, 2, 15);
+
+ EXPECT_EQ(2U, buf1.size());
+ EXPECT_LE(15U, buf1.capacity());
+}
kwiberg-webrtc 2016/09/09 08:55:13 In order to put the more fundamental tests first,
danilchap 2016/09/09 11:21:17 Done. Reordered 4312.
+
TEST(CopyOnWriteBufferTest, TestEnsureCapacity) {
CopyOnWriteBuffer buf1(kTestData, 3, 10);
CopyOnWriteBuffer buf2(buf1);
« webrtc/base/copyonwritebuffer.h ('K') | « webrtc/base/copyonwritebuffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698