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

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

Issue 1823503002: Reland Use CopyOnWriteBuffer instead of Buffer to avoid unnecessary copies. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 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 unified diff | Download patch
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
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 EXPECT_EQ(0, memcmp(buf.data(), kTestData, 7)); 57 EXPECT_EQ(0, memcmp(buf.data(), kTestData, 7));
58 } 58 }
59 59
60 TEST(BufferTest, TestConstructArray) { 60 TEST(BufferTest, TestConstructArray) {
61 Buffer buf(kTestData); 61 Buffer buf(kTestData);
62 EXPECT_EQ(buf.size(), 16u); 62 EXPECT_EQ(buf.size(), 16u);
63 EXPECT_EQ(buf.capacity(), 16u); 63 EXPECT_EQ(buf.capacity(), 16u);
64 EXPECT_EQ(0, memcmp(buf.data(), kTestData, 16)); 64 EXPECT_EQ(0, memcmp(buf.data(), kTestData, 16));
65 } 65 }
66 66
67 TEST(BufferTest, TestConstructCopy) {
68 Buffer buf1(kTestData), buf2(buf1);
69 EXPECT_EQ(buf2.size(), 16u);
70 EXPECT_EQ(buf2.capacity(), 16u);
71 EXPECT_EQ(0, memcmp(buf2.data(), kTestData, 16));
72 EXPECT_NE(buf1.data(), buf2.data());
73 EXPECT_EQ(buf1, buf2);
74 }
75
76 TEST(BufferTest, TestAssign) {
77 Buffer buf1, buf2(kTestData, sizeof(kTestData), 256);
78 EXPECT_NE(buf1, buf2);
79 buf1 = buf2;
80 EXPECT_EQ(buf1, buf2);
81 EXPECT_NE(buf1.data(), buf2.data());
82 }
83
84 TEST(BufferTest, TestSetData) { 67 TEST(BufferTest, TestSetData) {
85 Buffer buf(kTestData + 4, 7); 68 Buffer buf(kTestData + 4, 7);
86 buf.SetData(kTestData, 9); 69 buf.SetData(kTestData, 9);
87 EXPECT_EQ(buf.size(), 9u); 70 EXPECT_EQ(buf.size(), 9u);
88 EXPECT_EQ(buf.capacity(), 9u); 71 EXPECT_EQ(buf.capacity(), 9u);
89 EXPECT_EQ(0, memcmp(buf.data(), kTestData, 9)); 72 EXPECT_EQ(0, memcmp(buf.data(), kTestData, 9));
90 } 73 }
91 74
92 TEST(BufferTest, TestAppendData) { 75 TEST(BufferTest, TestAppendData) {
93 Buffer buf(kTestData + 4, 3); 76 Buffer buf(kTestData + 4, 3);
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 for (size_t i = 0; i != 7u; ++i) { 295 for (size_t i = 0; i != 7u; ++i) {
313 buf[i] = kTestData[i]; 296 buf[i] = kTestData[i];
314 } 297 }
315 298
316 for (size_t i = 0; i != 7u; ++i) { 299 for (size_t i = 0; i != 7u; ++i) {
317 EXPECT_EQ(buf[i], kTestData[i]); 300 EXPECT_EQ(buf[i], kTestData[i]);
318 } 301 }
319 } 302 }
320 303
321 } // namespace rtc 304 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698