Revert "Omit calls to set composing region when pasting image."
[chromium-blink-merge.git] / media / audio / audio_parameters_unittest.cc
blobc39e8d4915dcb8e9d256617dd63f5c53a354b334
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
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "base/strings/string_number_conversions.h"
7 #include "media/audio/audio_parameters.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace media {
12 TEST(AudioParameters, Constructor_Default) {
13 AudioParameters::Format expected_format = AudioParameters::AUDIO_PCM_LINEAR;
14 int expected_bits = 0;
15 int expected_channels = 0;
16 ChannelLayout expected_channel_layout = CHANNEL_LAYOUT_NONE;
17 int expected_rate = 0;
18 int expected_samples = 0;
19 AudioParameters::PlatformEffectsMask expected_effects =
20 AudioParameters::NO_EFFECTS;
21 std::vector<Point> expected_mic_positions;
23 AudioParameters params;
25 EXPECT_EQ(expected_format, params.format());
26 EXPECT_EQ(expected_bits, params.bits_per_sample());
27 EXPECT_EQ(expected_channels, params.channels());
28 EXPECT_EQ(expected_channel_layout, params.channel_layout());
29 EXPECT_EQ(expected_rate, params.sample_rate());
30 EXPECT_EQ(expected_samples, params.frames_per_buffer());
31 EXPECT_EQ(expected_effects, params.effects());
32 EXPECT_EQ(expected_mic_positions, params.mic_positions());
35 TEST(AudioParameters, Constructor_ParameterValues) {
36 AudioParameters::Format expected_format =
37 AudioParameters::AUDIO_PCM_LOW_LATENCY;
38 int expected_bits = 16;
39 int expected_channels = 6;
40 ChannelLayout expected_channel_layout = CHANNEL_LAYOUT_5_1;
41 int expected_rate = 44100;
42 int expected_samples = 880;
44 AudioParameters params(expected_format, expected_channel_layout,
45 expected_rate, expected_bits, expected_samples);
47 EXPECT_EQ(expected_format, params.format());
48 EXPECT_EQ(expected_bits, params.bits_per_sample());
49 EXPECT_EQ(expected_channels, params.channels());
50 EXPECT_EQ(expected_channel_layout, params.channel_layout());
51 EXPECT_EQ(expected_rate, params.sample_rate());
52 EXPECT_EQ(expected_samples, params.frames_per_buffer());
55 TEST(AudioParameters, GetBytesPerBuffer) {
56 EXPECT_EQ(100, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
57 CHANNEL_LAYOUT_MONO, 1000, 8, 100)
58 .GetBytesPerBuffer());
59 EXPECT_EQ(200, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
60 CHANNEL_LAYOUT_MONO, 1000, 16, 100)
61 .GetBytesPerBuffer());
62 EXPECT_EQ(200, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
63 CHANNEL_LAYOUT_STEREO, 1000, 8, 100)
64 .GetBytesPerBuffer());
65 EXPECT_EQ(200, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
66 CHANNEL_LAYOUT_MONO, 1000, 8, 200)
67 .GetBytesPerBuffer());
68 EXPECT_EQ(800, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
69 CHANNEL_LAYOUT_STEREO, 1000, 16, 200)
70 .GetBytesPerBuffer());
71 EXPECT_EQ(300, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
72 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC,
73 1000, 8, 100)
74 .GetBytesPerBuffer());
77 TEST(AudioParameters, GetBytesPerSecond) {
78 EXPECT_EQ(0, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
79 CHANNEL_LAYOUT_NONE, 0, 0, 0)
80 .GetBytesPerSecond());
81 EXPECT_EQ(0, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
82 CHANNEL_LAYOUT_STEREO, 0, 0, 0)
83 .GetBytesPerSecond());
84 EXPECT_EQ(0, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
85 CHANNEL_LAYOUT_NONE, 100, 0, 0)
86 .GetBytesPerSecond());
87 EXPECT_EQ(0, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
88 CHANNEL_LAYOUT_NONE, 0, 8, 0)
89 .GetBytesPerSecond());
90 EXPECT_EQ(200, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
91 CHANNEL_LAYOUT_STEREO, 100, 8, 0)
92 .GetBytesPerSecond());
95 TEST(AudioParameters, Compare) {
96 AudioParameters values[] = {
97 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
98 1000, 8, 100),
99 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
100 1000, 8, 200),
101 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
102 1000, 16, 100),
103 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
104 1000, 16, 200),
105 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
106 2000, 8, 100),
107 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
108 2000, 8, 200),
109 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
110 2000, 16, 100),
111 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
112 2000, 16, 200),
114 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
115 1000, 8, 100),
116 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
117 1000, 8, 200),
118 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
119 1000, 16, 100),
120 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
121 1000, 16, 200),
122 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
123 2000, 8, 100),
124 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
125 2000, 8, 200),
126 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
127 2000, 16, 100),
128 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
129 2000, 16, 200),
131 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
132 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 1000, 8, 100),
133 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
134 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 1000, 8, 200),
135 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
136 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 1000, 16, 100),
137 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
138 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 1000, 16, 200),
139 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
140 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 2000, 8, 100),
141 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
142 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 2000, 8, 200),
143 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
144 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 2000, 16, 100),
145 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
146 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 2000, 16, 200),
148 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO,
149 1000, 8, 100),
150 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO,
151 1000, 8, 200),
152 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO,
153 1000, 16, 100),
154 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO,
155 1000, 16, 200),
156 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO,
157 2000, 8, 100),
158 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO,
159 2000, 8, 200),
160 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO,
161 2000, 16, 100),
162 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO,
163 2000, 16, 200),
165 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
166 CHANNEL_LAYOUT_STEREO, 1000, 8, 100),
167 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
168 CHANNEL_LAYOUT_STEREO, 1000, 8, 200),
169 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
170 CHANNEL_LAYOUT_STEREO, 1000, 16, 100),
171 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
172 CHANNEL_LAYOUT_STEREO, 1000, 16, 200),
173 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
174 CHANNEL_LAYOUT_STEREO, 2000, 8, 100),
175 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
176 CHANNEL_LAYOUT_STEREO, 2000, 8, 200),
177 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
178 CHANNEL_LAYOUT_STEREO, 2000, 16, 100),
179 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
180 CHANNEL_LAYOUT_STEREO, 2000, 16, 200),
182 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
183 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 1000, 8, 100),
184 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
185 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 1000, 8, 200),
186 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
187 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 1000, 16, 100),
188 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
189 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 1000, 16, 200),
190 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
191 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 2000, 8, 100),
192 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
193 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 2000, 8, 200),
194 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
195 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 2000, 16, 100),
196 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
197 CHANNEL_LAYOUT_STEREO_AND_KEYBOARD_MIC, 2000, 16, 200),
200 for (size_t i = 0; i < arraysize(values); ++i) {
201 for (size_t j = 0; j < arraysize(values); ++j) {
202 SCOPED_TRACE("i=" + base::IntToString(i) + " j=" + base::IntToString(j));
203 EXPECT_EQ(i < j, values[i] < values[j]);
206 // Verify that a value is never less than itself.
207 EXPECT_FALSE(values[i] < values[i]);
211 TEST(AudioParameters, Constructor_ValidChannelCounts) {
212 int expected_channels = 8;
213 ChannelLayout expected_layout = CHANNEL_LAYOUT_DISCRETE;
215 AudioParameters params(AudioParameters::AUDIO_PCM_LOW_LATENCY,
216 expected_layout, 44100, 16, 880);
217 params.set_channels_for_discrete(expected_channels);
218 EXPECT_EQ(expected_channels, params.channels());
219 EXPECT_EQ(expected_layout, params.channel_layout());
220 EXPECT_TRUE(params.IsValid());
223 } // namespace media