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

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: 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 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>
halliwell 2015/04/24 15:04:47 insert blank line
slan 2015/04/24 16:19:38 Done.
6 #include "chromecast/media/audio/cast_audio_manager_factory.h"
7 #include "chromecast/public/cast_audio_output_device.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 CastAudioOutputDevice.
23 class MockCastAudioOutputDevice : public chromecast::CastAudioOutputDevice {
24 public:
25 MockCastAudioOutputDevice() {}
26 virtual ~MockCastAudioOutputDevice() {}
27
28 MOCK_CONST_METHOD0(GetMaximumOutputStreamsAllowed, int());
29 MOCK_CONST_METHOD1(GetPreferredOutputStreamParameters,
30 AudioParameters(const AudioParameters&));
31 MOCK_METHOD1(MakeOutputStream,
32 CastAudioOutputStream*(const AudioParameters&));
33
34 private:
35 DISALLOW_COPY_AND_ASSIGN(MockCastAudioOutputDevice);
36 };
37
38 // This test verifies that passing a CastAudioManagerFactory to
39 // media::AudioManager::SetFactory passes requests for audio stream creation
40 // to the underlying CastAudioOutputDevice, in this case a mock. It is
41 // intended to provide code coverage for CastAudioManagerFactory, but does not
42 // provide full coverage for CastAudioManager.
43 class CastAudioManagerFactoryTest : public testing::Test {
44 protected:
45 CastAudioManagerFactoryTest() : audio_manager_(nullptr) {}
46 ~CastAudioManagerFactoryTest() override {}
47
48 void SetUp() override {
49 // Set defaults for AudioParameters object.
50 testing::DefaultValue<chromecast::AudioParameters>::Set(
51 chromecast::AudioParameters());
52
53 // Set the factory. The factory must be reset in TearDown()
54 media::AudioManager::SetFactory(
55 new CastAudioManagerFactory(&mock_audio_output_device_));
56
57 // Create the AudioManager instance and verify it.
58 EXPECT_CALL(mock_audio_output_device_, GetMaximumOutputStreamsAllowed())
59 .WillOnce(testing::Return(1));
60 audio_manager_.reset(media::AudioManager::CreateForTesting());
61 ASSERT_NE(nullptr, audio_manager_.get());
62 }
63
64 void TearDown() override {
65 // This is crucial to not persisting state to other tests on the same gtest
66 // process. All other class members will destruct when this class destructs.
67 media::AudioManager::ResetFactoryForTesting();
68 }
69
70 testing::StrictMock<MockCastAudioOutputDevice> mock_audio_output_device_;
71 scoped_ptr<media::AudioManager> audio_manager_;
72
73 private:
74 DISALLOW_COPY_AND_ASSIGN(CastAudioManagerFactoryTest);
75 };
76
77 // Verifies that the default output stream parameters are obtained from the
78 // provided CastAudioOutputDevice instance.
79 TEST_F(CastAudioManagerFactoryTest, GetPreferredOutputStreamParameters) {
80 EXPECT_CALL(mock_audio_output_device_,
81 GetPreferredOutputStreamParameters(testing::_));
82 audio_manager_->GetDefaultOutputStreamParameters();
83 }
84
85 // Verifies that creating a linear output stream invokes MakeOutputStream in
86 // the provided CastAudioOutputDevice instance.
87 TEST_F(CastAudioManagerFactoryTest, MakeLinearOutputStream) {
88 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LINEAR,
89 kTestChannelLayout, kTestSampleRate,
90 kTestBitDepth, kTestFramesPerBuffer);
91 EXPECT_CALL(mock_audio_output_device_, MakeOutputStream(testing::_));
92
93 // Note that the empty string must be passed in to select the default device.
94 audio_manager_->MakeAudioOutputStream(params, "");
95 }
96
97 // Verifies that creating a low-latency output stream invokes MakeOutputStream
98 // in
99 // the provided CastAudioOutputDevice instance.
100 TEST_F(CastAudioManagerFactoryTest, MakeLowLatencyOutputStream) {
101 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
102 kTestChannelLayout, kTestSampleRate,
103 kTestBitDepth, kTestFramesPerBuffer);
104 EXPECT_CALL(mock_audio_output_device_, MakeOutputStream(testing::_));
105 audio_manager_->MakeAudioOutputStream(params, kTestDeviceId);
106 }
107
108 } // namespace
109 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698