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

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

Issue 2739143002: Revert of Enable cpplint and fix cpplint errors in webrtc/*audio (Closed)
Patch Set: 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 // rand_r is not supported on many platforms, so rand is used. 61 const int buffer_size = std::max(rand() % kMaxBufferSize, 1);
62 const int buffer_size = std::max(rand() % kMaxBufferSize, 1); // NOLINT
63 std::unique_ptr<int[]> write_data(new int[buffer_size]); 62 std::unique_ptr<int[]> write_data(new int[buffer_size]);
64 std::unique_ptr<int[]> read_data(new int[buffer_size]); 63 std::unique_ptr<int[]> read_data(new int[buffer_size]);
65 scoped_ring_buffer buffer(WebRtc_CreateBuffer(buffer_size, sizeof(int))); 64 scoped_ring_buffer buffer(WebRtc_CreateBuffer(buffer_size, sizeof(int)));
66 ASSERT_TRUE(buffer.get() != nullptr); 65 ASSERT_TRUE(buffer.get() != nullptr);
67 WebRtc_InitBuffer(buffer.get()); 66 WebRtc_InitBuffer(buffer.get());
68 int buffer_consumed = 0; 67 int buffer_consumed = 0;
69 int write_element = 0; 68 int write_element = 0;
70 int read_element = 0; 69 int read_element = 0;
71 for (int j = 0; j < kNumOps; j++) { 70 for (int j = 0; j < kNumOps; j++) {
72 const bool write = rand() % 2 == 0 ? true : false; // NOLINT 71 const bool write = rand() % 2 == 0 ? true : false;
73 const int num_elements = rand() % buffer_size; // NOLINT 72 const int num_elements = rand() % buffer_size;
74 if (write) { 73 if (write) {
75 const int buffer_available = buffer_size - buffer_consumed; 74 const int buffer_available = buffer_size - buffer_consumed;
76 ASSERT_EQ(static_cast<size_t>(buffer_available), 75 ASSERT_EQ(static_cast<size_t>(buffer_available),
77 WebRtc_available_write(buffer.get())); 76 WebRtc_available_write(buffer.get()));
78 const int expected_elements = std::min(num_elements, buffer_available); 77 const int expected_elements = std::min(num_elements, buffer_available);
79 write_element = SetIncrementingData(write_data.get(), expected_elements, 78 write_element = SetIncrementingData(write_data.get(), expected_elements,
80 write_element); 79 write_element);
81 ASSERT_EQ(static_cast<size_t>(expected_elements), 80 ASSERT_EQ(static_cast<size_t>(expected_elements),
82 WebRtc_WriteBuffer(buffer.get(), write_data.get(), 81 WebRtc_WriteBuffer(buffer.get(), write_data.get(),
83 num_elements)); 82 num_elements));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 141
143 TEST(RingBufferTest, CreateHandlesErrors) { 142 TEST(RingBufferTest, CreateHandlesErrors) {
144 EXPECT_TRUE(WebRtc_CreateBuffer(0, 1) == nullptr); 143 EXPECT_TRUE(WebRtc_CreateBuffer(0, 1) == nullptr);
145 EXPECT_TRUE(WebRtc_CreateBuffer(1, 0) == nullptr); 144 EXPECT_TRUE(WebRtc_CreateBuffer(1, 0) == nullptr);
146 RingBuffer* buffer = WebRtc_CreateBuffer(1, 1); 145 RingBuffer* buffer = WebRtc_CreateBuffer(1, 1);
147 EXPECT_TRUE(buffer != nullptr); 146 EXPECT_TRUE(buffer != nullptr);
148 WebRtc_FreeBuffer(buffer); 147 WebRtc_FreeBuffer(buffer);
149 } 148 }
150 149
151 } // namespace webrtc 150 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698