| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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 "base/logging.h" | |
| 6 #include "base/memory/scoped_ptr.h" | |
| 7 #include "media/audio/audio_manager.h" | |
| 8 #include "testing/gtest/include/gtest/gtest.h" | |
| 9 | |
| 10 #if defined(OS_LINUX) | |
| 11 #include "media/audio/linux/audio_manager_linux.h" | |
| 12 #endif // defined(OS_LINUX) | |
| 13 | |
| 14 #if defined(OS_WIN) | |
| 15 #include "media/audio/win/audio_manager_win.h" | |
| 16 #endif // defined(OS_WIN) | |
| 17 | |
| 18 #if defined(USE_PULSEAUDIO) | |
| 19 #include "media/audio/pulse/audio_manager_pulse.h" | |
| 20 #endif // defined(USE_PULSEAUDIO) | |
| 21 | |
| 22 namespace media { | |
| 23 | |
| 24 void GetAudioOutputDeviceNamesImpl(AudioManager* audio_manager) { | |
| 25 AudioDeviceNames device_names; | |
| 26 audio_manager->GetAudioOutputDeviceNames(&device_names); | |
| 27 | |
| 28 VLOG(2) << "Got " << device_names.size() << " audio output devices."; | |
| 29 for (AudioDeviceNames::iterator it = device_names.begin(); | |
| 30 it != device_names.end(); | |
| 31 ++it) { | |
| 32 EXPECT_FALSE(it->unique_id.empty()); | |
| 33 EXPECT_FALSE(it->device_name.empty()); | |
| 34 VLOG(2) << "Device ID(" << it->unique_id << "), label: " << it->device_name; | |
| 35 } | |
| 36 } | |
| 37 | |
| 38 // So that tests herein can be friends of AudioManagerWin. | |
| 39 // | |
| 40 // TODO(joi): Make this go away by unifying audio_manager_unittest.cc | |
| 41 // and audio_input_device_unittest.cc | |
| 42 class AudioManagerTest : public ::testing::Test { | |
| 43 public: | |
| 44 bool SetupForSecondTest(AudioManager* amw) { | |
| 45 #if defined(OS_WIN) | |
| 46 AudioManagerWin* audio_manager_win = static_cast<AudioManagerWin*>(amw); | |
| 47 if (audio_manager_win->enumeration_type() == | |
| 48 AudioManagerWin::kWaveEnumeration) { | |
| 49 // This will be true only if running on Windows XP. | |
| 50 VLOG(2) << "AudioManagerWin on WinXP; nothing more to test."; | |
| 51 } else { | |
| 52 VLOG(2) << "Testing AudioManagerWin in fallback WinXP mode."; | |
| 53 audio_manager_win->SetEnumerationType(AudioManagerWin::kWaveEnumeration); | |
| 54 return true; | |
| 55 } | |
| 56 #endif // defined(OS_WIN) | |
| 57 return false; | |
| 58 } | |
| 59 }; | |
| 60 | |
| 61 TEST_F(AudioManagerTest, GetAudioOutputDeviceNames) { | |
| 62 // On Linux, we may be able to test both the Alsa and Pulseaudio | |
| 63 // versions of the audio manager. | |
| 64 #if defined(USE_PULSEAUDIO) | |
| 65 { | |
| 66 VLOG(2) << "Testing AudioManagerPulse."; | |
| 67 scoped_ptr<AudioManager> pulse_audio_manager(AudioManagerPulse::Create()); | |
| 68 if (pulse_audio_manager.get()) | |
| 69 GetAudioOutputDeviceNamesImpl(pulse_audio_manager.get()); | |
| 70 else | |
| 71 LOG(WARNING) << "No pulseaudio on this system."; | |
| 72 } | |
| 73 #endif // defined(USE_PULSEAUDIO) | |
| 74 #if defined(USE_ALSA) | |
| 75 { | |
| 76 VLOG(2) << "Testing AudioManagerLinux."; | |
| 77 scoped_ptr<AudioManager> alsa_audio_manager(new AudioManagerLinux()); | |
| 78 GetAudioOutputDeviceNamesImpl(alsa_audio_manager.get()); | |
| 79 } | |
| 80 #endif // defined(USE_ALSA) | |
| 81 | |
| 82 #if defined(OS_MACOSX) | |
| 83 VLOG(2) << "Testing platform-default AudioManager."; | |
| 84 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | |
| 85 GetAudioOutputDeviceNamesImpl(audio_manager.get()); | |
| 86 #endif // defined(OS_MACOSX) | |
| 87 | |
| 88 #if defined(OS_WIN) | |
| 89 { | |
| 90 // TODO(joi): Unify the tests in audio_input_device_unittest.cc | |
| 91 // with the tests in this file, and reuse the Windows-specific | |
| 92 // bits from that file. | |
| 93 VLOG(2) << "Testing AudioManagerWin in its default mode."; | |
| 94 scoped_ptr<AudioManager> audio_manager_win(AudioManager::Create()); | |
| 95 GetAudioOutputDeviceNamesImpl(audio_manager_win.get()); | |
| 96 | |
| 97 if (SetupForSecondTest(audio_manager_win.get())) { | |
| 98 GetAudioOutputDeviceNamesImpl(audio_manager_win.get()); | |
| 99 } | |
| 100 } | |
| 101 #endif // defined(OS_WIN) | |
| 102 } | |
| 103 | |
| 104 TEST_F(AudioManagerTest, GetDefaultOutputStreamParameters) { | |
| 105 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 106 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | |
| 107 ASSERT_TRUE(audio_manager); | |
| 108 if (!audio_manager->HasAudioOutputDevices()) | |
| 109 return; | |
| 110 | |
| 111 AudioParameters params = audio_manager->GetDefaultOutputStreamParameters(); | |
| 112 EXPECT_TRUE(params.IsValid()); | |
| 113 #endif // defined(OS_WIN) || defined(OS_MACOSX) | |
| 114 } | |
| 115 | |
| 116 TEST_F(AudioManagerTest, GetAssociatedOutputDeviceID) { | |
| 117 #if defined(OS_WIN) || defined(OS_MACOSX) | |
| 118 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | |
| 119 ASSERT_TRUE(audio_manager); | |
| 120 if (!audio_manager->HasAudioOutputDevices() || | |
| 121 !audio_manager->HasAudioInputDevices()) { | |
| 122 return; | |
| 123 } | |
| 124 | |
| 125 AudioDeviceNames device_names; | |
| 126 audio_manager->GetAudioInputDeviceNames(&device_names); | |
| 127 bool found_an_associated_device = false; | |
| 128 for (AudioDeviceNames::iterator it = device_names.begin(); | |
| 129 it != device_names.end(); | |
| 130 ++it) { | |
| 131 EXPECT_FALSE(it->unique_id.empty()); | |
| 132 EXPECT_FALSE(it->device_name.empty()); | |
| 133 std::string output_device_id( | |
| 134 audio_manager->GetAssociatedOutputDeviceID(it->unique_id)); | |
| 135 if (!output_device_id.empty()) { | |
| 136 VLOG(2) << it->unique_id << " matches with " << output_device_id; | |
| 137 found_an_associated_device = true; | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 EXPECT_TRUE(found_an_associated_device); | |
| 142 #endif // defined(OS_WIN) || defined(OS_MACOSX) | |
| 143 } | |
| 144 | |
| 145 } // namespace media | |
| OLD | NEW |