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

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

Powered by Google App Engine
This is Rietveld 408576698