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

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

Issue 1745033002: Added an operator[] to Buffer, to make reading data easier. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added DCHECKs for index against size_ 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
« no previous file with comments | « 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
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 EXPECT_EQ(buf.AppendData(15, setter), 15u); 272 EXPECT_EQ(buf.AppendData(15, setter), 15u);
273 EXPECT_EQ(buf.size(), 30u); // Size is exactly what we wrote. 273 EXPECT_EQ(buf.size(), 30u); // Size is exactly what we wrote.
274 EXPECT_GE(buf.capacity(), 30u); // Capacity is valid. 274 EXPECT_GE(buf.capacity(), 30u); // Capacity is valid.
275 EXPECT_NE(buf.data<char>(), nullptr); // Data is actually stored. 275 EXPECT_NE(buf.data<char>(), nullptr); // Data is actually stored.
276 276
277 for (uint8_t i = 0; i != buf.size(); ++i) { 277 for (uint8_t i = 0; i != buf.size(); ++i) {
278 EXPECT_EQ(buf.data()[i], magic_number + i); 278 EXPECT_EQ(buf.data()[i], magic_number + i);
279 } 279 }
280 } 280 }
281 281
282 TEST(BufferTest, TestBracketRead) {
283 Buffer buf(kTestData, 7);
284 EXPECT_EQ(buf.size(), 7u);
285 EXPECT_EQ(buf.capacity(), 7u);
286 EXPECT_NE(buf.data(), nullptr);
287
288 for (size_t i = 0; i != 7u; ++i) {
289 EXPECT_EQ(buf[i], kTestData[i]);
290 }
291 }
292
293 TEST(BufferTest, TestBracketReadConst) {
294 Buffer buf(kTestData, 7);
295 EXPECT_EQ(buf.size(), 7u);
296 EXPECT_EQ(buf.capacity(), 7u);
297 EXPECT_NE(buf.data(), nullptr);
298
299 const Buffer& cbuf = buf;
300
301 for (size_t i = 0; i != 7u; ++i) {
302 EXPECT_EQ(cbuf[i], kTestData[i]);
303 }
304 }
305
306 TEST(BufferTest, TestBracketWrite) {
307 Buffer buf(7);
308 EXPECT_EQ(buf.size(), 7u);
309 EXPECT_EQ(buf.capacity(), 7u);
310 EXPECT_NE(buf.data(), nullptr);
311
312 for (size_t i = 0; i != 7u; ++i) {
313 buf[i] = kTestData[i];
314 }
315
316 for (size_t i = 0; i != 7u; ++i) {
317 EXPECT_EQ(buf[i], kTestData[i]);
318 }
319 }
320
282 } // namespace rtc 321 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/buffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698