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

Side by Side 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: 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:39 Done.
6 #include "base/logging.h"
7 #include "base/test/mock_log.h"
8 #include "chromecast/media/audio/cast_audio_manager.h"
9 #include "chromecast/media/audio/cast_audio_manager_factory.h"
10 #include "chromecast/public/cast_audio_output_device.h"
11 #include "chromecast/public/cast_audio_stream.h"
12 #include "media/audio/audio_manager.h"
13 #include "media/audio/fake_audio_log_factory.h"
14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace chromecast {
18 namespace {
19
20 // Makes reading the syntax prettier.
21 using testing::_;
22
23 // Testing constants.
24 const int kTestBitDepth = 16;
25 const auto kTestChannelLayout = media::ChannelLayout::CHANNEL_LAYOUT_STEREO;
26 const char kTestDeviceId[] = "test_device_id";
27 const int kTestFramesPerBuffer = 1024;
28 const int kTestSampleRate = 48000;
29
30 // A stubbed-out output stream.
31 class FakeCastAudioOutputStream : public CastAudioOutputStream {
32 public:
33 FakeCastAudioOutputStream() {}
34 ~FakeCastAudioOutputStream() override {}
35
36 // CastAudioOutputStream implementation:
37 bool Open() override { return true; }
38 void Start(AudioSourceCallback* callback) override {}
39 void Stop() override {}
40 void SetVolume(double volume) override {}
41 void GetVolume(double* volume) override {}
42 void Close() override {}
43 };
44
45 // A fake audio output device. This takes the place of a platform specific
46 // implementation.
47 class FakeCastAudioOutputDevice : public CastAudioOutputDevice {
48 public:
49 FakeCastAudioOutputDevice() : null_stream_(false) {}
50 ~FakeCastAudioOutputDevice() override {}
51
52 // Pass in true to return a nullptr when MakeOutputStream is called.
53 void set_null_stream(bool null_stream) { null_stream_ = null_stream; }
54
55 // AudioOutputDevice implementation:
56 int GetMaximumOutputStreamsAllowed() const override { return 1; }
57
58 AudioParameters GetPreferredOutputStreamParameters(
59 const AudioParameters& suggested) const override {
60 return suggested;
61 }
62
63 CastAudioOutputStream* MakeOutputStream(
64 const AudioParameters& params) override {
65 if (null_stream_)
66 return nullptr;
67
68 // Return a fake stream.
69 output_stream_.reset(new FakeCastAudioOutputStream());
70 return output_stream_.get();
71 }
72
73 private:
74 bool null_stream_;
75 scoped_ptr<CastAudioOutputStream> output_stream_;
76 };
77
78 // The testbed for this suite of tests.
79 class CastAudioManagerTest : public testing::Test {
80 protected:
81 CastAudioManagerTest() {}
82 ~CastAudioManagerTest() override {}
83
84 void SetUp() override {
85 audio_manager_.reset(
86 new CastAudioManager(&log_factory_, &audio_output_device_));
87 }
88
89 // Constructor parameters are fakes.
90 media::FakeAudioLogFactory log_factory_;
91 FakeCastAudioOutputDevice audio_output_device_;
92
93 // Class being tested.
94 scoped_ptr<CastAudioManager> audio_manager_;
95 };
96
97 TEST_F(CastAudioManagerTest, HasAudioOutputDevices) {
98 EXPECT_TRUE(audio_manager_->HasAudioOutputDevices());
99 }
100
101 TEST_F(CastAudioManagerTest, HasAudioInputDevices) {
102 EXPECT_FALSE(audio_manager_->HasAudioInputDevices());
103 }
104
105 TEST_F(CastAudioManagerTest, ShowAudioInputSettings) {
106 base::test::MockLog log;
107 log.StartCapturingLogs();
108 EXPECT_CALL(log, Log(logging::LOG_WARNING, _, _, _, _));
109 audio_manager_->ShowAudioInputSettings();
110 }
111
112 TEST_F(CastAudioManagerTest, GetAudioInputDeviceNames) {
113 base::test::MockLog log;
114 log.StartCapturingLogs();
115 EXPECT_CALL(log, Log(logging::LOG_WARNING, _, _, _, _));
116 media::AudioDeviceNames device_names;
117 audio_manager_->GetAudioInputDeviceNames(&device_names);
118 }
119
120 TEST_F(CastAudioManagerTest, GetInputStreamParameters) {
121 base::test::MockLog log;
122 log.StartCapturingLogs();
123 EXPECT_CALL(log, Log(logging::LOG_WARNING, _, _, _, _));
124 audio_manager_->GetInputStreamParameters(kTestDeviceId);
125 }
126
127 TEST_F(CastAudioManagerTest, GetPreferredOutputStreamParameters) {
128 // Create the parameters.
129 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LINEAR,
130 kTestChannelLayout, kTestSampleRate,
131 kTestBitDepth, kTestFramesPerBuffer);
132
133 media::AudioParameters params_out =
134 audio_manager_->GetPreferredOutputStreamParameters("", params);
135 ASSERT_TRUE(params.Equals(params_out));
136 }
137
138 TEST_F(CastAudioManagerTest, MakeLinearOutputStream) {
139 // Create the parameters.
140 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LINEAR,
141 kTestChannelLayout, kTestSampleRate,
142 kTestBitDepth, kTestFramesPerBuffer);
143
144 // Test that a returned null stream trickles all the way up.
145 audio_output_device_.set_null_stream(true);
146 media::AudioOutputStream* stream =
147 audio_manager_->MakeLinearOutputStream(params);
148 EXPECT_EQ(nullptr, stream);
149
150 // Test that a non-null stream returns successfully.
151 audio_output_device_.set_null_stream(false);
152 stream = audio_manager_->MakeLinearOutputStream(params);
153 EXPECT_NE(nullptr, stream);
154 }
155
156 TEST_F(CastAudioManagerTest, MakeLowLatencyOutputStream) {
157 // Create the parameters.
158 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
159 kTestChannelLayout, kTestSampleRate,
160 kTestBitDepth, kTestFramesPerBuffer);
161
162 // Test that a returned null stream trickles all the way up.
163 audio_output_device_.set_null_stream(true);
164 media::AudioOutputStream* stream =
165 audio_manager_->MakeLowLatencyOutputStream(params, kTestDeviceId);
166 EXPECT_EQ(nullptr, stream);
167
168 // Test that a non-null stream returns successfully.
169 audio_output_device_.set_null_stream(false);
170 stream = audio_manager_->MakeLowLatencyOutputStream(params, kTestDeviceId);
171 EXPECT_NE(nullptr, stream);
172 }
173
174 TEST_F(CastAudioManagerTest, MakeLinearInputStream) {
175 base::test::MockLog log;
176 log.StartCapturingLogs();
177 EXPECT_CALL(log, Log(logging::LOG_WARNING, _, _, _, _)).Times(2);
178
179 // Create the parameters.
180 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LINEAR,
181 kTestChannelLayout, kTestSampleRate,
182 kTestBitDepth, kTestFramesPerBuffer);
183
184 // Test that the returned stream is always null.
185 audio_output_device_.set_null_stream(true);
186 media::AudioInputStream* stream =
187 audio_manager_->MakeLinearInputStream(params, kTestDeviceId);
188 EXPECT_EQ(nullptr, stream);
189
190 audio_output_device_.set_null_stream(false);
191 stream = audio_manager_->MakeLinearInputStream(params, kTestDeviceId);
192 EXPECT_EQ(nullptr, stream);
193 }
194
195 TEST_F(CastAudioManagerTest, MakeLowLatencyInputStream) {
196 base::test::MockLog log;
197 log.StartCapturingLogs();
198 EXPECT_CALL(log, Log(logging::LOG_WARNING, _, _, _, _)).Times(2);
199
200 // Create the parameters.
201 media::AudioParameters params(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
202 kTestChannelLayout, kTestSampleRate,
203 kTestBitDepth, kTestFramesPerBuffer);
204
205 // Test that a the returned stream is always null.
206 audio_output_device_.set_null_stream(true);
207 media::AudioInputStream* stream =
208 audio_manager_->MakeLowLatencyInputStream(params, kTestDeviceId);
209 EXPECT_EQ(nullptr, stream);
210
211 audio_output_device_.set_null_stream(false);
212 stream = audio_manager_->MakeLowLatencyInputStream(params, kTestDeviceId);
213 EXPECT_EQ(nullptr, stream);
214 }
215
216 } // namespace
217 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698