2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
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.
11 #include "webrtc/modules/audio_processing/audio_processing_impl.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webrtc/modules/audio_processing/test/test_utils.h"
16 #include "webrtc/modules/interface/module_common_types.h"
18 using ::testing::Invoke;
19 using ::testing::Return;
23 class MockInitialize : public AudioProcessingImpl {
25 MOCK_METHOD0(InitializeLocked, int());
27 int RealInitializeLocked() { return AudioProcessingImpl::InitializeLocked(); }
30 TEST(AudioProcessingImplTest, AudioParameterChangeTriggersInit) {
32 ON_CALL(mock, InitializeLocked())
33 .WillByDefault(Invoke(&mock, &MockInitialize::RealInitializeLocked));
35 EXPECT_CALL(mock, InitializeLocked()).Times(1);
39 // Call with the default parameters; there should be no init.
40 frame.num_channels_ = 1;
41 SetFrameSampleRate(&frame, 16000);
42 EXPECT_CALL(mock, InitializeLocked())
44 EXPECT_EQ(kNoErr, mock.ProcessStream(&frame));
45 EXPECT_EQ(kNoErr, mock.AnalyzeReverseStream(&frame));
47 // New sample rate. (Only impacts ProcessStream).
48 SetFrameSampleRate(&frame, 32000);
49 EXPECT_CALL(mock, InitializeLocked())
51 EXPECT_EQ(kNoErr, mock.ProcessStream(&frame));
53 // New number of channels.
54 frame.num_channels_ = 2;
55 EXPECT_CALL(mock, InitializeLocked())
57 EXPECT_EQ(kNoErr, mock.ProcessStream(&frame));
58 // ProcessStream sets num_channels_ == num_output_channels.
59 frame.num_channels_ = 2;
60 EXPECT_EQ(kNoErr, mock.AnalyzeReverseStream(&frame));
62 // A new sample rate passed to AnalyzeReverseStream should be an error and
64 SetFrameSampleRate(&frame, 16000);
65 EXPECT_CALL(mock, InitializeLocked())
67 EXPECT_EQ(mock.kBadSampleRateError, mock.AnalyzeReverseStream(&frame));