Chromium Code Reviews| Index: webrtc/audio/audio_state_audio_path_unittest.cc |
| diff --git a/webrtc/audio/audio_state_audio_path_unittest.cc b/webrtc/audio/audio_state_audio_path_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8590827fc3f6edd05915b8122717b5490f3ba75a |
| --- /dev/null |
| +++ b/webrtc/audio/audio_state_audio_path_unittest.cc |
| @@ -0,0 +1,118 @@ |
| +/* |
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#include <memory> |
| + |
| +#include "webrtc/audio/audio_state.h" |
| +#include "webrtc/base/refcountedobject.h" |
|
the sun
2016/11/14 20:03:46
why?
aleloi
2016/11/15 16:56:54
Not needed; removed!
|
| +#include "webrtc/modules/audio_mixer/audio_mixer_impl.h" |
| +#include "webrtc/test/gtest.h" |
| +#include "webrtc/test/mock_voice_engine.h" |
| + |
| +namespace webrtc { |
| +namespace test { |
| + |
| +class AudioStateAudioPathTest : public testing::Test { |
|
the sun
2016/11/14 20:03:46
Please avoid fixtures. Like in the stream tests, m
|
| + public: |
| + AudioStateAudioPathTest() : audio_mixer_(AudioMixerImpl::Create()) { |
| + using testing::_; |
| + |
| + EXPECT_CALL(voice_engine_, RegisterVoiceEngineObserver(testing::_)) |
| + .WillOnce(testing::Return(0)); |
| + EXPECT_CALL(voice_engine_, DeRegisterVoiceEngineObserver()) |
| + .WillOnce(testing::Return(0)); |
| + EXPECT_CALL(voice_engine_, audio_device_module()); |
| + EXPECT_CALL(voice_engine_, audio_processing()); |
| + EXPECT_CALL(voice_engine_, audio_transport()); |
| + |
| + auto device = static_cast<MockAudioDeviceModule*>( |
| + voice_engine_.audio_device_module()); |
| + |
| + ON_CALL(*device, RegisterAudioCallback(_)) |
| + .WillByDefault(testing::Invoke([this](AudioTransport* transport) { |
| + audio_transport_proxy_ = transport; |
| + return 0; |
| + })); |
| + |
| + ON_CALL(voice_engine_, audio_transport()) |
| + .WillByDefault(testing::Return(&original_audio_transport_)); |
| + |
| + EXPECT_CALL(voice_engine_, audio_device_module()); |
| + |
| + AudioState::Config config; |
| + config.voice_engine = &voice_engine_; |
| + config.audio_mixer = audio_mixer_; |
| + |
| + audio_state_.reset(new internal::AudioState(config)); |
| + } |
| + |
| + rtc::scoped_refptr<AudioMixer> mixer() { return audio_mixer_; } |
| + |
| + AudioTransport* audio_transport_proxy() { return audio_transport_proxy_; } |
| + |
| + MockAudioTransport& audio_transport() { return original_audio_transport_; } |
| + |
| + private: |
| + testing::StrictMock<MockVoiceEngine> voice_engine_; |
| + MockAudioTransport original_audio_transport_; |
| + std::unique_ptr<internal::AudioState> audio_state_; |
| + AudioTransport* audio_transport_proxy_ = nullptr; |
| + rtc::scoped_refptr<AudioMixer> audio_mixer_; |
| +}; |
| + |
| +namespace { |
| +class FakeAudioSource : public AudioMixer::Source { |
| + public: |
| + int Ssrc() const /*override*/ { return 0; } |
| + |
| + int PreferredSampleRate() const /*override*/ { return 8000; } |
| + |
| + MOCK_METHOD2(GetAudioFrameWithInfo, |
| + AudioFrameInfo(int sample_rate_hz, AudioFrame* audio_frame)); |
| +}; |
| +} // namespace |
| + |
| +// Test that RecordedDataIsAvailable calls get to the original transport. |
| +TEST_F(AudioStateAudioPathTest, RecordedAudioArrivesAtOriginalTransport) { |
| + // Setup completed. Ensure call of old transport is forwarded to new. |
| + uint32_t new_mic_level; |
| + EXPECT_CALL(audio_transport(), |
| + RecordedDataIsAvailable(nullptr, 80, 2, 1, 8000, 0, 0, 0, false, |
| + testing::Ref(new_mic_level))); |
| + |
| + audio_transport_proxy()->RecordedDataIsAvailable(nullptr, 80, 2, 1, 8000, 0, |
| + 0, 0, false, new_mic_level); |
| +} |
| + |
| +TEST_F(AudioStateAudioPathTest, |
| + QueryingProxyForAudioShouldResultInGetAudioCallOnMixerSource) { |
| + FakeAudioSource fake_source; |
| + |
| + mixer()->AddSource(&fake_source); |
| + |
| + EXPECT_CALL(fake_source, GetAudioFrameWithInfo(testing::_, testing::_)) |
| + .WillOnce( |
| + testing::Invoke([](int sample_rate_hz, AudioFrame* audio_frame) { |
| + audio_frame->sample_rate_hz_ = sample_rate_hz; |
| + audio_frame->samples_per_channel_ = sample_rate_hz / 100; |
| + audio_frame->num_channels_ = 1; |
| + return AudioMixer::Source::AudioFrameInfo::kNormal; |
| + })); |
| + |
| + int16_t audio_buffer[80]; |
| + size_t n_samples_out; |
| + int64_t elapsed_time_ms; |
| + int64_t ntp_time_ms; |
| + audio_transport_proxy()->NeedMorePlayData(80, 2, 1, 8000, audio_buffer, |
| + n_samples_out, &elapsed_time_ms, |
| + &ntp_time_ms); |
| +} |
| +} // namespace test |
| +} // namespace webrtc |