75b9230f1c0566f50b608cd383e94490af77dde3
[platform/framework/web/crosswalk.git] / src / third_party / webrtc / modules / audio_processing / audio_processing_impl_unittest.cc
1 /*
2  *  Copyright (c) 2014 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 "webrtc/modules/audio_processing/audio_processing_impl.h"
12
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"
17
18 using ::testing::Invoke;
19 using ::testing::Return;
20
21 namespace webrtc {
22
23 class MockInitialize : public AudioProcessingImpl {
24  public:
25   MOCK_METHOD0(InitializeLocked, int());
26
27   int RealInitializeLocked() { return AudioProcessingImpl::InitializeLocked(); }
28 };
29
30 TEST(AudioProcessingImplTest, AudioParameterChangeTriggersInit) {
31   MockInitialize mock;
32   ON_CALL(mock, InitializeLocked())
33       .WillByDefault(Invoke(&mock, &MockInitialize::RealInitializeLocked));
34
35   EXPECT_CALL(mock, InitializeLocked()).Times(1);
36   mock.Initialize();
37
38   AudioFrame frame;
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())
43       .Times(0);
44   EXPECT_EQ(kNoErr, mock.ProcessStream(&frame));
45   EXPECT_EQ(kNoErr, mock.AnalyzeReverseStream(&frame));
46
47   // New sample rate. (Only impacts ProcessStream).
48   SetFrameSampleRate(&frame, 32000);
49   EXPECT_CALL(mock, InitializeLocked())
50       .Times(1);
51   EXPECT_EQ(kNoErr, mock.ProcessStream(&frame));
52
53   // New number of channels.
54   frame.num_channels_ = 2;
55   EXPECT_CALL(mock, InitializeLocked())
56       .Times(2);
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));
61
62   // A new sample rate passed to AnalyzeReverseStream should be an error and
63   // not cause an init.
64   SetFrameSampleRate(&frame, 16000);
65   EXPECT_CALL(mock, InitializeLocked())
66       .Times(0);
67   EXPECT_EQ(mock.kBadSampleRateError, mock.AnalyzeReverseStream(&frame));
68 }
69
70 }  // namespace webrtc