OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/environment.h" | 5 #include "base/environment.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "media/audio/audio_manager.h" | 8 #include "media/audio/audio_manager.h" |
9 #include "media/audio/audio_manager_base.h" | 9 #include "media/audio/audio_manager_base.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 #if defined(OS_LINUX) | 12 #if defined(OS_LINUX) |
13 #include "media/audio/linux/audio_manager_linux.h" | 13 #include "media/audio/linux/audio_manager_linux.h" |
14 #endif // defined(OS_LINUX) | 14 #endif // defined(OS_LINUX) |
15 | 15 |
16 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
17 #include "base/win/scoped_com_initializer.h" | 17 #include "base/win/scoped_com_initializer.h" |
18 #include "media/audio/win/audio_manager_win.h" | 18 #include "media/audio/win/audio_manager_win.h" |
19 #include "media/audio/win/wavein_input_win.h" | 19 #include "media/audio/win/wavein_input_win.h" |
20 #endif | 20 #endif |
21 | 21 |
22 #if defined(USE_PULSEAUDIO) | 22 #if defined(USE_PULSEAUDIO) |
23 #include "media/audio/pulse/audio_manager_pulse.h" | 23 #include "media/audio/pulse/audio_manager_pulse.h" |
24 #endif // defined(USE_PULSEAUDIO) | 24 #endif // defined(USE_PULSEAUDIO) |
25 | 25 |
26 namespace media { | 26 namespace media { |
27 | 27 |
28 // Test fixture which allows us to override the default enumeration API on | 28 // Test fixture which allows us to override the default enumeration API on |
29 // Windows. | 29 // Windows. |
30 class AudioInputDeviceTest | 30 class AudioManagerTest |
31 : public ::testing::Test { | 31 : public ::testing::Test { |
32 protected: | 32 protected: |
33 AudioInputDeviceTest() | 33 AudioManagerTest() |
34 : audio_manager_(AudioManager::Create()) | 34 : audio_manager_(AudioManager::Create()) |
35 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
36 , com_init_(base::win::ScopedCOMInitializer::kMTA) | 36 , com_init_(base::win::ScopedCOMInitializer::kMTA) |
37 #endif | 37 #endif |
38 { | 38 { |
39 } | 39 } |
40 | 40 |
41 #if defined(OS_WIN) | 41 #if defined(OS_WIN) |
42 bool SetMMDeviceEnumeration() { | 42 bool SetMMDeviceEnumeration() { |
43 AudioManagerWin* amw = static_cast<AudioManagerWin*>(audio_manager_.get()); | 43 AudioManagerWin* amw = static_cast<AudioManagerWin*>(audio_manager_.get()); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 113 |
114 scoped_ptr<AudioManager> audio_manager_; | 114 scoped_ptr<AudioManager> audio_manager_; |
115 | 115 |
116 #if defined(OS_WIN) | 116 #if defined(OS_WIN) |
117 // The MMDevice API requires COM to be initialized on the current thread. | 117 // The MMDevice API requires COM to be initialized on the current thread. |
118 base::win::ScopedCOMInitializer com_init_; | 118 base::win::ScopedCOMInitializer com_init_; |
119 #endif | 119 #endif |
120 }; | 120 }; |
121 | 121 |
122 // Test that devices can be enumerated. | 122 // Test that devices can be enumerated. |
123 TEST_F(AudioInputDeviceTest, EnumerateInputDevices) { | 123 TEST_F(AudioManagerTest, EnumerateInputDevices) { |
124 if (!CanRunInputTest()) | 124 if (!CanRunInputTest()) |
125 return; | 125 return; |
126 | 126 |
127 AudioDeviceNames device_names; | 127 AudioDeviceNames device_names; |
128 audio_manager_->GetAudioInputDeviceNames(&device_names); | 128 audio_manager_->GetAudioInputDeviceNames(&device_names); |
129 CheckDeviceNames(device_names); | 129 CheckDeviceNames(device_names); |
130 } | 130 } |
131 | 131 |
132 // Test that devices can be enumerated. | 132 // Test that devices can be enumerated. |
133 TEST_F(AudioInputDeviceTest, EnumerateOutputDevices) { | 133 TEST_F(AudioManagerTest, EnumerateOutputDevices) { |
134 if (!CanRunOutputTest()) | 134 if (!CanRunOutputTest()) |
135 return; | 135 return; |
136 | 136 |
137 AudioDeviceNames device_names; | 137 AudioDeviceNames device_names; |
138 audio_manager_->GetAudioOutputDeviceNames(&device_names); | 138 audio_manager_->GetAudioOutputDeviceNames(&device_names); |
139 CheckDeviceNames(device_names); | 139 CheckDeviceNames(device_names); |
140 } | 140 } |
141 | 141 |
142 // Run additional tests for Windows since enumeration can be done using | 142 // Run additional tests for Windows since enumeration can be done using |
143 // two different APIs. MMDevice is default for Vista and higher and Wave | 143 // two different APIs. MMDevice is default for Vista and higher and Wave |
144 // is default for XP and lower. | 144 // is default for XP and lower. |
145 #if defined(OS_WIN) | 145 #if defined(OS_WIN) |
146 | 146 |
147 // Override default enumeration API and force usage of Windows MMDevice. | 147 // Override default enumeration API and force usage of Windows MMDevice. |
148 // This test will only run on Windows Vista and higher. | 148 // This test will only run on Windows Vista and higher. |
149 TEST_F(AudioInputDeviceTest, EnumerateInputDevicesWinMMDevice) { | 149 TEST_F(AudioManagerTest, EnumerateInputDevicesWinMMDevice) { |
150 if (!CanRunInputTest()) | 150 if (!CanRunInputTest()) |
151 return; | 151 return; |
152 | 152 |
153 AudioDeviceNames device_names; | 153 AudioDeviceNames device_names; |
154 if (!SetMMDeviceEnumeration()) { | 154 if (!SetMMDeviceEnumeration()) { |
155 // Usage of MMDevice will fail on XP and lower. | 155 // Usage of MMDevice will fail on XP and lower. |
156 LOG(WARNING) << "MM device enumeration is not supported."; | 156 LOG(WARNING) << "MM device enumeration is not supported."; |
157 return; | 157 return; |
158 } | 158 } |
159 audio_manager_->GetAudioInputDeviceNames(&device_names); | 159 audio_manager_->GetAudioInputDeviceNames(&device_names); |
160 CheckDeviceNames(device_names); | 160 CheckDeviceNames(device_names); |
161 } | 161 } |
162 | 162 |
163 TEST_F(AudioInputDeviceTest, EnumerateOutputDevicesWinMMDevice) { | 163 TEST_F(AudioManagerTest, EnumerateOutputDevicesWinMMDevice) { |
164 if (!CanRunOutputTest()) | 164 if (!CanRunOutputTest()) |
165 return; | 165 return; |
166 | 166 |
167 AudioDeviceNames device_names; | 167 AudioDeviceNames device_names; |
168 if (!SetMMDeviceEnumeration()) { | 168 if (!SetMMDeviceEnumeration()) { |
169 // Usage of MMDevice will fail on XP and lower. | 169 // Usage of MMDevice will fail on XP and lower. |
170 LOG(WARNING) << "MM device enumeration is not supported."; | 170 LOG(WARNING) << "MM device enumeration is not supported."; |
171 return; | 171 return; |
172 } | 172 } |
173 audio_manager_->GetAudioOutputDeviceNames(&device_names); | 173 audio_manager_->GetAudioOutputDeviceNames(&device_names); |
174 CheckDeviceNames(device_names); | 174 CheckDeviceNames(device_names); |
175 } | 175 } |
176 | 176 |
177 // Override default enumeration API and force usage of Windows Wave. | 177 // Override default enumeration API and force usage of Windows Wave. |
178 // This test will run on Windows XP, Windows Vista and Windows 7. | 178 // This test will run on Windows XP, Windows Vista and Windows 7. |
179 TEST_F(AudioInputDeviceTest, EnumerateInputDevicesWinWave) { | 179 TEST_F(AudioManagerTest, EnumerateInputDevicesWinWave) { |
180 if (!CanRunInputTest()) | 180 if (!CanRunInputTest()) |
181 return; | 181 return; |
182 | 182 |
183 AudioDeviceNames device_names; | 183 AudioDeviceNames device_names; |
184 SetWaveEnumeration(); | 184 SetWaveEnumeration(); |
185 audio_manager_->GetAudioInputDeviceNames(&device_names); | 185 audio_manager_->GetAudioInputDeviceNames(&device_names); |
186 CheckDeviceNames(device_names); | 186 CheckDeviceNames(device_names); |
187 } | 187 } |
188 | 188 |
189 TEST_F(AudioInputDeviceTest, EnumerateOutputDevicesWinWave) { | 189 TEST_F(AudioManagerTest, EnumerateOutputDevicesWinWave) { |
190 if (!CanRunOutputTest()) | 190 if (!CanRunOutputTest()) |
191 return; | 191 return; |
192 | 192 |
193 AudioDeviceNames device_names; | 193 AudioDeviceNames device_names; |
194 SetWaveEnumeration(); | 194 SetWaveEnumeration(); |
195 audio_manager_->GetAudioOutputDeviceNames(&device_names); | 195 audio_manager_->GetAudioOutputDeviceNames(&device_names); |
196 CheckDeviceNames(device_names); | 196 CheckDeviceNames(device_names); |
197 } | 197 } |
198 | 198 |
199 TEST_F(AudioInputDeviceTest, WinXPDeviceIdUnchanged) { | 199 TEST_F(AudioManagerTest, WinXPDeviceIdUnchanged) { |
200 if (!CanRunInputTest()) | 200 if (!CanRunInputTest()) |
201 return; | 201 return; |
202 | 202 |
203 AudioDeviceNames xp_device_names; | 203 AudioDeviceNames xp_device_names; |
204 SetWaveEnumeration(); | 204 SetWaveEnumeration(); |
205 audio_manager_->GetAudioInputDeviceNames(&xp_device_names); | 205 audio_manager_->GetAudioInputDeviceNames(&xp_device_names); |
206 CheckDeviceNames(xp_device_names); | 206 CheckDeviceNames(xp_device_names); |
207 | 207 |
208 // Device ID should remain unchanged, including the default device ID. | 208 // Device ID should remain unchanged, including the default device ID. |
209 for (AudioDeviceNames::iterator i = xp_device_names.begin(); | 209 for (AudioDeviceNames::iterator i = xp_device_names.begin(); |
210 i != xp_device_names.end(); ++i) { | 210 i != xp_device_names.end(); ++i) { |
211 EXPECT_EQ(i->unique_id, | 211 EXPECT_EQ(i->unique_id, |
212 GetDeviceIdFromPCMWaveInAudioInputStream(i->unique_id)); | 212 GetDeviceIdFromPCMWaveInAudioInputStream(i->unique_id)); |
213 } | 213 } |
214 } | 214 } |
215 | 215 |
216 TEST_F(AudioInputDeviceTest, ConvertToWinXPInputDeviceId) { | 216 TEST_F(AudioManagerTest, ConvertToWinXPInputDeviceId) { |
217 if (!CanRunInputTest()) | 217 if (!CanRunInputTest()) |
218 return; | 218 return; |
219 | 219 |
220 if (!SetMMDeviceEnumeration()) { | 220 if (!SetMMDeviceEnumeration()) { |
221 // Usage of MMDevice will fail on XP and lower. | 221 // Usage of MMDevice will fail on XP and lower. |
222 LOG(WARNING) << "MM device enumeration is not supported."; | 222 LOG(WARNING) << "MM device enumeration is not supported."; |
223 return; | 223 return; |
224 } | 224 } |
225 | 225 |
226 AudioDeviceNames device_names; | 226 AudioDeviceNames device_names; |
(...skipping 16 matching lines...) Expand all Loading... |
243 } | 243 } |
244 } | 244 } |
245 | 245 |
246 #endif // defined(OS_WIN) | 246 #endif // defined(OS_WIN) |
247 | 247 |
248 #if defined(USE_PULSEAUDIO) | 248 #if defined(USE_PULSEAUDIO) |
249 // On Linux, there are two implementations available and both can | 249 // On Linux, there are two implementations available and both can |
250 // sometimes be tested on a single system. These tests specifically | 250 // sometimes be tested on a single system. These tests specifically |
251 // test Pulseaudio. | 251 // test Pulseaudio. |
252 | 252 |
253 TEST_F(AudioInputDeviceTest, EnumerateInputDevicesPulseaudio) { | 253 TEST_F(AudioManagerTest, EnumerateInputDevicesPulseaudio) { |
254 if (!CanRunInputTest()) | 254 if (!CanRunInputTest()) |
255 return; | 255 return; |
256 | 256 |
257 audio_manager_.reset(AudioManagerPulse::Create()); | 257 audio_manager_.reset(AudioManagerPulse::Create()); |
258 if (audio_manager_.get()) { | 258 if (audio_manager_.get()) { |
259 AudioDeviceNames device_names; | 259 AudioDeviceNames device_names; |
260 audio_manager_->GetAudioInputDeviceNames(&device_names); | 260 audio_manager_->GetAudioInputDeviceNames(&device_names); |
261 CheckDeviceNames(device_names); | 261 CheckDeviceNames(device_names); |
262 } else { | 262 } else { |
263 LOG(WARNING) << "No pulseaudio on this system."; | 263 LOG(WARNING) << "No pulseaudio on this system."; |
264 } | 264 } |
265 } | 265 } |
266 | 266 |
267 TEST_F(AudioInputDeviceTest, EnumerateOutputDevicesPulseaudio) { | 267 TEST_F(AudioManagerTest, EnumerateOutputDevicesPulseaudio) { |
268 if (!CanRunOutputTest()) | 268 if (!CanRunOutputTest()) |
269 return; | 269 return; |
270 | 270 |
271 audio_manager_.reset(AudioManagerPulse::Create()); | 271 audio_manager_.reset(AudioManagerPulse::Create()); |
272 if (audio_manager_.get()) { | 272 if (audio_manager_.get()) { |
273 AudioDeviceNames device_names; | 273 AudioDeviceNames device_names; |
274 audio_manager_->GetAudioOutputDeviceNames(&device_names); | 274 audio_manager_->GetAudioOutputDeviceNames(&device_names); |
275 CheckDeviceNames(device_names); | 275 CheckDeviceNames(device_names); |
276 } else { | 276 } else { |
277 LOG(WARNING) << "No pulseaudio on this system."; | 277 LOG(WARNING) << "No pulseaudio on this system."; |
278 } | 278 } |
279 } | 279 } |
280 #endif // defined(USE_PULSEAUDIO) | 280 #endif // defined(USE_PULSEAUDIO) |
281 | 281 |
282 #if defined(USE_ALSA) | 282 #if defined(USE_ALSA) |
283 // On Linux, there are two implementations available and both can | 283 // On Linux, there are two implementations available and both can |
284 // sometimes be tested on a single system. These tests specifically | 284 // sometimes be tested on a single system. These tests specifically |
285 // test Alsa. | 285 // test Alsa. |
286 | 286 |
287 TEST_F(AudioInputDeviceTest, EnumerateInputDevicesAlsa) { | 287 TEST_F(AudioManagerTest, EnumerateInputDevicesAlsa) { |
288 if (!CanRunInputTest()) | 288 if (!CanRunInputTest()) |
289 return; | 289 return; |
290 | 290 |
291 VLOG(2) << "Testing AudioManagerLinux."; | 291 VLOG(2) << "Testing AudioManagerLinux."; |
292 audio_manager_.reset(new AudioManagerLinux()); | 292 audio_manager_.reset(new AudioManagerLinux()); |
293 AudioDeviceNames device_names; | 293 AudioDeviceNames device_names; |
294 audio_manager_->GetAudioInputDeviceNames(&device_names); | 294 audio_manager_->GetAudioInputDeviceNames(&device_names); |
295 CheckDeviceNames(device_names); | 295 CheckDeviceNames(device_names); |
296 } | 296 } |
297 | 297 |
298 TEST_F(AudioInputDeviceTest, EnumerateOutputDevicesAlsa) { | 298 TEST_F(AudioManagerTest, EnumerateOutputDevicesAlsa) { |
299 if (!CanRunOutputTest()) | 299 if (!CanRunOutputTest()) |
300 return; | 300 return; |
301 | 301 |
302 VLOG(2) << "Testing AudioManagerLinux."; | 302 VLOG(2) << "Testing AudioManagerLinux."; |
303 audio_manager_.reset(new AudioManagerLinux()); | 303 audio_manager_.reset(new AudioManagerLinux()); |
304 AudioDeviceNames device_names; | 304 AudioDeviceNames device_names; |
305 audio_manager_->GetAudioOutputDeviceNames(&device_names); | 305 audio_manager_->GetAudioOutputDeviceNames(&device_names); |
306 CheckDeviceNames(device_names); | 306 CheckDeviceNames(device_names); |
307 } | 307 } |
308 #endif // defined(USE_ALSA) | 308 #endif // defined(USE_ALSA) |
309 | 309 |
310 TEST_F(AudioInputDeviceTest, GetDefaultOutputStreamParameters) { | 310 TEST_F(AudioManagerTest, GetDefaultOutputStreamParameters) { |
311 #if defined(OS_WIN) || defined(OS_MACOSX) | 311 #if defined(OS_WIN) || defined(OS_MACOSX) |
312 if (!CanRunInputTest()) | 312 if (!CanRunInputTest()) |
313 return; | 313 return; |
314 | 314 |
315 AudioParameters params = audio_manager_->GetDefaultOutputStreamParameters(); | 315 AudioParameters params = audio_manager_->GetDefaultOutputStreamParameters(); |
316 EXPECT_TRUE(params.IsValid()); | 316 EXPECT_TRUE(params.IsValid()); |
317 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 317 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
318 } | 318 } |
319 | 319 |
320 TEST_F(AudioInputDeviceTest, GetAssociatedOutputDeviceID) { | 320 TEST_F(AudioManagerTest, GetAssociatedOutputDeviceID) { |
321 #if defined(OS_WIN) || defined(OS_MACOSX) | 321 #if defined(OS_WIN) || defined(OS_MACOSX) |
322 if (!CanRunInputTest() || !CanRunOutputTest()) | 322 if (!CanRunInputTest() || !CanRunOutputTest()) |
323 return; | 323 return; |
324 | 324 |
325 AudioDeviceNames device_names; | 325 AudioDeviceNames device_names; |
326 audio_manager_->GetAudioInputDeviceNames(&device_names); | 326 audio_manager_->GetAudioInputDeviceNames(&device_names); |
327 bool found_an_associated_device = false; | 327 bool found_an_associated_device = false; |
328 for (AudioDeviceNames::iterator it = device_names.begin(); | 328 for (AudioDeviceNames::iterator it = device_names.begin(); |
329 it != device_names.end(); | 329 it != device_names.end(); |
330 ++it) { | 330 ++it) { |
331 EXPECT_FALSE(it->unique_id.empty()); | 331 EXPECT_FALSE(it->unique_id.empty()); |
332 EXPECT_FALSE(it->device_name.empty()); | 332 EXPECT_FALSE(it->device_name.empty()); |
333 std::string output_device_id( | 333 std::string output_device_id( |
334 audio_manager_->GetAssociatedOutputDeviceID(it->unique_id)); | 334 audio_manager_->GetAssociatedOutputDeviceID(it->unique_id)); |
335 if (!output_device_id.empty()) { | 335 if (!output_device_id.empty()) { |
336 VLOG(2) << it->unique_id << " matches with " << output_device_id; | 336 VLOG(2) << it->unique_id << " matches with " << output_device_id; |
337 found_an_associated_device = true; | 337 found_an_associated_device = true; |
338 } | 338 } |
339 } | 339 } |
340 | 340 |
341 EXPECT_TRUE(found_an_associated_device); | 341 EXPECT_TRUE(found_an_associated_device); |
342 #endif // defined(OS_WIN) || defined(OS_MACOSX) | 342 #endif // defined(OS_WIN) || defined(OS_MACOSX) |
343 } | 343 } |
344 | 344 |
345 } // namespace media | 345 } // namespace media |
OLD | NEW |