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

Side by Side Diff: webrtc/common_audio/ring_buffer_unittest.cc

Issue 2683033004: Enable cpplint and fix cpplint errors in webrtc/*audio (Closed)
Patch Set: Rebase Created 3 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 (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // failure. 51 // failure.
52 static void RandomStressTest(int** data_ptr) { 52 static void RandomStressTest(int** data_ptr) {
53 const int kNumTests = 10; 53 const int kNumTests = 10;
54 const int kNumOps = 1000; 54 const int kNumOps = 1000;
55 const int kMaxBufferSize = 1000; 55 const int kMaxBufferSize = 1000;
56 56
57 unsigned int seed = time(nullptr); 57 unsigned int seed = time(nullptr);
58 printf("seed=%u\n", seed); 58 printf("seed=%u\n", seed);
59 srand(seed); 59 srand(seed);
60 for (int i = 0; i < kNumTests; i++) { 60 for (int i = 0; i < kNumTests; i++) {
61 const int buffer_size = std::max(rand() % kMaxBufferSize, 1); 61 // rand_r is not supported on many platforms, so rand is used.
62 const int buffer_size = std::max(rand() % kMaxBufferSize, 1); // NOLINT
62 std::unique_ptr<int[]> write_data(new int[buffer_size]); 63 std::unique_ptr<int[]> write_data(new int[buffer_size]);
63 std::unique_ptr<int[]> read_data(new int[buffer_size]); 64 std::unique_ptr<int[]> read_data(new int[buffer_size]);
64 scoped_ring_buffer buffer(WebRtc_CreateBuffer(buffer_size, sizeof(int))); 65 scoped_ring_buffer buffer(WebRtc_CreateBuffer(buffer_size, sizeof(int)));
65 ASSERT_TRUE(buffer.get() != nullptr); 66 ASSERT_TRUE(buffer.get() != nullptr);
66 WebRtc_InitBuffer(buffer.get()); 67 WebRtc_InitBuffer(buffer.get());
67 int buffer_consumed = 0; 68 int buffer_consumed = 0;
68 int write_element = 0; 69 int write_element = 0;
69 int read_element = 0; 70 int read_element = 0;
70 for (int j = 0; j < kNumOps; j++) { 71 for (int j = 0; j < kNumOps; j++) {
71 const bool write = rand() % 2 == 0 ? true : false; 72 const bool write = rand() % 2 == 0 ? true : false; // NOLINT
72 const int num_elements = rand() % buffer_size; 73 const int num_elements = rand() % buffer_size; // NOLINT
73 if (write) { 74 if (write) {
74 const int buffer_available = buffer_size - buffer_consumed; 75 const int buffer_available = buffer_size - buffer_consumed;
75 ASSERT_EQ(static_cast<size_t>(buffer_available), 76 ASSERT_EQ(static_cast<size_t>(buffer_available),
76 WebRtc_available_write(buffer.get())); 77 WebRtc_available_write(buffer.get()));
77 const int expected_elements = std::min(num_elements, buffer_available); 78 const int expected_elements = std::min(num_elements, buffer_available);
78 write_element = SetIncrementingData(write_data.get(), expected_elements, 79 write_element = SetIncrementingData(write_data.get(), expected_elements,
79 write_element); 80 write_element);
80 ASSERT_EQ(static_cast<size_t>(expected_elements), 81 ASSERT_EQ(static_cast<size_t>(expected_elements),
81 WebRtc_WriteBuffer(buffer.get(), write_data.get(), 82 WebRtc_WriteBuffer(buffer.get(), write_data.get(),
82 num_elements)); 83 num_elements));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 142
142 TEST(RingBufferTest, CreateHandlesErrors) { 143 TEST(RingBufferTest, CreateHandlesErrors) {
143 EXPECT_TRUE(WebRtc_CreateBuffer(0, 1) == nullptr); 144 EXPECT_TRUE(WebRtc_CreateBuffer(0, 1) == nullptr);
144 EXPECT_TRUE(WebRtc_CreateBuffer(1, 0) == nullptr); 145 EXPECT_TRUE(WebRtc_CreateBuffer(1, 0) == nullptr);
145 RingBuffer* buffer = WebRtc_CreateBuffer(1, 1); 146 RingBuffer* buffer = WebRtc_CreateBuffer(1, 1);
146 EXPECT_TRUE(buffer != nullptr); 147 EXPECT_TRUE(buffer != nullptr);
147 WebRtc_FreeBuffer(buffer); 148 WebRtc_FreeBuffer(buffer);
148 } 149 }
149 150
150 } // namespace webrtc 151 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698