Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Unified Diff: chromecast/media/audio/cast_audio_manager_unittest.cc

Issue 1105803002: Exposes a shlib interface for media/audio path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment out streaming test until the default implementation is improved. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..833f911a26ff4a5324d2ccdae1931a9849514ef2
--- /dev/null
+++ b/chromecast/media/audio/cast_audio_manager_unittest.cc
@@ -0,0 +1,239 @@
+// 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/media/cast_audio_output_device.h"
+#include "chromecast/public/media/cast_audio_output_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 media {
+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() : callback_(nullptr) {}
+ ~FakeCastAudioOutputStream() override {}
+
+ // CastAudioOutputStream implementation:
+ AudioParameters GetParameters() override { return params_; }
+ bool Open() override { return true; }
+ void Start(AudioSourceCallback* callback) override { callback_ = callback; }
+ void Stop() override {}
+ void SetVolume(double volume) override {}
+ double GetVolume() override { return 0.0; }
+ void Close() override {}
+
+ private:
+ AudioParameters params_;
+ AudioSourceCallback* callback_;
+};
+
+// 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() override { return 1; }
+
+ AudioParameters GetPreferredOutputStreamParameters(
+ const AudioParameters& suggested) override {
+ return suggested;
+ }
+
+ CastAudioOutputStream* MakeOutputStream(const AudioParameters& params,
+ TaskRunner* task_runner) 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();
+
+ // 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);
+ EXPECT_CALL(log, Log(logging::LOG_WARNING, _, _, _, _));
+ ::media::AudioInputStream* stream =
+ audio_manager_->MakeLinearInputStream(params, kTestDeviceId);
+ EXPECT_EQ(nullptr, stream);
+
+ audio_output_device_.set_null_stream(false);
+ EXPECT_CALL(log, Log(logging::LOG_WARNING, _, _, _, _));
+ stream = audio_manager_->MakeLinearInputStream(params, kTestDeviceId);
+ EXPECT_EQ(nullptr, stream);
+}
+
+TEST_F(CastAudioManagerTest, MakeLowLatencyInputStream) {
+ base::test::MockLog log;
+ log.StartCapturingLogs();
+
+ // 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);
+ EXPECT_CALL(log, Log(logging::LOG_WARNING, _, _, _, _));
+ ::media::AudioInputStream* stream =
+ audio_manager_->MakeLowLatencyInputStream(params, kTestDeviceId);
+ EXPECT_EQ(nullptr, stream);
+
+ audio_output_device_.set_null_stream(false);
+ EXPECT_CALL(log, Log(logging::LOG_WARNING, _, _, _, _));
+ stream = audio_manager_->MakeLowLatencyInputStream(params, kTestDeviceId);
+ EXPECT_EQ(nullptr, stream);
+}
+
+} // namespace
+} // namespace media
+} // namespace chromecast

Powered by Google App Engine
This is Rietveld 408576698