| Index: chromecast/media/audio/cast_audio_manager_factory_test.cc
|
| diff --git a/chromecast/media/audio/cast_audio_manager_factory_test.cc b/chromecast/media/audio/cast_audio_manager_factory_test.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e7b34d9a0ab5f33667a37b92e4e7d9b91e1d589e
|
| --- /dev/null
|
| +++ b/chromecast/media/audio/cast_audio_manager_factory_test.cc
|
| @@ -0,0 +1,108 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include <string>
|
| +#include "chromecast/media/audio/cast_audio_manager_factory.h"
|
| +#include "chromecast/public/cast_audio_stream_provider.h"
|
| +#include "media/audio/audio_manager.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace chromecast {
|
| +namespace {
|
| +
|
| +// Testing constants.
|
| +const int kTestBitDepth = 16;
|
| +const auto kTestChannelLayout = media::ChannelLayout::CHANNEL_LAYOUT_STEREO;
|
| +const char kTestDeviceId[] = "test_device_id";
|
| +const int kTestFramesPerBuffer = 1024;
|
| +const int kTestSampleRate = 48000;
|
| +
|
| +// Mock for CastAudioStreamProvider.
|
| +class MockCastAudioStreamProvider : public chromecast::CastAudioStreamProvider {
|
| + public:
|
| + MockCastAudioStreamProvider() {}
|
| + virtual ~MockCastAudioStreamProvider() {}
|
| +
|
| + MOCK_CONST_METHOD0(GetMaximumOutputStreamsAllowed, int());
|
| + MOCK_CONST_METHOD1(GetPreferredOutputStreamParameters,
|
| + AudioParameters(const AudioParameters&));
|
| + MOCK_METHOD1(MakeOutputStream, AudioOutputStream*(const AudioParameters&));
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(MockCastAudioStreamProvider);
|
| +};
|
| +
|
| +// This test verifies that passing a CastAudioManagerFactory to
|
| +// media::AudioManager::SetFactory passes requests for audio stream creation
|
| +// to the underlying CastAudioStreamProvider, in this case a mock. It is
|
| +// intended to provide code coverage for CastAudioManagerFactory, but does not
|
| +// provide full coverage for CastAudioManager.
|
| +class CastAudioManagerFactoryTest : public testing::Test {
|
| + protected:
|
| + CastAudioManagerFactoryTest() : audio_manager_(nullptr) {}
|
| + ~CastAudioManagerFactoryTest() override {}
|
| +
|
| + void SetUp() override {
|
| + // Set defaults for AudioParameters object.
|
| + testing::DefaultValue<chromecast::AudioParameters>::Set(
|
| + chromecast::AudioParameters());
|
| +
|
| + // Set the factory. The factory must be reset in TearDown()
|
| + media::AudioManager::SetFactory(
|
| + new media::CastAudioManagerFactory(&mock_audio_stream_provider_));
|
| +
|
| + // Create the AudioManager instance and verify it.
|
| + EXPECT_CALL(mock_audio_stream_provider_, GetMaximumOutputStreamsAllowed())
|
| + .WillOnce(testing::Return(1));
|
| + audio_manager_.reset(media::AudioManager::CreateForTesting());
|
| + ASSERT_NE(nullptr, audio_manager_.get());
|
| + }
|
| +
|
| + void TearDown() override {
|
| + // This is crucial to not persisting state to other tests on the same gtest
|
| + // process. All other class members will destruct when this class destructs.
|
| + media::AudioManager::ResetFactoryForTesting();
|
| + }
|
| +
|
| + testing::StrictMock<MockCastAudioStreamProvider> mock_audio_stream_provider_;
|
| + scoped_ptr<media::AudioManager> audio_manager_;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(CastAudioManagerFactoryTest);
|
| +};
|
| +
|
| +// Verifies that the default output stream parameters are obtained from the
|
| +// provided CastAudioStreamProvider instance.
|
| +TEST_F(CastAudioManagerFactoryTest, GetPreferredOutputStreamParameters) {
|
| + EXPECT_CALL(mock_audio_stream_provider_,
|
| + GetPreferredOutputStreamParameters(testing::_));
|
| + audio_manager_->GetDefaultOutputStreamParameters();
|
| +}
|
| +
|
| +// Verifies that creating a linear output stream invokes MakeOutputStream in
|
| +// the provided CastAudioStreamProvider instance.
|
| +TEST_F(CastAudioManagerFactoryTest, MakeLinearOutputStream) {
|
| + media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LINEAR,
|
| + kTestChannelLayout, kTestSampleRate,
|
| + kTestBitDepth, kTestFramesPerBuffer);
|
| + EXPECT_CALL(mock_audio_stream_provider_, MakeOutputStream(testing::_));
|
| +
|
| + // Note that the empty string must be passed in to select the default device.
|
| + audio_manager_->MakeAudioOutputStream(params, "");
|
| +}
|
| +
|
| +// Verifies that creating a low-latency output stream invokes MakeOutputStream
|
| +// in
|
| +// the provided CastAudioStreamProvider instance.
|
| +TEST_F(CastAudioManagerFactoryTest, MakeLowLatencyOutputStream) {
|
| + media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
|
| + kTestChannelLayout, kTestSampleRate,
|
| + kTestBitDepth, kTestFramesPerBuffer);
|
| + EXPECT_CALL(mock_audio_stream_provider_, MakeOutputStream(testing::_));
|
| + audio_manager_->MakeAudioOutputStream(params, kTestDeviceId);
|
| +}
|
| +
|
| +} // namespace
|
| +} // namespace chromecast
|
|
|