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/string_number_conversions.h"
7 #include "media/audio/audio_parameters.h"
8 #include "testing/gtest/include/gtest/gtest.h"
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;
20 AudioParameters params
;
22 EXPECT_EQ(expected_format
, params
.format());
23 EXPECT_EQ(expected_bits
, params
.bits_per_sample());
24 EXPECT_EQ(expected_channels
, params
.channels());
25 EXPECT_EQ(expected_channel_layout
, params
.channel_layout());
26 EXPECT_EQ(expected_rate
, params
.sample_rate());
27 EXPECT_EQ(expected_samples
, params
.frames_per_buffer());
30 TEST(AudioParameters
, Constructor_ParameterValues
) {
31 AudioParameters::Format expected_format
=
32 AudioParameters::AUDIO_PCM_LOW_LATENCY
;
33 int expected_bits
= 16;
34 int expected_channels
= 6;
35 ChannelLayout expected_channel_layout
= CHANNEL_LAYOUT_5_1
;
36 int expected_rate
= 44100;
37 int expected_samples
= 880;
39 AudioParameters
params(expected_format
, expected_channel_layout
,
40 expected_rate
, expected_bits
, expected_samples
);
42 EXPECT_EQ(expected_format
, params
.format());
43 EXPECT_EQ(expected_bits
, params
.bits_per_sample());
44 EXPECT_EQ(expected_channels
, params
.channels());
45 EXPECT_EQ(expected_channel_layout
, params
.channel_layout());
46 EXPECT_EQ(expected_rate
, params
.sample_rate());
47 EXPECT_EQ(expected_samples
, params
.frames_per_buffer());
50 TEST(AudioParameters
, GetBytesPerBuffer
) {
51 EXPECT_EQ(100, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
,
52 CHANNEL_LAYOUT_MONO
, 1000, 8, 100)
53 .GetBytesPerBuffer());
54 EXPECT_EQ(200, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
,
55 CHANNEL_LAYOUT_MONO
, 1000, 16, 100)
56 .GetBytesPerBuffer());
57 EXPECT_EQ(200, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
,
58 CHANNEL_LAYOUT_STEREO
, 1000, 8, 100)
59 .GetBytesPerBuffer());
60 EXPECT_EQ(200, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
,
61 CHANNEL_LAYOUT_MONO
, 1000, 8, 200)
62 .GetBytesPerBuffer());
63 EXPECT_EQ(800, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
,
64 CHANNEL_LAYOUT_STEREO
, 1000, 16, 200)
65 .GetBytesPerBuffer());
68 TEST(AudioParameters
, GetBytesPerSecond
) {
69 EXPECT_EQ(0, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
,
70 CHANNEL_LAYOUT_NONE
, 0, 0, 0)
71 .GetBytesPerSecond());
72 EXPECT_EQ(0, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
,
73 CHANNEL_LAYOUT_STEREO
, 0, 0, 0)
74 .GetBytesPerSecond());
75 EXPECT_EQ(0, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
,
76 CHANNEL_LAYOUT_NONE
, 100, 0, 0)
77 .GetBytesPerSecond());
78 EXPECT_EQ(0, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
,
79 CHANNEL_LAYOUT_NONE
, 0, 8, 0)
80 .GetBytesPerSecond());
81 EXPECT_EQ(200, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
,
82 CHANNEL_LAYOUT_STEREO
, 100, 8, 0)
83 .GetBytesPerSecond());
86 TEST(AudioParameters
, Compare
) {
87 AudioParameters values
[] = {
88 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
, CHANNEL_LAYOUT_MONO
,
90 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
, CHANNEL_LAYOUT_MONO
,
92 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
, CHANNEL_LAYOUT_MONO
,
94 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
, CHANNEL_LAYOUT_MONO
,
96 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
, CHANNEL_LAYOUT_MONO
,
98 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
, CHANNEL_LAYOUT_MONO
,
100 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
, CHANNEL_LAYOUT_MONO
,
102 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
, CHANNEL_LAYOUT_MONO
,
105 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
, CHANNEL_LAYOUT_STEREO
,
107 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
, CHANNEL_LAYOUT_STEREO
,
109 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
, CHANNEL_LAYOUT_STEREO
,
111 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
, CHANNEL_LAYOUT_STEREO
,
113 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
, CHANNEL_LAYOUT_STEREO
,
115 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
, CHANNEL_LAYOUT_STEREO
,
117 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
, CHANNEL_LAYOUT_STEREO
,
119 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR
, CHANNEL_LAYOUT_STEREO
,
122 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
, CHANNEL_LAYOUT_MONO
,
124 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
, CHANNEL_LAYOUT_MONO
,
126 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
, CHANNEL_LAYOUT_MONO
,
128 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
, CHANNEL_LAYOUT_MONO
,
130 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
, CHANNEL_LAYOUT_MONO
,
132 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
, CHANNEL_LAYOUT_MONO
,
134 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
, CHANNEL_LAYOUT_MONO
,
136 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
, CHANNEL_LAYOUT_MONO
,
139 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
,
140 CHANNEL_LAYOUT_STEREO
, 1000, 8, 100),
141 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
,
142 CHANNEL_LAYOUT_STEREO
, 1000, 8, 200),
143 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
,
144 CHANNEL_LAYOUT_STEREO
, 1000, 16, 100),
145 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
,
146 CHANNEL_LAYOUT_STEREO
, 1000, 16, 200),
147 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
,
148 CHANNEL_LAYOUT_STEREO
, 2000, 8, 100),
149 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
,
150 CHANNEL_LAYOUT_STEREO
, 2000, 8, 200),
151 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
,
152 CHANNEL_LAYOUT_STEREO
, 2000, 16, 100),
153 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY
,
154 CHANNEL_LAYOUT_STEREO
, 2000, 16, 200),
157 for (size_t i
= 0; i
< arraysize(values
); ++i
) {
158 for (size_t j
= 0; j
< arraysize(values
); ++j
) {
159 SCOPED_TRACE("i=" + base::IntToString(i
) + " j=" + base::IntToString(j
));
160 EXPECT_EQ(i
< j
, values
[i
] < values
[j
]);
163 // Verify that a value is never less than itself.
164 EXPECT_FALSE(values
[i
] < values
[i
]);