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

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

Issue 1105803002: Exposes a shlib interface for media/audio path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Name refactoring. Created 5 years, 8 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_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..d5dff71a48e024cf0c7bc8c93151061b309060b3
--- /dev/null
+++ b/chromecast/media/audio/cast_audio_manager_factory_test.cc
@@ -0,0 +1,109 @@
+// 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:38 Done.
+#include "chromecast/media/audio/cast_audio_manager_factory.h"
+#include "chromecast/public/cast_audio_output_device.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 CastAudioOutputDevice.
+class MockCastAudioOutputDevice : public chromecast::CastAudioOutputDevice {
+ public:
+ MockCastAudioOutputDevice() {}
+ virtual ~MockCastAudioOutputDevice() {}
+
+ MOCK_CONST_METHOD0(GetMaximumOutputStreamsAllowed, int());
+ MOCK_CONST_METHOD1(GetPreferredOutputStreamParameters,
+ AudioParameters(const AudioParameters&));
+ MOCK_METHOD1(MakeOutputStream,
+ CastAudioOutputStream*(const AudioParameters&));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockCastAudioOutputDevice);
+};
+
+// This test verifies that passing a CastAudioManagerFactory to
+// media::AudioManager::SetFactory passes requests for audio stream creation
+// to the underlying CastAudioOutputDevice, 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 CastAudioManagerFactory(&mock_audio_output_device_));
+
+ // Create the AudioManager instance and verify it.
+ EXPECT_CALL(mock_audio_output_device_, 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<MockCastAudioOutputDevice> mock_audio_output_device_;
+ scoped_ptr<media::AudioManager> audio_manager_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(CastAudioManagerFactoryTest);
+};
+
+// Verifies that the default output stream parameters are obtained from the
+// provided CastAudioOutputDevice instance.
+TEST_F(CastAudioManagerFactoryTest, GetPreferredOutputStreamParameters) {
+ EXPECT_CALL(mock_audio_output_device_,
+ GetPreferredOutputStreamParameters(testing::_));
+ audio_manager_->GetDefaultOutputStreamParameters();
+}
+
+// Verifies that creating a linear output stream invokes MakeOutputStream in
+// the provided CastAudioOutputDevice instance.
+TEST_F(CastAudioManagerFactoryTest, MakeLinearOutputStream) {
+ media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LINEAR,
+ kTestChannelLayout, kTestSampleRate,
+ kTestBitDepth, kTestFramesPerBuffer);
+ EXPECT_CALL(mock_audio_output_device_, 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 CastAudioOutputDevice instance.
+TEST_F(CastAudioManagerFactoryTest, MakeLowLatencyOutputStream) {
+ media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
+ kTestChannelLayout, kTestSampleRate,
+ kTestBitDepth, kTestFramesPerBuffer);
+ EXPECT_CALL(mock_audio_output_device_, MakeOutputStream(testing::_));
+ audio_manager_->MakeAudioOutputStream(params, kTestDeviceId);
+}
+
+} // namespace
+} // namespace chromecast

Powered by Google App Engine
This is Rietveld 408576698