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

Side by Side Diff: webrtc/common_audio/wav_header_unittest.cc

Issue 1316523002: Convert channel counts to size_t. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Fix compile Created 4 years, 11 months 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
« no previous file with comments | « webrtc/common_audio/wav_header.cc ('k') | webrtc/common_types.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // Too large values. 84 // Too large values.
85 EXPECT_FALSE(CheckWavParameters(1 << 20, 1 << 20, kWavFormatPcm, 1, 0)); 85 EXPECT_FALSE(CheckWavParameters(1 << 20, 1 << 20, kWavFormatPcm, 1, 0));
86 EXPECT_FALSE(CheckWavParameters( 86 EXPECT_FALSE(CheckWavParameters(
87 1, 8000, kWavFormatPcm, 1, std::numeric_limits<uint32_t>::max())); 87 1, 8000, kWavFormatPcm, 1, std::numeric_limits<uint32_t>::max()));
88 88
89 // Not the same number of samples for each channel. 89 // Not the same number of samples for each channel.
90 EXPECT_FALSE(CheckWavParameters(3, 8000, kWavFormatPcm, 1, 5)); 90 EXPECT_FALSE(CheckWavParameters(3, 8000, kWavFormatPcm, 1, 5));
91 } 91 }
92 92
93 TEST(WavHeaderTest, ReadWavHeaderWithErrors) { 93 TEST(WavHeaderTest, ReadWavHeaderWithErrors) {
94 int num_channels = 0; 94 size_t num_channels = 0;
95 int sample_rate = 0; 95 int sample_rate = 0;
96 WavFormat format = kWavFormatPcm; 96 WavFormat format = kWavFormatPcm;
97 size_t bytes_per_sample = 0; 97 size_t bytes_per_sample = 0;
98 size_t num_samples = 0; 98 size_t num_samples = 0;
99 99
100 // Test a few ways the header can be invalid. We start with the valid header 100 // Test a few ways the header can be invalid. We start with the valid header
101 // used in WriteAndReadWavHeader, and invalidate one field per test. The 101 // used in WriteAndReadWavHeader, and invalidate one field per test. The
102 // invalid field is indicated in the array name, and in the comments with 102 // invalid field is indicated in the array name, and in the comments with
103 // *BAD*. 103 // *BAD*.
104 { 104 {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 0xc9, 0x33, 0x03, 0, // byte rate: 1 * 17 * 12345 261 0xc9, 0x33, 0x03, 0, // byte rate: 1 * 17 * 12345
262 17, 0, // block align: NumChannels * BytesPerSample 262 17, 0, // block align: NumChannels * BytesPerSample
263 8, 0, // bits per sample: 1 * 8 263 8, 0, // bits per sample: 1 * 8
264 'd', 'a', 't', 'a', 264 'd', 'a', 't', 'a',
265 0x99, 0xd0, 0x5b, 0x07, // size of payload: 123457689 265 0x99, 0xd0, 0x5b, 0x07, // size of payload: 123457689
266 0xa4, 0xa4, 0xa4, 0xa4, // untouched bytes after header 266 0xa4, 0xa4, 0xa4, 0xa4, // untouched bytes after header
267 }; 267 };
268 static_assert(sizeof(kExpectedBuf) == kSize, "buffer size"); 268 static_assert(sizeof(kExpectedBuf) == kSize, "buffer size");
269 EXPECT_EQ(0, memcmp(kExpectedBuf, buf, kSize)); 269 EXPECT_EQ(0, memcmp(kExpectedBuf, buf, kSize));
270 270
271 int num_channels = 0; 271 size_t num_channels = 0;
272 int sample_rate = 0; 272 int sample_rate = 0;
273 WavFormat format = kWavFormatPcm; 273 WavFormat format = kWavFormatPcm;
274 size_t bytes_per_sample = 0; 274 size_t bytes_per_sample = 0;
275 size_t num_samples = 0; 275 size_t num_samples = 0;
276 ReadableWavBuffer r(buf + 4, sizeof(buf) - 8); 276 ReadableWavBuffer r(buf + 4, sizeof(buf) - 8);
277 EXPECT_TRUE( 277 EXPECT_TRUE(
278 ReadWavHeader(&r, &num_channels, &sample_rate, &format, 278 ReadWavHeader(&r, &num_channels, &sample_rate, &format,
279 &bytes_per_sample, &num_samples)); 279 &bytes_per_sample, &num_samples));
280 EXPECT_EQ(17, num_channels); 280 EXPECT_EQ(17u, num_channels);
281 EXPECT_EQ(12345, sample_rate); 281 EXPECT_EQ(12345, sample_rate);
282 EXPECT_EQ(kWavFormatALaw, format); 282 EXPECT_EQ(kWavFormatALaw, format);
283 EXPECT_EQ(1u, bytes_per_sample); 283 EXPECT_EQ(1u, bytes_per_sample);
284 EXPECT_EQ(123457689u, num_samples); 284 EXPECT_EQ(123457689u, num_samples);
285 } 285 }
286 286
287 // Try reading an atypical but valid WAV header and make sure it's parsed OK. 287 // Try reading an atypical but valid WAV header and make sure it's parsed OK.
288 TEST(WavHeaderTest, ReadAtypicalWavHeader) { 288 TEST(WavHeaderTest, ReadAtypicalWavHeader) {
289 static const uint8_t kBuf[] = { 289 static const uint8_t kBuf[] = {
290 'R', 'I', 'F', 'F', 290 'R', 'I', 'F', 'F',
291 0x3d, 0xd1, 0x5b, 0x07, // size of whole file - 8 + an extra 128 bytes of 291 0x3d, 0xd1, 0x5b, 0x07, // size of whole file - 8 + an extra 128 bytes of
292 // "metadata": 123457689 + 44 - 8 + 128. (atypical) 292 // "metadata": 123457689 + 44 - 8 + 128. (atypical)
293 'W', 'A', 'V', 'E', 293 'W', 'A', 'V', 'E',
294 'f', 'm', 't', ' ', 294 'f', 'm', 't', ' ',
295 18, 0, 0, 0, // size of fmt block (with an atypical extension size field) 295 18, 0, 0, 0, // size of fmt block (with an atypical extension size field)
296 6, 0, // format: A-law (6) 296 6, 0, // format: A-law (6)
297 17, 0, // channels: 17 297 17, 0, // channels: 17
298 0x39, 0x30, 0, 0, // sample rate: 12345 298 0x39, 0x30, 0, 0, // sample rate: 12345
299 0xc9, 0x33, 0x03, 0, // byte rate: 1 * 17 * 12345 299 0xc9, 0x33, 0x03, 0, // byte rate: 1 * 17 * 12345
300 17, 0, // block align: NumChannels * BytesPerSample 300 17, 0, // block align: NumChannels * BytesPerSample
301 8, 0, // bits per sample: 1 * 8 301 8, 0, // bits per sample: 1 * 8
302 0, 0, // zero extension size field (atypical) 302 0, 0, // zero extension size field (atypical)
303 'd', 'a', 't', 'a', 303 'd', 'a', 't', 'a',
304 0x99, 0xd0, 0x5b, 0x07, // size of payload: 123457689 304 0x99, 0xd0, 0x5b, 0x07, // size of payload: 123457689
305 }; 305 };
306 306
307 int num_channels = 0; 307 size_t num_channels = 0;
308 int sample_rate = 0; 308 int sample_rate = 0;
309 WavFormat format = kWavFormatPcm; 309 WavFormat format = kWavFormatPcm;
310 size_t bytes_per_sample = 0; 310 size_t bytes_per_sample = 0;
311 size_t num_samples = 0; 311 size_t num_samples = 0;
312 ReadableWavBuffer r(kBuf, sizeof(kBuf)); 312 ReadableWavBuffer r(kBuf, sizeof(kBuf));
313 EXPECT_TRUE( 313 EXPECT_TRUE(
314 ReadWavHeader(&r, &num_channels, &sample_rate, &format, 314 ReadWavHeader(&r, &num_channels, &sample_rate, &format,
315 &bytes_per_sample, &num_samples)); 315 &bytes_per_sample, &num_samples));
316 EXPECT_EQ(17, num_channels); 316 EXPECT_EQ(17u, num_channels);
317 EXPECT_EQ(12345, sample_rate); 317 EXPECT_EQ(12345, sample_rate);
318 EXPECT_EQ(kWavFormatALaw, format); 318 EXPECT_EQ(kWavFormatALaw, format);
319 EXPECT_EQ(1u, bytes_per_sample); 319 EXPECT_EQ(1u, bytes_per_sample);
320 EXPECT_EQ(123457689u, num_samples); 320 EXPECT_EQ(123457689u, num_samples);
321 } 321 }
322 322
323 } // namespace webrtc 323 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/common_audio/wav_header.cc ('k') | webrtc/common_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698