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

Side by Side Diff: media/base/audio_bus_unittest.cc

Issue 2845813004: Add unit test for AudioBus::CreateWrapper() (Closed)
Patch Set: Created 3 years, 7 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 | « media/base/audio_bus.h ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 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 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <limits> 8 #include <limits>
9 #include <memory> 9 #include <memory>
10 10
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 125
126 // Verify Create(...) using AudioParameters works as advertised. 126 // Verify Create(...) using AudioParameters works as advertised.
127 TEST_F(AudioBusTest, CreateUsingAudioParameters) { 127 TEST_F(AudioBusTest, CreateUsingAudioParameters) {
128 std::unique_ptr<AudioBus> bus = AudioBus::Create( 128 std::unique_ptr<AudioBus> bus = AudioBus::Create(
129 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, 129 AudioParameters(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout,
130 kSampleRate, 32, kFrameCount)); 130 kSampleRate, 32, kFrameCount));
131 VerifyChannelAndFrameCount(bus.get()); 131 VerifyChannelAndFrameCount(bus.get());
132 VerifyReadWriteAndAlignment(bus.get()); 132 VerifyReadWriteAndAlignment(bus.get());
133 } 133 }
134 134
135 // Verify CreateWrapper(...) method works as advertised.
136 TEST_F(AudioBusTest, CreateWrapper) {
137 std::unique_ptr<AudioBus> bus = AudioBus::CreateWrapper(kChannels);
138 EXPECT_EQ(kChannels, bus->channels());
139 EXPECT_EQ(0, bus->frames());
140 }
141
135 // Verify an AudioBus created via wrapping a vector works as advertised. 142 // Verify an AudioBus created via wrapping a vector works as advertised.
136 TEST_F(AudioBusTest, WrapVector) { 143 TEST_F(AudioBusTest, WrapVector) {
137 data_.reserve(kChannels); 144 data_.reserve(kChannels);
138 for (int i = 0; i < kChannels; ++i) { 145 for (int i = 0; i < kChannels; ++i) {
139 data_.push_back(static_cast<float*>(base::AlignedAlloc( 146 data_.push_back(static_cast<float*>(base::AlignedAlloc(
140 sizeof(*data_[i]) * kFrameCount, AudioBus::kChannelAlignment))); 147 sizeof(*data_[i]) * kFrameCount, AudioBus::kChannelAlignment)));
141 } 148 }
142 149
143 std::unique_ptr<AudioBus> bus = AudioBus::WrapVector(kFrameCount, data_); 150 std::unique_ptr<AudioBus> bus = AudioBus::WrapVector(kFrameCount, data_);
144 VerifyChannelAndFrameCount(bus.get()); 151 VerifyChannelAndFrameCount(bus.get());
(...skipping 20 matching lines...) Expand all
165 VerifyArrayIsFilledWithValue(bus->channel(i), bus->frames(), kTestValue); 172 VerifyArrayIsFilledWithValue(bus->channel(i), bus->frames(), kTestValue);
166 VerifyChannelAndFrameCount(bus.get()); 173 VerifyChannelAndFrameCount(bus.get());
167 VerifyReadWriteAndAlignment(bus.get()); 174 VerifyReadWriteAndAlignment(bus.get());
168 175
169 // Verify the channel vectors lie within the provided memory block. 176 // Verify the channel vectors lie within the provided memory block.
170 EXPECT_GE(bus->channel(0), data.get()); 177 EXPECT_GE(bus->channel(0), data.get());
171 EXPECT_LT(bus->channel(bus->channels() - 1) + bus->frames(), 178 EXPECT_LT(bus->channel(bus->channels() - 1) + bus->frames(),
172 data.get() + data_size / sizeof(*data.get())); 179 data.get() + data_size / sizeof(*data.get()));
173 } 180 }
174 181
182 // Verify SetChannelData(...) method works as advertised.
183 TEST_F(AudioBusTest, SetChannelData) {
184 data_.reserve(kChannels);
185 for (int i = 0; i < kChannels; ++i) {
186 data_.push_back(static_cast<float*>(
187 base::AlignedAlloc(sizeof(*data_[i]), AudioBus::kChannelAlignment)));
188 }
189 std::unique_ptr<AudioBus> bus = AudioBus::CreateWrapper(kChannels);
190 for (int i = 0; i < bus->channels(); ++i)
191 bus->SetChannelData(i, data_[i]);
192
193 for (int i = 0; i < bus->channels(); ++i)
194 EXPECT_EQ(bus->channel(i), data_[i]);
chfremer 2017/04/27 16:55:14 Would it make sense to add VerifyReadWriteAndAli
Chandan 2017/04/27 18:43:07 With number of frames in this test being always ze
chfremer 2017/04/27 20:19:36 Hmm, I feel that for the cases where AudioBus itse
Chandan 2017/04/28 06:07:29 Sure. I will add Alignment verification for this t
chfremer 2017/04/28 16:39:48 Not needed for the tests involving AudioBus::Creat
195 }
196
197 // Verify set_frames(...) method works as advertised.
198 TEST_F(AudioBusTest, SetFrames) {
199 std::unique_ptr<AudioBus> bus = AudioBus::CreateWrapper(kChannels);
200 bus->set_frames(kFrameCount);
201 EXPECT_EQ(kFrameCount, bus->frames());
chfremer 2017/04/27 16:55:14 Would it make sense to add VerifyReadWriteAndAli
Chandan 2017/04/27 18:43:07 With no channel data allocated in this test, verif
chfremer 2017/04/27 20:19:36 True. I guess, when I added the TODO for adding te
Chandan 2017/04/28 06:07:29 By 'everything' you mean read/write/alignment? Im
chfremer 2017/04/28 16:39:48 Sorry about my vague language. Yes I meant read/wr
Chandan 2017/05/02 09:27:06 Right. With the new test in place, these 3 individ
202 }
203
175 // Simulate a shared memory transfer and verify results. 204 // Simulate a shared memory transfer and verify results.
176 TEST_F(AudioBusTest, CopyTo) { 205 TEST_F(AudioBusTest, CopyTo) {
177 // Create one bus with AudioParameters and the other through direct values to 206 // Create one bus with AudioParameters and the other through direct values to
178 // test for parity between the Create() functions. 207 // test for parity between the Create() functions.
179 AudioParameters params( 208 AudioParameters params(
180 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, 32, 209 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, 32,
181 kFrameCount); 210 kFrameCount);
182 std::unique_ptr<AudioBus> bus1 = AudioBus::Create(kChannels, kFrameCount); 211 std::unique_ptr<AudioBus> bus1 = AudioBus::Create(kChannels, kFrameCount);
183 std::unique_ptr<AudioBus> bus2 = AudioBus::Create(params); 212 std::unique_ptr<AudioBus> bus2 = AudioBus::Create(params);
184 213
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 688
660 // Verify zero volume case. 689 // Verify zero volume case.
661 bus->Scale(0); 690 bus->Scale(0);
662 for (int i = 0; i < bus->channels(); ++i) { 691 for (int i = 0; i < bus->channels(); ++i) {
663 SCOPED_TRACE("Zero Scale"); 692 SCOPED_TRACE("Zero Scale");
664 VerifyArrayIsFilledWithValue(bus->channel(i), bus->frames(), 0); 693 VerifyArrayIsFilledWithValue(bus->channel(i), bus->frames(), 0);
665 } 694 }
666 } 695 }
667 696
668 } // namespace media 697 } // namespace media
OLDNEW
« no previous file with comments | « media/base/audio_bus.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698