| Index: chromecast/media/audio/cast_audio_manager_unittest.cc
|
| diff --git a/chromecast/media/audio/cast_audio_manager_unittest.cc b/chromecast/media/audio/cast_audio_manager_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3c0f0d51221d115960dd0af7a5492ef64e15ba24
|
| --- /dev/null
|
| +++ b/chromecast/media/audio/cast_audio_manager_unittest.cc
|
| @@ -0,0 +1,213 @@
|
| +// 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 "base/logging.h"
|
| +#include "base/test/mock_log.h"
|
| +#include "chromecast/media/audio/cast_audio_manager.h"
|
| +#include "chromecast/media/audio/cast_audio_manager_factory.h"
|
| +#include "chromecast/public/cast_audio_stream.h"
|
| +#include "chromecast/public/cast_audio_stream_provider.h"
|
| +#include "media/audio/audio_manager.h"
|
| +#include "media/audio/fake_audio_log_factory.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace chromecast {
|
| +namespace {
|
| +
|
| +// Makes reading the syntax prettier.
|
| +using testing::_;
|
| +
|
| +// 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;
|
| +
|
| +class FakeAudioOutputStream : public AudioOutputStream {
|
| + public:
|
| + FakeAudioOutputStream() {}
|
| + ~FakeAudioOutputStream() override {}
|
| +
|
| + // AudioOutputStream overrides.
|
| + bool Open() override { return true; }
|
| + void Start(AudioSourceCallback* callback) override {}
|
| + void Stop() override {}
|
| + void SetVolume(double volume) override {}
|
| + void GetVolume(double* volume) override {}
|
| + void Close() override {}
|
| +};
|
| +
|
| +class FakeAudioStreamProvider : public CastAudioStreamProvider {
|
| + public:
|
| + FakeAudioStreamProvider() : null_stream_(false) {}
|
| + ~FakeAudioStreamProvider() override {}
|
| +
|
| + // Pass in true to return a nullptr when MakeOutputStream is called.
|
| + void set_null_stream(bool null_stream) { null_stream_ = null_stream; }
|
| +
|
| + // AudioStreamProvider overrides.
|
| + int GetMaximumOutputStreamsAllowed() const override { return 1; }
|
| +
|
| + AudioParameters GetPreferredOutputStreamParameters(
|
| + const AudioParameters& suggested) const override {
|
| + return suggested;
|
| + }
|
| +
|
| + AudioOutputStream* MakeOutputStream(const AudioParameters& params) override {
|
| + if (null_stream_)
|
| + return nullptr;
|
| +
|
| + // Return a fake stream.
|
| + output_stream_.reset(new FakeAudioOutputStream());
|
| + return output_stream_.get();
|
| + }
|
| +
|
| + private:
|
| + bool null_stream_;
|
| + scoped_ptr<AudioOutputStream> output_stream_;
|
| +};
|
| +
|
| +class CastAudioManagerTest : public testing::Test {
|
| + protected:
|
| + CastAudioManagerTest() {}
|
| + ~CastAudioManagerTest() override {}
|
| +
|
| + void SetUp() override {
|
| + audio_manager_.reset(
|
| + new media::CastAudioManager(&log_factory_, &audio_stream_provider_));
|
| + }
|
| +
|
| + // Constructor parameters are fakes.
|
| + media::FakeAudioLogFactory log_factory_;
|
| + FakeAudioStreamProvider audio_stream_provider_;
|
| +
|
| + // Class being tested.
|
| + scoped_ptr<media::CastAudioManager> audio_manager_;
|
| +};
|
| +
|
| +TEST_F(CastAudioManagerTest, HasAudioOutputDevices) {
|
| + EXPECT_TRUE(audio_manager_->HasAudioOutputDevices());
|
| +}
|
| +
|
| +TEST_F(CastAudioManagerTest, HasAudioInputDevices) {
|
| + EXPECT_FALSE(audio_manager_->HasAudioInputDevices());
|
| +}
|
| +
|
| +TEST_F(CastAudioManagerTest, ShowAudioInputSettings) {
|
| + base::test::MockLog log;
|
| + log.StartCapturingLogs();
|
| + EXPECT_CALL(log, Log(logging::LOG_WARNING, _, _, _, _));
|
| + audio_manager_->ShowAudioInputSettings();
|
| +}
|
| +
|
| +TEST_F(CastAudioManagerTest, GetAudioInputDeviceNames) {
|
| + base::test::MockLog log;
|
| + log.StartCapturingLogs();
|
| + EXPECT_CALL(log, Log(logging::LOG_WARNING, _, _, _, _));
|
| + media::AudioDeviceNames device_names;
|
| + audio_manager_->GetAudioInputDeviceNames(&device_names);
|
| +}
|
| +
|
| +TEST_F(CastAudioManagerTest, GetInputStreamParameters) {
|
| + base::test::MockLog log;
|
| + log.StartCapturingLogs();
|
| + EXPECT_CALL(log, Log(logging::LOG_WARNING, _, _, _, _));
|
| + audio_manager_->GetInputStreamParameters(kTestDeviceId);
|
| +}
|
| +
|
| +TEST_F(CastAudioManagerTest, GetPreferredOutputStreamParameters) {
|
| + // Create the parameters.
|
| + media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LINEAR,
|
| + kTestChannelLayout, kTestSampleRate,
|
| + kTestBitDepth, kTestFramesPerBuffer);
|
| +
|
| + media::AudioParameters params_out =
|
| + audio_manager_->GetPreferredOutputStreamParameters("", params);
|
| + ASSERT_TRUE(params.Equals(params_out));
|
| +}
|
| +
|
| +TEST_F(CastAudioManagerTest, MakeLinearOutputStream) {
|
| + // Create the parameters.
|
| + media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LINEAR,
|
| + kTestChannelLayout, kTestSampleRate,
|
| + kTestBitDepth, kTestFramesPerBuffer);
|
| +
|
| + // Test that a returned null stream trickles all the way up.
|
| + audio_stream_provider_.set_null_stream(true);
|
| + media::AudioOutputStream* stream =
|
| + audio_manager_->MakeLinearOutputStream(params);
|
| + EXPECT_EQ(nullptr, stream);
|
| +
|
| + // Test that a non-null stream returns successfully.
|
| + audio_stream_provider_.set_null_stream(false);
|
| + stream = audio_manager_->MakeLinearOutputStream(params);
|
| + EXPECT_NE(nullptr, stream);
|
| +}
|
| +
|
| +TEST_F(CastAudioManagerTest, MakeLowLatencyOutputStream) {
|
| + // Create the parameters.
|
| + media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
|
| + kTestChannelLayout, kTestSampleRate,
|
| + kTestBitDepth, kTestFramesPerBuffer);
|
| +
|
| + // Test that a returned null stream trickles all the way up.
|
| + audio_stream_provider_.set_null_stream(true);
|
| +
|
| + media::AudioOutputStream* stream =
|
| + audio_manager_->MakeLowLatencyOutputStream(params, kTestDeviceId);
|
| + EXPECT_EQ(nullptr, stream);
|
| +
|
| + // Test that a non-null stream returns successfully.
|
| + audio_stream_provider_.set_null_stream(false);
|
| + stream = audio_manager_->MakeLowLatencyOutputStream(params, kTestDeviceId);
|
| + EXPECT_NE(nullptr, stream);
|
| +}
|
| +
|
| +TEST_F(CastAudioManagerTest, MakeLinearInputStream) {
|
| + base::test::MockLog log;
|
| + log.StartCapturingLogs();
|
| + EXPECT_CALL(log, Log(logging::LOG_WARNING, _, _, _, _)).Times(2);
|
| +
|
| + // Create the parameters.
|
| + media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LINEAR,
|
| + kTestChannelLayout, kTestSampleRate,
|
| + kTestBitDepth, kTestFramesPerBuffer);
|
| +
|
| + // Test that the returned stream is always null.
|
| + audio_stream_provider_.set_null_stream(true);
|
| + media::AudioInputStream* stream =
|
| + audio_manager_->MakeLinearInputStream(params, kTestDeviceId);
|
| + EXPECT_EQ(nullptr, stream);
|
| +
|
| + audio_stream_provider_.set_null_stream(false);
|
| + stream = audio_manager_->MakeLinearInputStream(params, kTestDeviceId);
|
| + EXPECT_EQ(nullptr, stream);
|
| +}
|
| +
|
| +TEST_F(CastAudioManagerTest, MakeLowLatencyInputStream) {
|
| + base::test::MockLog log;
|
| + log.StartCapturingLogs();
|
| + EXPECT_CALL(log, Log(logging::LOG_WARNING, _, _, _, _)).Times(2);
|
| +
|
| + // Create the parameters.
|
| + media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
|
| + kTestChannelLayout, kTestSampleRate,
|
| + kTestBitDepth, kTestFramesPerBuffer);
|
| +
|
| + // Test that a the returned stream is always null.
|
| + audio_stream_provider_.set_null_stream(true);
|
| + media::AudioInputStream* stream =
|
| + audio_manager_->MakeLowLatencyInputStream(params, kTestDeviceId);
|
| + EXPECT_EQ(nullptr, stream);
|
| +
|
| + audio_stream_provider_.set_null_stream(false);
|
| + stream = audio_manager_->MakeLowLatencyInputStream(params, kTestDeviceId);
|
| + EXPECT_EQ(nullptr, stream);
|
| +}
|
| +
|
| +} // namespace
|
| +} // namespace chromecast
|
|
|