1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "modules/audio_processing/echo_detector/circular_buffer.h"
12
13 #include "test/gtest.h"
14
15 namespace webrtc {
16
TEST(CircularBufferTests,LessThanMaxTest)17 TEST(CircularBufferTests, LessThanMaxTest) {
18 CircularBuffer test_buffer(3);
19 test_buffer.Push(1.f);
20 test_buffer.Push(2.f);
21 EXPECT_EQ(1.f, test_buffer.Pop());
22 EXPECT_EQ(2.f, test_buffer.Pop());
23 }
24
TEST(CircularBufferTests,FillTest)25 TEST(CircularBufferTests, FillTest) {
26 CircularBuffer test_buffer(3);
27 test_buffer.Push(1.f);
28 test_buffer.Push(2.f);
29 test_buffer.Push(3.f);
30 EXPECT_EQ(1.f, test_buffer.Pop());
31 EXPECT_EQ(2.f, test_buffer.Pop());
32 EXPECT_EQ(3.f, test_buffer.Pop());
33 }
34
TEST(CircularBufferTests,OverflowTest)35 TEST(CircularBufferTests, OverflowTest) {
36 CircularBuffer test_buffer(3);
37 test_buffer.Push(1.f);
38 test_buffer.Push(2.f);
39 test_buffer.Push(3.f);
40 test_buffer.Push(4.f);
41 // Because the circular buffer has a size of 3, the first insert should have
42 // been forgotten.
43 EXPECT_EQ(2.f, test_buffer.Pop());
44 EXPECT_EQ(3.f, test_buffer.Pop());
45 EXPECT_EQ(4.f, test_buffer.Pop());
46 }
47
TEST(CircularBufferTests,ReadFromEmpty)48 TEST(CircularBufferTests, ReadFromEmpty) {
49 CircularBuffer test_buffer(3);
50 EXPECT_EQ(absl::nullopt, test_buffer.Pop());
51 }
52
53 } // namespace webrtc
54