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

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

Issue 1726043002: Revert of Replace scoped_ptr with unique_ptr in webrtc/common_audio/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 10 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
11 #include "webrtc/common_audio/ring_buffer.h" 11 #include "webrtc/common_audio/ring_buffer.h"
12 12
13 #include <stdlib.h> 13 #include <stdlib.h>
14 #include <time.h> 14 #include <time.h>
15
16 #include <algorithm> 15 #include <algorithm>
17 #include <memory>
18 16
19 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "webrtc/base/scoped_ptr.h"
20 19
21 namespace webrtc { 20 namespace webrtc {
22 21
23 struct FreeBufferDeleter { 22 struct FreeBufferDeleter {
24 inline void operator()(void* ptr) const { 23 inline void operator()(void* ptr) const {
25 WebRtc_FreeBuffer(ptr); 24 WebRtc_FreeBuffer(ptr);
26 } 25 }
27 }; 26 };
28 typedef std::unique_ptr<RingBuffer, FreeBufferDeleter> scoped_ring_buffer; 27 typedef rtc::scoped_ptr<RingBuffer, FreeBufferDeleter> scoped_ring_buffer;
29 28
30 static void AssertElementEq(int expected, int actual) { 29 static void AssertElementEq(int expected, int actual) {
31 ASSERT_EQ(expected, actual); 30 ASSERT_EQ(expected, actual);
32 } 31 }
33 32
34 static int SetIncrementingData(int* data, int num_elements, 33 static int SetIncrementingData(int* data, int num_elements,
35 int starting_value) { 34 int starting_value) {
36 for (int i = 0; i < num_elements; i++) { 35 for (int i = 0; i < num_elements; i++) {
37 data[i] = starting_value++; 36 data[i] = starting_value++;
38 } 37 }
(...skipping 13 matching lines...) Expand all
52 static void RandomStressTest(int** data_ptr) { 51 static void RandomStressTest(int** data_ptr) {
53 const int kNumTests = 10; 52 const int kNumTests = 10;
54 const int kNumOps = 1000; 53 const int kNumOps = 1000;
55 const int kMaxBufferSize = 1000; 54 const int kMaxBufferSize = 1000;
56 55
57 unsigned int seed = time(NULL); 56 unsigned int seed = time(NULL);
58 printf("seed=%u\n", seed); 57 printf("seed=%u\n", seed);
59 srand(seed); 58 srand(seed);
60 for (int i = 0; i < kNumTests; i++) { 59 for (int i = 0; i < kNumTests; i++) {
61 const int buffer_size = std::max(rand() % kMaxBufferSize, 1); 60 const int buffer_size = std::max(rand() % kMaxBufferSize, 1);
62 std::unique_ptr<int[]> write_data(new int[buffer_size]); 61 rtc::scoped_ptr<int[]> write_data(new int[buffer_size]);
63 std::unique_ptr<int[]> read_data(new int[buffer_size]); 62 rtc::scoped_ptr<int[]> read_data(new int[buffer_size]);
64 scoped_ring_buffer buffer(WebRtc_CreateBuffer(buffer_size, sizeof(int))); 63 scoped_ring_buffer buffer(WebRtc_CreateBuffer(buffer_size, sizeof(int)));
65 ASSERT_TRUE(buffer.get() != NULL); 64 ASSERT_TRUE(buffer.get() != NULL);
66 WebRtc_InitBuffer(buffer.get()); 65 WebRtc_InitBuffer(buffer.get());
67 int buffer_consumed = 0; 66 int buffer_consumed = 0;
68 int write_element = 0; 67 int write_element = 0;
69 int read_element = 0; 68 int read_element = 0;
70 for (int j = 0; j < kNumOps; j++) { 69 for (int j = 0; j < kNumOps; j++) {
71 const bool write = rand() % 2 == 0 ? true : false; 70 const bool write = rand() % 2 == 0 ? true : false;
72 const int num_elements = rand() % buffer_size; 71 const int num_elements = rand() % buffer_size;
73 if (write) { 72 if (write) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 140
142 TEST(RingBufferTest, CreateHandlesErrors) { 141 TEST(RingBufferTest, CreateHandlesErrors) {
143 EXPECT_TRUE(WebRtc_CreateBuffer(0, 1) == NULL); 142 EXPECT_TRUE(WebRtc_CreateBuffer(0, 1) == NULL);
144 EXPECT_TRUE(WebRtc_CreateBuffer(1, 0) == NULL); 143 EXPECT_TRUE(WebRtc_CreateBuffer(1, 0) == NULL);
145 RingBuffer* buffer = WebRtc_CreateBuffer(1, 1); 144 RingBuffer* buffer = WebRtc_CreateBuffer(1, 1);
146 EXPECT_TRUE(buffer != NULL); 145 EXPECT_TRUE(buffer != NULL);
147 WebRtc_FreeBuffer(buffer); 146 WebRtc_FreeBuffer(buffer);
148 } 147 }
149 148
150 } // namespace webrtc 149 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_audio/resampler/sinc_resampler_unittest.cc ('k') | webrtc/common_audio/sparse_fir_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698