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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <string>
6 #include "chromecast/media/audio/cast_audio_manager_factory.h"
7 #include "chromecast/public/cast_audio_stream_provider.h"
8 #include "media/audio/audio_manager.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace chromecast {
13 namespace {
14
15 // Testing constants.
16 const int kTestBitDepth = 16;
17 const auto kTestChannelLayout = media::ChannelLayout::CHANNEL_LAYOUT_STEREO;
18 const char kTestDeviceId[] = "test_device_id";
19 const int kTestFramesPerBuffer = 1024;
20 const int kTestSampleRate = 48000;
21
22 // Mock for CastAudioStreamProvider.
23 class MockCastAudioStreamProvider : public chromecast::CastAudioStreamProvider {
24 public:
25 MockCastAudioStreamProvider() {}
26 virtual ~MockCastAudioStreamProvider() {}
27
28 MOCK_CONST_METHOD0(GetMaximumOutputStreamsAllowed, int());
29 MOCK_CONST_METHOD1(GetPreferredOutputStreamParameters,
30 AudioParameters(const AudioParameters&));
31 MOCK_METHOD1(MakeOutputStream, AudioOutputStream*(const AudioParameters&));
32
33 private:
34 DISALLOW_COPY_AND_ASSIGN(MockCastAudioStreamProvider);
35 };
36
37 // This test verifies that passing a CastAudioManagerFactory to
38 // media::AudioManager::SetFactory passes requests for audio stream creation
39 // to the underlying CastAudioStreamProvider, in this case a mock. It is
40 // intended to provide code coverage for CastAudioManagerFactory, but does not
41 // provide full coverage for CastAudioManager.
42 class CastAudioManagerFactoryTest : public testing::Test {
43 protected:
44 CastAudioManagerFactoryTest() : audio_manager_(nullptr) {}
45 ~CastAudioManagerFactoryTest() override {}
46
47 void SetUp() override {
48 // Set defaults for AudioParameters object.
49 testing::DefaultValue<chromecast::AudioParameters>::Set(
50 chromecast::AudioParameters());
51
52 // Set the factory. The factory must be reset in TearDown()
53 media::AudioManager::SetFactory(
54 new media::CastAudioManagerFactory(&mock_audio_stream_provider_));
55
56 // Create the AudioManager instance and verify it.
57 EXPECT_CALL(mock_audio_stream_provider_, GetMaximumOutputStreamsAllowed())
58 .WillOnce(testing::Return(1));
59 audio_manager_.reset(media::AudioManager::CreateForTesting());
60 ASSERT_NE(nullptr, audio_manager_.get());
61 }
62
63 void TearDown() override {
64 // This is crucial to not persisting state to other tests on the same gtest
65 // process. All other class members will destruct when this class destructs.
66 media::AudioManager::ResetFactoryForTesting();
67 }
68
69 testing::StrictMock<MockCastAudioStreamProvider> mock_audio_stream_provider_;
70 scoped_ptr<media::AudioManager> audio_manager_;
71
72 private:
73 DISALLOW_COPY_AND_ASSIGN(CastAudioManagerFactoryTest);
74 };
75
76 // Verifies that the default output stream parameters are obtained from the
77 // provided CastAudioStreamProvider instance.
78 TEST_F(CastAudioManagerFactoryTest, GetPreferredOutputStreamParameters) {
79 EXPECT_CALL(mock_audio_stream_provider_,
80 GetPreferredOutputStreamParameters(testing::_));
81 audio_manager_->GetDefaultOutputStreamParameters();
82 }
83
84 // Verifies that creating a linear output stream invokes MakeOutputStream in
85 // the provided CastAudioStreamProvider instance.
86 TEST_F(CastAudioManagerFactoryTest, MakeLinearOutputStream) {
87 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LINEAR,
88 kTestChannelLayout, kTestSampleRate,
89 kTestBitDepth, kTestFramesPerBuffer);
90 EXPECT_CALL(mock_audio_stream_provider_, MakeOutputStream(testing::_));
91
92 // Note that the empty string must be passed in to select the default device.
93 audio_manager_->MakeAudioOutputStream(params, "");
94 }
95
96 // Verifies that creating a low-latency output stream invokes MakeOutputStream
97 // in
98 // the provided CastAudioStreamProvider instance.
99 TEST_F(CastAudioManagerFactoryTest, MakeLowLatencyOutputStream) {
100 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
101 kTestChannelLayout, kTestSampleRate,
102 kTestBitDepth, kTestFramesPerBuffer);
103 EXPECT_CALL(mock_audio_stream_provider_, MakeOutputStream(testing::_));
104 audio_manager_->MakeAudioOutputStream(params, kTestDeviceId);
105 }
106
107 } // namespace
108 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698