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

Side by Side Diff: media/audio/android/audio_android_unittest.cc

Issue 2563653002: Replace AudioManager::GetAudio*DeviceNames with AudioManager::GetAudio*DeviceDescriptions (Closed)
Patch Set: fix for windows Created 4 years 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/android/build_info.h" 9 #include "base/android/build_info.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 86 }
87 87
88 double ExpectedTimeBetweenCallbacks(AudioParameters params) { 88 double ExpectedTimeBetweenCallbacks(AudioParameters params) {
89 return (base::TimeDelta::FromMicroseconds( 89 return (base::TimeDelta::FromMicroseconds(
90 params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond / 90 params.frames_per_buffer() * base::Time::kMicrosecondsPerSecond /
91 static_cast<double>(params.sample_rate()))).InMillisecondsF(); 91 static_cast<double>(params.sample_rate()))).InMillisecondsF();
92 } 92 }
93 93
94 // Helper method which verifies that the device list starts with a valid 94 // Helper method which verifies that the device list starts with a valid
95 // default device name followed by non-default device names. 95 // default device name followed by non-default device names.
96 void CheckDeviceNames(const AudioDeviceNames& device_names) { 96 void CheckDeviceDescriptions(
97 DVLOG(2) << "Got " << device_names.size() << " audio devices."; 97 const AudioDeviceDescriptions& device_descriptions) {
98 if (device_names.empty()) { 98 DVLOG(2) << "Got " << device_descriptions.size() << " audio devices.";
99 if (device_descriptions.empty()) {
99 // Log a warning so we can see the status on the build bots. No need to 100 // Log a warning so we can see the status on the build bots. No need to
100 // break the test though since this does successfully test the code and 101 // break the test though since this does successfully test the code and
101 // some failure cases. 102 // some failure cases.
102 LOG(WARNING) << "No input devices detected"; 103 LOG(WARNING) << "No input devices detected";
103 return; 104 return;
104 } 105 }
105 106
106 AudioDeviceNames::const_iterator it = device_names.begin(); 107 AudioDeviceDescriptions::const_iterator it = device_descriptions.begin();
107 108
108 // The first device in the list should always be the default device. 109 // The first device in the list should always be the default device.
109 EXPECT_EQ(AudioDeviceDescription::GetDefaultDeviceName(), it->device_name); 110 EXPECT_EQ(AudioDeviceDescription::GetDefaultDeviceName(), it->device_name);
110 EXPECT_EQ(std::string(AudioDeviceDescription::kDefaultDeviceId), 111 EXPECT_EQ(std::string(AudioDeviceDescription::kDefaultDeviceId),
111 it->unique_id); 112 it->unique_id);
112 ++it; 113 ++it;
113 114
114 // Other devices should have non-empty name and id and should not contain 115 // Other devices should have non-empty name and id and should not contain
115 // default name or id. 116 // default name or id.
116 while (it != device_names.end()) { 117 while (it != device_descriptions.end()) {
117 EXPECT_FALSE(it->device_name.empty()); 118 EXPECT_FALSE(it->device_name.empty());
118 EXPECT_FALSE(it->unique_id.empty()); 119 EXPECT_FALSE(it->unique_id.empty());
119 DVLOG(2) << "Device ID(" << it->unique_id 120 DVLOG(2) << "Device ID(" << it->unique_id
Guido Urdaneta 2016/12/08 15:53:37 Should you check anything about group ID here?
o1ka 2016/12/09 14:56:30 Done.
120 << "), label: " << it->device_name; 121 << "), label: " << it->device_name;
121 EXPECT_NE(AudioDeviceDescription::GetDefaultDeviceName(), it->device_name); 122 EXPECT_NE(AudioDeviceDescription::GetDefaultDeviceName(), it->device_name);
122 EXPECT_NE(std::string(AudioDeviceDescription::kDefaultDeviceId), 123 EXPECT_NE(std::string(AudioDeviceDescription::kDefaultDeviceId),
123 it->unique_id); 124 it->unique_id);
124 ++it; 125 ++it;
125 } 126 }
126 } 127 }
127 128
128 // We clear the data bus to ensure that the test does not cause noise. 129 // We clear the data bus to ensure that the test does not cause noise.
129 int RealOnMoreData(base::TimeDelta /* delay */, 130 int RealOnMoreData(base::TimeDelta /* delay */,
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 DVLOG(1) << audio_input_parameters(); 733 DVLOG(1) << audio_input_parameters();
733 } 734 }
734 735
735 // Get the default audio output parameters and log the result. 736 // Get the default audio output parameters and log the result.
736 TEST_F(AudioAndroidOutputTest, GetDefaultOutputStreamParameters) { 737 TEST_F(AudioAndroidOutputTest, GetDefaultOutputStreamParameters) {
737 GetDefaultOutputStreamParametersOnAudioThread(); 738 GetDefaultOutputStreamParametersOnAudioThread();
738 DVLOG(1) << audio_output_parameters(); 739 DVLOG(1) << audio_output_parameters();
739 } 740 }
740 741
741 // Verify input device enumeration. 742 // Verify input device enumeration.
742 TEST_F(AudioAndroidInputTest, GetAudioInputDeviceNames) { 743 TEST_F(AudioAndroidInputTest, GetAudioInputDeviceDescriptions) {
743 ABORT_AUDIO_TEST_IF_NOT(audio_manager()->HasAudioInputDevices()); 744 ABORT_AUDIO_TEST_IF_NOT(audio_manager()->HasAudioInputDevices());
744 AudioDeviceNames devices; 745 AudioDeviceDescriptions devices;
745 RunOnAudioThread( 746 RunOnAudioThread(base::Bind(&AudioManager::GetAudioInputDeviceDescriptions,
746 base::Bind(&AudioManager::GetAudioInputDeviceNames, 747 base::Unretained(audio_manager()), &devices));
747 base::Unretained(audio_manager()), 748 CheckDeviceDescriptions(devices);
748 &devices));
749 CheckDeviceNames(devices);
750 } 749 }
751 750
752 // Verify output device enumeration. 751 // Verify output device enumeration.
753 TEST_F(AudioAndroidOutputTest, GetAudioOutputDeviceNames) { 752 TEST_F(AudioAndroidOutputTest, GetAudioOutputDeviceDescriptions) {
754 ABORT_AUDIO_TEST_IF_NOT(audio_manager()->HasAudioOutputDevices()); 753 ABORT_AUDIO_TEST_IF_NOT(audio_manager()->HasAudioOutputDevices());
755 AudioDeviceNames devices; 754 AudioDeviceDescriptions devices;
756 RunOnAudioThread( 755 RunOnAudioThread(base::Bind(&AudioManager::GetAudioOutputDeviceDescriptions,
757 base::Bind(&AudioManager::GetAudioOutputDeviceNames, 756 base::Unretained(audio_manager()), &devices));
758 base::Unretained(audio_manager()), 757 CheckDeviceDescriptions(devices);
759 &devices));
760 CheckDeviceNames(devices);
761 } 758 }
762 759
763 // Ensure that a default input stream can be created and closed. 760 // Ensure that a default input stream can be created and closed.
764 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) { 761 TEST_P(AudioAndroidInputTest, CreateAndCloseInputStream) {
765 AudioParameters params = GetInputStreamParameters(); 762 AudioParameters params = GetInputStreamParameters();
766 MakeAudioInputStreamOnAudioThread(params); 763 MakeAudioInputStreamOnAudioThread(params);
767 RunOnAudioThread( 764 RunOnAudioThread(
768 base::Bind(&AudioInputStream::Close, 765 base::Bind(&AudioInputStream::Close,
769 base::Unretained(audio_input_stream_))); 766 base::Unretained(audio_input_stream_)));
770 } 767 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 printf("\n"); 962 printf("\n");
966 StopAndCloseAudioOutputStreamOnAudioThread(); 963 StopAndCloseAudioOutputStreamOnAudioThread();
967 StopAndCloseAudioInputStreamOnAudioThread(); 964 StopAndCloseAudioInputStreamOnAudioThread();
968 } 965 }
969 966
970 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, 967 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest,
971 AudioAndroidInputTest, 968 AudioAndroidInputTest,
972 testing::Bool()); 969 testing::Bool());
973 970
974 } // namespace media 971 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698