OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 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 131 matching lines...) Loading... | |
142 } | 142 } |
143 | 143 |
144 TEST(CopyOnWriteBufferTest, TestSetDataEmpty) { | 144 TEST(CopyOnWriteBufferTest, TestSetDataEmpty) { |
145 CopyOnWriteBuffer buf; | 145 CopyOnWriteBuffer buf; |
146 buf.SetData(static_cast<const uint8_t*>(nullptr), 0u); | 146 buf.SetData(static_cast<const uint8_t*>(nullptr), 0u); |
147 EXPECT_EQ(buf.size(), 0u); | 147 EXPECT_EQ(buf.size(), 0u); |
148 EXPECT_EQ(buf.capacity(), 0u); | 148 EXPECT_EQ(buf.capacity(), 0u); |
149 EXPECT_EQ(buf.data(), nullptr); | 149 EXPECT_EQ(buf.data(), nullptr); |
150 } | 150 } |
151 | 151 |
152 TEST(CopyOnWriteBufferTest, SetDataSmallerCapacityCauseNoReallocation) { | |
kwiberg-webrtc
2016/09/09 08:55:14
"Causes". Or even better, "DoesntCause"
danilchap
2016/09/09 11:21:17
Done.
| |
153 CopyOnWriteBuffer buf1(kTestData, 3, 10); | |
154 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.
| |
155 | |
156 buf1.SetData(kTestData, 2, 5); | |
157 | |
158 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.
| |
159 EXPECT_LE(5U, buf1.capacity()); | |
160 EXPECT_EQ(raw, buf1.cdata()); | |
161 } | |
162 | |
163 TEST(CopyOnWriteBufferTest, SetDataSmallerCapacityOnShared) { | |
164 CopyOnWriteBuffer buf1(kTestData, 3, 10); | |
165 CopyOnWriteBuffer buf2(buf1); | |
166 EnsureBuffersShareData(buf1, buf2); | |
167 | |
168 buf2.SetData(kTestData, 2, 5); | |
169 | |
170 EnsureBuffersDontShareData(buf1, buf2); | |
171 EXPECT_EQ(2U, buf2.size()); | |
172 EXPECT_LE(5U, buf2.capacity()); | |
173 } | |
174 | |
175 TEST(CopyOnWriteBufferTest, SetDataLargerCapacity) { | |
176 CopyOnWriteBuffer buf1(kTestData, 3, 10); | |
177 | |
178 buf1.SetData(kTestData, 2, 15); | |
179 | |
180 EXPECT_EQ(2U, buf1.size()); | |
181 EXPECT_LE(15U, buf1.capacity()); | |
182 } | |
183 | |
184 TEST(CopyOnWriteBufferTest, SetDataOnEmpty) { | |
185 CopyOnWriteBuffer buf1; | |
186 | |
187 buf1.SetData(kTestData, 2, 15); | |
188 | |
189 EXPECT_EQ(2U, buf1.size()); | |
190 EXPECT_LE(15U, buf1.capacity()); | |
191 } | |
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.
| |
192 | |
152 TEST(CopyOnWriteBufferTest, TestEnsureCapacity) { | 193 TEST(CopyOnWriteBufferTest, TestEnsureCapacity) { |
153 CopyOnWriteBuffer buf1(kTestData, 3, 10); | 194 CopyOnWriteBuffer buf1(kTestData, 3, 10); |
154 CopyOnWriteBuffer buf2(buf1); | 195 CopyOnWriteBuffer buf2(buf1); |
155 | 196 |
156 // Smaller than existing capacity -> no change and still same contents. | 197 // Smaller than existing capacity -> no change and still same contents. |
157 buf2.EnsureCapacity(8); | 198 buf2.EnsureCapacity(8); |
158 EnsureBuffersShareData(buf1, buf2); | 199 EnsureBuffersShareData(buf1, buf2); |
159 EXPECT_EQ(buf1.size(), 3u); | 200 EXPECT_EQ(buf1.size(), 3u); |
160 EXPECT_EQ(buf1.capacity(), 10u); | 201 EXPECT_EQ(buf1.capacity(), 10u); |
161 EXPECT_EQ(buf2.size(), 3u); | 202 EXPECT_EQ(buf2.size(), 3u); |
(...skipping 89 matching lines...) Loading... | |
251 buf1[i] = kTestData[i] + 1; | 292 buf1[i] = kTestData[i] + 1; |
252 } | 293 } |
253 EXPECT_EQ(buf1.size(), 3u); | 294 EXPECT_EQ(buf1.size(), 3u); |
254 EXPECT_EQ(buf1.capacity(), 10u); | 295 EXPECT_EQ(buf1.capacity(), 10u); |
255 EXPECT_EQ(buf2.size(), 3u); | 296 EXPECT_EQ(buf2.size(), 3u); |
256 EXPECT_EQ(buf2.capacity(), 10u); | 297 EXPECT_EQ(buf2.capacity(), 10u); |
257 EXPECT_EQ(0, memcmp(buf2.cdata(), kTestData, 3)); | 298 EXPECT_EQ(0, memcmp(buf2.cdata(), kTestData, 3)); |
258 } | 299 } |
259 | 300 |
260 } // namespace rtc | 301 } // namespace rtc |
OLD | NEW |