srpcgen: Use 'const char*' for string parameters
[chromium-blink-merge.git] / media / audio / audio_parameters_unittest.cc
blobda3e746fc2808b2ff9f47715e01007f0bd7de48d
1 // Copyright (c) 2011 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"
10 TEST(AudioParameters, Constructor_Default) {
11 AudioParameters::Format expected_format = AudioParameters::AUDIO_PCM_LINEAR;
12 int expected_bits = 0;
13 int expected_channels = 0;
14 ChannelLayout expected_channel_layout = CHANNEL_LAYOUT_NONE;
15 int expected_rate = 0;
16 int expected_samples = 0;
18 AudioParameters params;
20 EXPECT_EQ(expected_format, params.format);
21 EXPECT_EQ(expected_bits, params.bits_per_sample);
22 EXPECT_EQ(expected_channels, params.channels);
23 EXPECT_EQ(expected_channel_layout, params.channel_layout);
24 EXPECT_EQ(expected_rate, params.sample_rate);
25 EXPECT_EQ(expected_samples, params.samples_per_packet);
28 TEST(AudioParameters, Constructor_ParameterValues) {
29 AudioParameters::Format expected_format =
30 AudioParameters::AUDIO_PCM_LOW_LATENCY;
31 int expected_bits = 16;
32 int expected_channels = 6;
33 ChannelLayout expected_channel_layout = CHANNEL_LAYOUT_5POINT1;
34 int expected_rate = 44100;
35 int expected_samples = 880;
37 AudioParameters params(expected_format, expected_channel_layout,
38 expected_rate, expected_bits, expected_samples);
40 EXPECT_EQ(expected_format, params.format);
41 EXPECT_EQ(expected_bits, params.bits_per_sample);
42 EXPECT_EQ(expected_channels, params.channels);
43 EXPECT_EQ(expected_channel_layout, params.channel_layout);
44 EXPECT_EQ(expected_rate, params.sample_rate);
45 EXPECT_EQ(expected_samples, params.samples_per_packet);
48 TEST(AudioParameters, GetPacketSize) {
49 EXPECT_EQ(100, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
50 CHANNEL_LAYOUT_MONO, 1000, 8, 100)
51 .GetPacketSize());
52 EXPECT_EQ(200, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
53 CHANNEL_LAYOUT_MONO, 1000, 16, 100)
54 .GetPacketSize());
55 EXPECT_EQ(200, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
56 CHANNEL_LAYOUT_STEREO, 1000, 8, 100)
57 .GetPacketSize());
58 EXPECT_EQ(200, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
59 CHANNEL_LAYOUT_MONO, 1000, 8, 200)
60 .GetPacketSize());
61 EXPECT_EQ(800, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
62 CHANNEL_LAYOUT_STEREO, 1000, 16, 200)
63 .GetPacketSize());
66 TEST(AudioParameters, GetBytesPerSecond) {
67 EXPECT_EQ(0, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
68 CHANNEL_LAYOUT_NONE, 0, 0, 0)
69 .GetBytesPerSecond());
70 EXPECT_EQ(0, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
71 CHANNEL_LAYOUT_STEREO, 0, 0, 0)
72 .GetBytesPerSecond());
73 EXPECT_EQ(0, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
74 CHANNEL_LAYOUT_NONE, 100, 0, 0)
75 .GetBytesPerSecond());
76 EXPECT_EQ(0, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
77 CHANNEL_LAYOUT_NONE, 0, 8, 0)
78 .GetBytesPerSecond());
79 EXPECT_EQ(200, AudioParameters(AudioParameters::AUDIO_PCM_LINEAR,
80 CHANNEL_LAYOUT_STEREO, 100, 8, 0)
81 .GetBytesPerSecond());
84 TEST(AudioParameters, Compare) {
85 AudioParameters values[] = {
86 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
87 1000, 8, 100),
88 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
89 1000, 8, 200),
90 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
91 1000, 16, 100),
92 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
93 1000, 16, 200),
94 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
95 2000, 8, 100),
96 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
97 2000, 8, 200),
98 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
99 2000, 16, 100),
100 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO,
101 2000, 16, 200),
103 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
104 1000, 8, 100),
105 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
106 1000, 8, 200),
107 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
108 1000, 16, 100),
109 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
110 1000, 16, 200),
111 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
112 2000, 8, 100),
113 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
114 2000, 8, 200),
115 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
116 2000, 16, 100),
117 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_STEREO,
118 2000, 16, 200),
120 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO,
121 1000, 8, 100),
122 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO,
123 1000, 8, 200),
124 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO,
125 1000, 16, 100),
126 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO,
127 1000, 16, 200),
128 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO,
129 2000, 8, 100),
130 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO,
131 2000, 8, 200),
132 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO,
133 2000, 16, 100),
134 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_MONO,
135 2000, 16, 200),
137 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
138 CHANNEL_LAYOUT_STEREO, 1000, 8, 100),
139 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
140 CHANNEL_LAYOUT_STEREO, 1000, 8, 200),
141 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
142 CHANNEL_LAYOUT_STEREO, 1000, 16, 100),
143 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
144 CHANNEL_LAYOUT_STEREO, 1000, 16, 200),
145 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
146 CHANNEL_LAYOUT_STEREO, 2000, 8, 100),
147 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
148 CHANNEL_LAYOUT_STEREO, 2000, 8, 200),
149 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
150 CHANNEL_LAYOUT_STEREO, 2000, 16, 100),
151 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
152 CHANNEL_LAYOUT_STEREO, 2000, 16, 200),
155 AudioParameters::Compare target;
156 for (size_t i = 0; i < arraysize(values); ++i) {
157 for (size_t j = 0; j < arraysize(values); ++j) {
158 SCOPED_TRACE("i=" + base::IntToString(i) + " j=" + base::IntToString(j));
159 EXPECT_EQ(i < j, target(values[i], values[j]));
162 // Verify that a value is never less than itself.
163 EXPECT_FALSE(target(values[i], values[i]));