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

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

Issue 2293983002: rtc::Buffer: Let SetData and AppendData accept anything with .data() and .size() (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 unified diff | Download patch
« webrtc/base/buffer.h ('K') | « webrtc/base/buffer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "webrtc/base/buffer.h" 11 #include "webrtc/base/buffer.h"
12
13 #include "webrtc/base/array_view.h"
12 #include "webrtc/base/gunit.h" 14 #include "webrtc/base/gunit.h"
13 15
14 #include <type_traits> 16 #include <type_traits>
15 #include <utility> 17 #include <utility>
16 18
17 namespace rtc { 19 namespace rtc {
18 20
19 namespace { 21 namespace {
20 22
21 // clang-format off 23 // clang-format off
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 EXPECT_EQ(buf.capacity(), 16u); 65 EXPECT_EQ(buf.capacity(), 16u);
64 EXPECT_EQ(0, memcmp(buf.data(), kTestData, 16)); 66 EXPECT_EQ(0, memcmp(buf.data(), kTestData, 16));
65 } 67 }
66 68
67 TEST(BufferTest, TestSetData) { 69 TEST(BufferTest, TestSetData) {
68 Buffer buf(kTestData + 4, 7); 70 Buffer buf(kTestData + 4, 7);
69 buf.SetData(kTestData, 9); 71 buf.SetData(kTestData, 9);
70 EXPECT_EQ(buf.size(), 9u); 72 EXPECT_EQ(buf.size(), 9u);
71 EXPECT_EQ(buf.capacity(), 7u * 3 / 2); 73 EXPECT_EQ(buf.capacity(), 7u * 3 / 2);
72 EXPECT_EQ(0, memcmp(buf.data(), kTestData, 9)); 74 EXPECT_EQ(0, memcmp(buf.data(), kTestData, 9));
75 Buffer buf2;
ossu 2016/08/31 09:31:03 Do you want to test this with an unrelated class a
kwiberg-webrtc 2016/09/01 09:23:53 Done.
76 buf2.SetData(buf);
77 EXPECT_EQ(buf.size(), 9u);
78 EXPECT_EQ(buf.capacity(), 7u * 3 / 2);
79 EXPECT_EQ(0, memcmp(buf.data(), kTestData, 9));
73 } 80 }
74 81
75 TEST(BufferTest, TestAppendData) { 82 TEST(BufferTest, TestAppendData) {
76 Buffer buf(kTestData + 4, 3); 83 Buffer buf(kTestData + 4, 3);
77 buf.AppendData(kTestData + 10, 2); 84 buf.AppendData(kTestData + 10, 2);
78 const int8_t exp[] = {0x4, 0x5, 0x6, 0xa, 0xb}; 85 const int8_t exp[] = {0x4, 0x5, 0x6, 0xa, 0xb};
79 EXPECT_EQ(buf, Buffer(exp)); 86 EXPECT_EQ(buf, Buffer(exp));
87 Buffer buf2;
88 buf2.AppendData(buf);
89 buf2.AppendData(rtc::ArrayView<uint8_t>(buf));
90 const int8_t exp2[] = {0x4, 0x5, 0x6, 0xa, 0xb, 0x4, 0x5, 0x6, 0xa, 0xb};
91 EXPECT_EQ(buf2, Buffer(exp2));
80 } 92 }
81 93
82 TEST(BufferTest, TestSetSizeSmaller) { 94 TEST(BufferTest, TestSetSizeSmaller) {
83 Buffer buf; 95 Buffer buf;
84 buf.SetData(kTestData, 15); 96 buf.SetData(kTestData, 15);
85 buf.SetSize(10); 97 buf.SetSize(10);
86 EXPECT_EQ(buf.size(), 10u); 98 EXPECT_EQ(buf.size(), 10u);
87 EXPECT_EQ(buf.capacity(), 15u); // Hasn't shrunk. 99 EXPECT_EQ(buf.capacity(), 15u); // Hasn't shrunk.
88 EXPECT_EQ(buf, Buffer(kTestData, 10)); 100 EXPECT_EQ(buf, Buffer(kTestData, 10));
89 } 101 }
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 BufferT<BloodStone*> buf2(4); 363 BufferT<BloodStone*> buf2(4);
352 for (size_t i = 0; i < buf2.size(); ++i) { 364 for (size_t i = 0; i < buf2.size(); ++i) {
353 buf2[i] = &buf[i]; 365 buf2[i] = &buf[i];
354 } 366 }
355 static const char kObsidian[] = "obsidian"; 367 static const char kObsidian[] = "obsidian";
356 buf2[2]->stone = kObsidian; 368 buf2[2]->stone = kObsidian;
357 EXPECT_EQ(kObsidian, buf[2].stone); 369 EXPECT_EQ(kObsidian, buf[2].stone);
358 } 370 }
359 371
360 } // namespace rtc 372 } // namespace rtc
OLDNEW
« webrtc/base/buffer.h ('K') | « webrtc/base/buffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698