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

Side by Side Diff: components/copresence/mediums/audio/audio_player_unittest.cc

Issue 886593005: Enhance audio player tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 | « no previous file | 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/copresence/mediums/audio/audio_player.h" 5 #include "components/copresence/mediums/audio/audio_player.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "components/copresence/mediums/audio/audio_player_impl.h" 9 #include "components/copresence/mediums/audio/audio_player_impl.h"
10 #include "components/copresence/public/copresence_constants.h" 10 #include "components/copresence/public/copresence_constants.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 92
93 void DeletePlayer() { 93 void DeletePlayer() {
94 if (!player_) 94 if (!player_)
95 return; 95 return;
96 player_->Finalize(); 96 player_->Finalize();
97 player_ = nullptr; 97 player_ = nullptr;
98 } 98 }
99 99
100 void PlayAndVerifySamples( 100 void PlayAndVerifySamples(
101 const scoped_refptr<media::AudioBusRefCounted>& samples) { 101 const scoped_refptr<media::AudioBusRefCounted>& samples) {
102 DCHECK_LT(samples->frames(), kMaxFrameCount);
103
102 buffer_ = media::AudioBus::Create(1, kMaxFrameCount); 104 buffer_ = media::AudioBus::Create(1, kMaxFrameCount);
105 buffer_index_ = 0;
103 player_->Play(samples); 106 player_->Play(samples);
104 player_->FlushAudioLoopForTesting(); 107 player_->FlushAudioLoopForTesting();
108 player_->Stop();
105 109
106 int differences = 0; 110 int differences = 0;
107 for (int i = 0; i < samples->frames(); ++i) 111 for (int i = 0; i < kMaxFrameCount; ++i) {
108 differences += (buffer_->channel(0)[i] != samples->channel(0)[i]); 112 differences += (buffer_->channel(0)[i] !=
113 samples->channel(0)[i % samples->frames()]);
114 }
109 ASSERT_EQ(0, differences); 115 ASSERT_EQ(0, differences);
110 116
111 buffer_.reset(); 117 buffer_.reset();
112 } 118 }
113 119
114 void GatherSamples(scoped_ptr<media::AudioBus> bus, int frames) { 120 void GatherSamples(scoped_ptr<media::AudioBus> bus, int frames) {
115 if (!buffer_.get()) 121 if (!buffer_.get())
116 return; 122 return;
117 bus->CopyPartialFramesTo(0, frames, buffer_index_, buffer_.get()); 123 bus->CopyPartialFramesTo(0, frames, buffer_index_, buffer_.get());
118 buffer_index_ += frames; 124 buffer_index_ += frames;
119 } 125 }
120 126
121 protected: 127 protected:
122 bool IsPlaying() { 128 bool IsPlaying() {
123 player_->FlushAudioLoopForTesting(); 129 player_->FlushAudioLoopForTesting();
124 return player_->is_playing_; 130 return player_->is_playing_;
125 } 131 }
126 132
127 static const int kDefaultFrameCount = 1024; 133 static const int kDefaultFrameCount = 1024;
128 static const int kMaxFrameCount = 1024 * 10; 134 static const int kMaxFrameCount = 1024 * 100;
129 135
130 scoped_ptr<media::AudioBus> buffer_; 136 scoped_ptr<media::AudioBus> buffer_;
131 int buffer_index_; 137 int buffer_index_;
132 138
133 // Deleted by calling Finalize() on the object. 139 // Deleted by calling Finalize() on the object.
134 AudioPlayerImpl* player_; 140 AudioPlayerImpl* player_;
135 base::MessageLoop message_loop_; 141 base::MessageLoop message_loop_;
136 }; 142 };
137 143
138 TEST_F(AudioPlayerTest, BasicPlayAndStop) { 144 TEST_F(AudioPlayerTest, BasicPlayAndStop) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 EXPECT_TRUE(IsPlaying()); 179 EXPECT_TRUE(IsPlaying());
174 180
175 player_->Stop(); 181 player_->Stop();
176 player_->Stop(); 182 player_->Stop();
177 EXPECT_FALSE(IsPlaying()); 183 EXPECT_FALSE(IsPlaying());
178 184
179 DeletePlayer(); 185 DeletePlayer();
180 } 186 }
181 187
182 TEST_F(AudioPlayerTest, PlayingEndToEnd) { 188 TEST_F(AudioPlayerTest, PlayingEndToEnd) {
183 const int kNumSamples = kDefaultFrameCount * 10; 189 const int kNumSamples = kDefaultFrameCount * 7 + 321;
184 CreatePlayer(); 190 CreatePlayer();
185 191
186 PlayAndVerifySamples(CreateRandomAudioRefCounted(0x1337, 1, kNumSamples)); 192 PlayAndVerifySamples(CreateRandomAudioRefCounted(0x1337, 1, kNumSamples));
187 193
188 DeletePlayer(); 194 DeletePlayer();
189 } 195 }
190 196
197 TEST_F(AudioPlayerTest, PlayingEndToEndRepeated) {
198 const int kNumSamples = kDefaultFrameCount * 7 + 537;
199 CreatePlayer();
200
201 PlayAndVerifySamples(CreateRandomAudioRefCounted(0x1337, 1, kNumSamples));
202
203 PlayAndVerifySamples(
204 CreateRandomAudioRefCounted(0x7331, 1, kNumSamples - 3123));
205
206 PlayAndVerifySamples(CreateRandomAudioRefCounted(0xf00d, 1, kNumSamples * 2));
207
208 DeletePlayer();
209 }
210
191 } // namespace copresence 211 } // namespace copresence
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698