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

Side by Side Diff: media/audio/audio_util_unittest.cc

Issue 6300001: Clang: enable -Wbool-conversions and -Wunused-variables on Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, undo indent Created 9 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 | Annotate | Revision Log
« no previous file with comments | « courgette/third_party/paged_array_unittest.cc ('k') | media/omx/omx_codec_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "media/audio/audio_util.h" 6 #include "media/audio/audio_util.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 // Number of samples in each audio array. 9 // Number of samples in each audio array.
10 static const size_t kNumberOfSamples = 4; 10 static const size_t kNumberOfSamples = 4;
11 11
12 namespace media { 12 namespace media {
13 13
14 TEST(AudioUtilTest, AdjustVolume_u8) { 14 TEST(AudioUtilTest, AdjustVolume_u8) {
15 // Test AdjustVolume() on 8 bit samples. 15 // Test AdjustVolume() on 8 bit samples.
16 uint8 samples_u8[kNumberOfSamples] = { 4, 0x40, 0x80, 0xff }; 16 uint8 samples_u8[kNumberOfSamples] = { 4, 0x40, 0x80, 0xff };
17 uint8 expected_u8[kNumberOfSamples] = { (4 - 128) / 2 + 128, 17 uint8 expected_u8[kNumberOfSamples] = { (4 - 128) / 2 + 128,
18 (0x40 - 128) / 2 + 128, 18 (0x40 - 128) / 2 + 128,
19 (0x80 - 128) / 2 + 128, 19 (0x80 - 128) / 2 + 128,
20 (0xff - 128) / 2 + 128 }; 20 (0xff - 128) / 2 + 128 };
21 bool result_u8 = media::AdjustVolume(samples_u8, sizeof(samples_u8), 21 bool result_u8 = media::AdjustVolume(samples_u8, sizeof(samples_u8),
22 1, // channels. 22 1, // channels.
23 sizeof(samples_u8[0]), 23 sizeof(samples_u8[0]),
24 0.5f); 24 0.5f);
25 EXPECT_EQ(true, result_u8); 25 EXPECT_TRUE(result_u8);
26 int expected_test = memcmp(samples_u8, expected_u8, sizeof(expected_u8)); 26 int expected_test = memcmp(samples_u8, expected_u8, sizeof(expected_u8));
27 EXPECT_EQ(0, expected_test); 27 EXPECT_EQ(0, expected_test);
28 } 28 }
29 29
30 TEST(AudioUtilTest, AdjustVolume_s16) { 30 TEST(AudioUtilTest, AdjustVolume_s16) {
31 // Test AdjustVolume() on 16 bit samples. 31 // Test AdjustVolume() on 16 bit samples.
32 int16 samples_s16[kNumberOfSamples] = { -4, 0x40, -32768, 123 }; 32 int16 samples_s16[kNumberOfSamples] = { -4, 0x40, -32768, 123 };
33 int16 expected_s16[kNumberOfSamples] = { -1, 0x10, -8192, 30 }; 33 int16 expected_s16[kNumberOfSamples] = { -1, 0x10, -8192, 30 };
34 bool result_s16 = media::AdjustVolume(samples_s16, sizeof(samples_s16), 34 bool result_s16 = media::AdjustVolume(samples_s16, sizeof(samples_s16),
35 2, // channels. 35 2, // channels.
36 sizeof(samples_s16[0]), 36 sizeof(samples_s16[0]),
37 0.25f); 37 0.25f);
38 EXPECT_EQ(true, result_s16); 38 EXPECT_TRUE(result_s16);
39 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16)); 39 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16));
40 EXPECT_EQ(0, expected_test); 40 EXPECT_EQ(0, expected_test);
41 } 41 }
42 42
43 TEST(AudioUtilTest, AdjustVolume_s16_zero) { 43 TEST(AudioUtilTest, AdjustVolume_s16_zero) {
44 // Test AdjustVolume() on 16 bit samples. 44 // Test AdjustVolume() on 16 bit samples.
45 int16 samples_s16[kNumberOfSamples] = { -4, 0x40, -32768, 123 }; 45 int16 samples_s16[kNumberOfSamples] = { -4, 0x40, -32768, 123 };
46 int16 expected_s16[kNumberOfSamples] = { 0, 0, 0, 0 }; 46 int16 expected_s16[kNumberOfSamples] = { 0, 0, 0, 0 };
47 bool result_s16 = media::AdjustVolume(samples_s16, sizeof(samples_s16), 47 bool result_s16 = media::AdjustVolume(samples_s16, sizeof(samples_s16),
48 2, // channels. 48 2, // channels.
49 sizeof(samples_s16[0]), 49 sizeof(samples_s16[0]),
50 0.0f); 50 0.0f);
51 EXPECT_EQ(true, result_s16); 51 EXPECT_TRUE(result_s16);
52 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16)); 52 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16));
53 EXPECT_EQ(0, expected_test); 53 EXPECT_EQ(0, expected_test);
54 } 54 }
55 55
56 TEST(AudioUtilTest, AdjustVolume_s16_one) { 56 TEST(AudioUtilTest, AdjustVolume_s16_one) {
57 // Test AdjustVolume() on 16 bit samples. 57 // Test AdjustVolume() on 16 bit samples.
58 int16 samples_s16[kNumberOfSamples] = { -4, 0x40, -32768, 123 }; 58 int16 samples_s16[kNumberOfSamples] = { -4, 0x40, -32768, 123 };
59 int16 expected_s16[kNumberOfSamples] = { -4, 0x40, -32768, 123 }; 59 int16 expected_s16[kNumberOfSamples] = { -4, 0x40, -32768, 123 };
60 bool result_s16 = media::AdjustVolume(samples_s16, sizeof(samples_s16), 60 bool result_s16 = media::AdjustVolume(samples_s16, sizeof(samples_s16),
61 2, // channels. 61 2, // channels.
62 sizeof(samples_s16[0]), 62 sizeof(samples_s16[0]),
63 1.0f); 63 1.0f);
64 EXPECT_EQ(true, result_s16); 64 EXPECT_TRUE(result_s16);
65 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16)); 65 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16));
66 EXPECT_EQ(0, expected_test); 66 EXPECT_EQ(0, expected_test);
67 } 67 }
68 68
69 TEST(AudioUtilTest, AdjustVolume_s32) { 69 TEST(AudioUtilTest, AdjustVolume_s32) {
70 // Test AdjustVolume() on 32 bit samples. 70 // Test AdjustVolume() on 32 bit samples.
71 int32 samples_s32[kNumberOfSamples] = { -4, 0x40, -32768, 123 }; 71 int32 samples_s32[kNumberOfSamples] = { -4, 0x40, -32768, 123 };
72 int32 expected_s32[kNumberOfSamples] = { -1, 0x10, -8192, 30 }; 72 int32 expected_s32[kNumberOfSamples] = { -1, 0x10, -8192, 30 };
73 bool result_s32 = media::AdjustVolume(samples_s32, sizeof(samples_s32), 73 bool result_s32 = media::AdjustVolume(samples_s32, sizeof(samples_s32),
74 4, // channels. 74 4, // channels.
75 sizeof(samples_s32[0]), 75 sizeof(samples_s32[0]),
76 0.25f); 76 0.25f);
77 EXPECT_EQ(true, result_s32); 77 EXPECT_TRUE(result_s32);
78 int expected_test = memcmp(samples_s32, expected_s32, sizeof(expected_s32)); 78 int expected_test = memcmp(samples_s32, expected_s32, sizeof(expected_s32));
79 EXPECT_EQ(0, expected_test); 79 EXPECT_EQ(0, expected_test);
80 } 80 }
81 81
82 TEST(AudioUtilTest, FoldChannels_u8) { 82 TEST(AudioUtilTest, FoldChannels_u8) {
83 // Test FoldChannels() on 8 bit samples. 83 // Test FoldChannels() on 8 bit samples.
84 uint8 samples_u8[6] = { 100, 150, 130, 70, 130, 170 }; 84 uint8 samples_u8[6] = { 100, 150, 130, 70, 130, 170 };
85 uint8 expected_u8[2] = { static_cast<uint8>((130 - 128) * 0.707 + 85 uint8 expected_u8[2] = { static_cast<uint8>((130 - 128) * 0.707 +
86 (100 - 128) + 128), 86 (100 - 128) + 128),
87 static_cast<uint8>((130 - 128) * 0.707 + 87 static_cast<uint8>((130 - 128) * 0.707 +
88 (150 - 128) + 128) }; 88 (150 - 128) + 128) };
89 bool result_u8 = media::FoldChannels(samples_u8, sizeof(samples_u8), 89 bool result_u8 = media::FoldChannels(samples_u8, sizeof(samples_u8),
90 6, // channels. 90 6, // channels.
91 sizeof(samples_u8[0]), 91 sizeof(samples_u8[0]),
92 1.0f); 92 1.0f);
93 EXPECT_EQ(true, result_u8); 93 EXPECT_TRUE(result_u8);
94 int expected_test = memcmp(samples_u8, expected_u8, sizeof(expected_u8)); 94 int expected_test = memcmp(samples_u8, expected_u8, sizeof(expected_u8));
95 EXPECT_EQ(0, expected_test); 95 EXPECT_EQ(0, expected_test);
96 } 96 }
97 97
98 TEST(AudioUtilTest, FoldChannels_s16) { 98 TEST(AudioUtilTest, FoldChannels_s16) {
99 // Test FoldChannels() on 16 bit samples. 99 // Test FoldChannels() on 16 bit samples.
100 int16 samples_s16[6] = { 1, 3, 12, 7, 13, 17 }; 100 int16 samples_s16[6] = { 1, 3, 12, 7, 13, 17 };
101 int16 expected_s16[2] = { static_cast<int16>(12 * .707 + 1), 101 int16 expected_s16[2] = { static_cast<int16>(12 * .707 + 1),
102 static_cast<int16>(12 * .707 + 3) }; 102 static_cast<int16>(12 * .707 + 3) };
103 bool result_s16 = media::FoldChannels(samples_s16, sizeof(samples_s16), 103 bool result_s16 = media::FoldChannels(samples_s16, sizeof(samples_s16),
104 6, // channels. 104 6, // channels.
105 sizeof(samples_s16[0]), 105 sizeof(samples_s16[0]),
106 1.00f); 106 1.00f);
107 EXPECT_EQ(true, result_s16); 107 EXPECT_TRUE(result_s16);
108 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16)); 108 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16));
109 EXPECT_EQ(0, expected_test); 109 EXPECT_EQ(0, expected_test);
110 } 110 }
111 111
112 TEST(AudioUtilTest, FoldChannels_s32) { 112 TEST(AudioUtilTest, FoldChannels_s32) {
113 // Test FoldChannels() on 32 bit samples. 113 // Test FoldChannels() on 32 bit samples.
114 int32 samples_s32[6] = { 1, 3, 12, 7, 13, 17 }; 114 int32 samples_s32[6] = { 1, 3, 12, 7, 13, 17 };
115 int32 expected_s32[2] = { static_cast<int16>(12 * .707 + 1), 115 int32 expected_s32[2] = { static_cast<int16>(12 * .707 + 1),
116 static_cast<int16>(12 * .707 + 3) }; 116 static_cast<int16>(12 * .707 + 3) };
117 bool result_s32 = media::FoldChannels(samples_s32, sizeof(samples_s32), 117 bool result_s32 = media::FoldChannels(samples_s32, sizeof(samples_s32),
118 6, // channels. 118 6, // channels.
119 sizeof(samples_s32[0]), 119 sizeof(samples_s32[0]),
120 1.00f); 120 1.00f);
121 EXPECT_EQ(true, result_s32); 121 EXPECT_TRUE(result_s32);
122 int expected_test = memcmp(samples_s32, expected_s32, sizeof(expected_s32)); 122 int expected_test = memcmp(samples_s32, expected_s32, sizeof(expected_s32));
123 EXPECT_EQ(0, expected_test); 123 EXPECT_EQ(0, expected_test);
124 } 124 }
125 125
126 // Fold 7.1 126 // Fold 7.1
127 TEST(AudioUtilTest, FoldChannels71_s16) { 127 TEST(AudioUtilTest, FoldChannels71_s16) {
128 // Test FoldChannels() on 16 bit samples. 128 // Test FoldChannels() on 16 bit samples.
129 int16 samples_s16[8] = { 1, 3, 12, 7, 13, 17, 30, 40 }; 129 int16 samples_s16[8] = { 1, 3, 12, 7, 13, 17, 30, 40 };
130 int16 expected_s16[2] = { static_cast<int16>(12 * .707 + 1), 130 int16 expected_s16[2] = { static_cast<int16>(12 * .707 + 1),
131 static_cast<int16>(12 * .707 + 3) }; 131 static_cast<int16>(12 * .707 + 3) };
132 bool result_s16 = media::FoldChannels(samples_s16, sizeof(samples_s16), 132 bool result_s16 = media::FoldChannels(samples_s16, sizeof(samples_s16),
133 8, // channels. 133 8, // channels.
134 sizeof(samples_s16[0]), 134 sizeof(samples_s16[0]),
135 1.00f); 135 1.00f);
136 EXPECT_EQ(true, result_s16); 136 EXPECT_TRUE(result_s16);
137 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16)); 137 int expected_test = memcmp(samples_s16, expected_s16, sizeof(expected_s16));
138 EXPECT_EQ(0, expected_test); 138 EXPECT_EQ(0, expected_test);
139 } 139 }
140 140
141 } // namespace media 141 } // namespace media
OLDNEW
« no previous file with comments | « courgette/third_party/paged_array_unittest.cc ('k') | media/omx/omx_codec_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698