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..fde6d6564300899c1572d66f1450e307365b9c28 |
--- /dev/null |
+++ b/chromecast/media/audio/cast_audio_manager_unittest.cc |
@@ -0,0 +1,217 @@ |
+// 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> |
halliwell
2015/04/24 15:04:47
insert blank line
slan
2015/04/24 16:19:39
Done.
|
+#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_output_device.h" |
+#include "chromecast/public/cast_audio_stream.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; |
+ |
+// A stubbed-out output stream. |
+class FakeCastAudioOutputStream : public CastAudioOutputStream { |
+ public: |
+ FakeCastAudioOutputStream() {} |
+ ~FakeCastAudioOutputStream() override {} |
+ |
+ // CastAudioOutputStream implementation: |
+ 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 {} |
+}; |
+ |
+// A fake audio output device. This takes the place of a platform specific |
+// implementation. |
+class FakeCastAudioOutputDevice : public CastAudioOutputDevice { |
+ public: |
+ FakeCastAudioOutputDevice() : null_stream_(false) {} |
+ ~FakeCastAudioOutputDevice() override {} |
+ |
+ // Pass in true to return a nullptr when MakeOutputStream is called. |
+ void set_null_stream(bool null_stream) { null_stream_ = null_stream; } |
+ |
+ // AudioOutputDevice implementation: |
+ int GetMaximumOutputStreamsAllowed() const override { return 1; } |
+ |
+ AudioParameters GetPreferredOutputStreamParameters( |
+ const AudioParameters& suggested) const override { |
+ return suggested; |
+ } |
+ |
+ CastAudioOutputStream* MakeOutputStream( |
+ const AudioParameters& params) override { |
+ if (null_stream_) |
+ return nullptr; |
+ |
+ // Return a fake stream. |
+ output_stream_.reset(new FakeCastAudioOutputStream()); |
+ return output_stream_.get(); |
+ } |
+ |
+ private: |
+ bool null_stream_; |
+ scoped_ptr<CastAudioOutputStream> output_stream_; |
+}; |
+ |
+// The testbed for this suite of tests. |
+class CastAudioManagerTest : public testing::Test { |
+ protected: |
+ CastAudioManagerTest() {} |
+ ~CastAudioManagerTest() override {} |
+ |
+ void SetUp() override { |
+ audio_manager_.reset( |
+ new CastAudioManager(&log_factory_, &audio_output_device_)); |
+ } |
+ |
+ // Constructor parameters are fakes. |
+ media::FakeAudioLogFactory log_factory_; |
+ FakeCastAudioOutputDevice audio_output_device_; |
+ |
+ // Class being tested. |
+ scoped_ptr<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_output_device_.set_null_stream(true); |
+ media::AudioOutputStream* stream = |
+ audio_manager_->MakeLinearOutputStream(params); |
+ EXPECT_EQ(nullptr, stream); |
+ |
+ // Test that a non-null stream returns successfully. |
+ audio_output_device_.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_output_device_.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_output_device_.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_output_device_.set_null_stream(true); |
+ media::AudioInputStream* stream = |
+ audio_manager_->MakeLinearInputStream(params, kTestDeviceId); |
+ EXPECT_EQ(nullptr, stream); |
+ |
+ audio_output_device_.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_output_device_.set_null_stream(true); |
+ media::AudioInputStream* stream = |
+ audio_manager_->MakeLowLatencyInputStream(params, kTestDeviceId); |
+ EXPECT_EQ(nullptr, stream); |
+ |
+ audio_output_device_.set_null_stream(false); |
+ stream = audio_manager_->MakeLowLatencyInputStream(params, kTestDeviceId); |
+ EXPECT_EQ(nullptr, stream); |
+} |
+ |
+} // namespace |
+} // namespace chromecast |