Chromium Code Reviews| Index: media/audio/android/audio_android_unittest.cc |
| diff --git a/media/audio/android/audio_android_unittest.cc b/media/audio/android/audio_android_unittest.cc |
| index 300e1545322feabcb104f35947b66c866404455d..561354a0e34bf32ab1eac797026a418af4bf956c 100644 |
| --- a/media/audio/android/audio_android_unittest.cc |
| +++ b/media/audio/android/audio_android_unittest.cc |
| @@ -84,6 +84,40 @@ static double ExpectedTimeBetweenCallbacks(AudioParameters params) { |
| static_cast<double>(params.sample_rate()))).InMillisecondsF(); |
| } |
| +// Helper method which verifies that the device list starts with a valid |
| +// default record followed by non-default device names. |
|
tommi (sloooow) - chröme
2013/12/10 21:19:11
nit; took me a couple of reads to understand that
henrika (OOO until Aug 14)
2013/12/11 13:16:38
fixed. I was thinking in Pascal ;-)
|
| +static void CheckDeviceNames(const AudioDeviceNames& device_names) { |
| + VLOG(2) << "Got " << device_names.size() << " audio devices."; |
| + if (!device_names.empty()) { |
|
tommi (sloooow) - chröme
2013/12/10 21:19:11
nit: to reduce scopes:
if (device_names.empty())
henrika (OOO until Aug 14)
2013/12/11 13:16:38
Done.
|
| + AudioDeviceNames::const_iterator it = device_names.begin(); |
| + |
| + // The first device in the list should always be the default device. |
| + EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceName), |
| + it->device_name); |
| + EXPECT_EQ(std::string(AudioManagerBase::kDefaultDeviceId), it->unique_id); |
| + ++it; |
| + |
| + // Other devices should have non-empty name and id and should not contain |
| + // default name or id. |
|
tommi (sloooow) - chröme
2013/12/10 21:19:11
good thing to test
henrika (OOO until Aug 14)
2013/12/11 13:16:38
Thx.
|
| + while (it != device_names.end()) { |
| + EXPECT_FALSE(it->device_name.empty()); |
| + EXPECT_FALSE(it->unique_id.empty()); |
| + VLOG(2) << "Device ID(" << it->unique_id |
| + << "), label: " << it->device_name; |
| + EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceName), |
| + it->device_name); |
| + EXPECT_NE(std::string(AudioManagerBase::kDefaultDeviceId), |
| + it->unique_id); |
| + ++it; |
| + } |
| + } else { |
| + // Log a warning so we can see the status on the build bots. No need to |
| + // break the test though since this does successfully test the code and |
| + // some failure cases. |
| + LOG(WARNING) << "No input devices detected"; |
| + } |
| +} |
| + |
| std::ostream& operator<<(std::ostream& os, const AudioParameters& params) { |
| using namespace std; |
| os << endl << "format: " << FormatToString(params.format()) << endl |
| @@ -524,10 +558,40 @@ TEST_F(AudioAndroidTest, IsAudioLowLatencySupported) { |
| : VLOG(0) << "Low latency output is *not* supported"; |
| } |
| +// Verify input device enumeration. |
| +TEST_F(AudioAndroidTest, GetAudioInputDeviceNames) { |
| + AudioManagerAndroid* manager = |
|
tommi (sloooow) - chröme
2013/12/10 21:19:11
Do you need AudioManagerAndroid* or is AudioManage
henrika (OOO until Aug 14)
2013/12/11 13:16:38
My bad. Fixed.
|
| + static_cast<AudioManagerAndroid*>(audio_manager()); |
| + if (!manager->HasAudioInputDevices()) |
| + return; |
| + AudioDeviceNames devices; |
| + manager->GetAudioInputDeviceNames(&devices); |
| + CheckDeviceNames(devices); |
| +} |
| + |
| +// Verify output device enumeration. |
| +TEST_F(AudioAndroidTest, GetAudioOutputDeviceNames) { |
| + AudioManagerAndroid* manager = |
|
tommi (sloooow) - chröme
2013/12/10 21:19:11
AudioManager* enough? These tests seem like valid
henrika (OOO until Aug 14)
2013/12/11 13:16:38
Done.
|
| + static_cast<AudioManagerAndroid*>(audio_manager()); |
| + if (!manager->HasAudioOutputDevices()) |
| + return; |
| + AudioDeviceNames devices; |
| + manager->GetAudioOutputDeviceNames(&devices); |
| + CheckDeviceNames(devices); |
| +} |
| + |
| // Ensure that a default input stream can be created and closed. |
| TEST_F(AudioAndroidTest, CreateAndCloseInputStream) { |
| AudioParameters params = GetDefaultInputStreamParameters(); |
| + const char kInvalidId1[] = "_InVaLiDdEvIcEId_"; |
| AudioInputStream* ais = audio_manager()->MakeAudioInputStream( |
| + params, kInvalidId1); |
| + EXPECT_FALSE(ais); |
| + const char kInvalidId2[] = "192837464"; |
| + ais = audio_manager()->MakeAudioInputStream( |
| + params, kInvalidId2); |
| + EXPECT_FALSE(ais); |
| + ais = audio_manager()->MakeAudioInputStream( |
| params, AudioManagerBase::kDefaultDeviceId); |
| EXPECT_TRUE(ais); |
| ais->Close(); |