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

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

Powered by Google App Engine
This is Rietveld 408576698