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

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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 buffer_ = media::AudioBus::Create(1, kMaxFrameCount); 102 buffer_ = media::AudioBus::Create(1, kMaxFrameCount);
103 player_->Play(samples); 103 player_->Play(samples);
104 player_->FlushAudioLoopForTesting(); 104 player_->FlushAudioLoopForTesting();
105 105
106 int differences = 0; 106 int differences = 0;
107 for (int i = 0; i < samples->frames(); ++i) 107 for (int i = 0; i < kMaxFrameCount; ++i) {
108 differences += (buffer_->channel(0)[i] != samples->channel(0)[i]); 108 differences += (buffer_->channel(0)[i] !=
109 samples->channel(0)[i % samples->frames()]);
110 }
109 ASSERT_EQ(0, differences); 111 ASSERT_EQ(0, differences);
110 112
111 buffer_.reset(); 113 buffer_.reset();
112 } 114 }
113 115
114 void GatherSamples(scoped_ptr<media::AudioBus> bus, int frames) { 116 void GatherSamples(scoped_ptr<media::AudioBus> bus, int frames) {
115 if (!buffer_.get()) 117 if (!buffer_.get())
116 return; 118 return;
117 bus->CopyPartialFramesTo(0, frames, buffer_index_, buffer_.get()); 119 bus->CopyPartialFramesTo(0, frames, buffer_index_, buffer_.get());
118 buffer_index_ += frames; 120 buffer_index_ += frames;
119 } 121 }
120 122
121 protected: 123 protected:
122 bool IsPlaying() { 124 bool IsPlaying() {
123 player_->FlushAudioLoopForTesting(); 125 player_->FlushAudioLoopForTesting();
124 return player_->is_playing_; 126 return player_->is_playing_;
125 } 127 }
126 128
127 static const int kDefaultFrameCount = 1024; 129 static const int kDefaultFrameCount = 1024;
128 static const int kMaxFrameCount = 1024 * 10; 130 static const int kMaxFrameCount = 1024 * 100;
129 131
130 scoped_ptr<media::AudioBus> buffer_; 132 scoped_ptr<media::AudioBus> buffer_;
131 int buffer_index_; 133 int buffer_index_;
132 134
133 // Deleted by calling Finalize() on the object. 135 // Deleted by calling Finalize() on the object.
134 AudioPlayerImpl* player_; 136 AudioPlayerImpl* player_;
135 base::MessageLoop message_loop_; 137 base::MessageLoop message_loop_;
136 }; 138 };
137 139
138 TEST_F(AudioPlayerTest, BasicPlayAndStop) { 140 TEST_F(AudioPlayerTest, BasicPlayAndStop) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 EXPECT_TRUE(IsPlaying()); 175 EXPECT_TRUE(IsPlaying());
174 176
175 player_->Stop(); 177 player_->Stop();
176 player_->Stop(); 178 player_->Stop();
177 EXPECT_FALSE(IsPlaying()); 179 EXPECT_FALSE(IsPlaying());
178 180
179 DeletePlayer(); 181 DeletePlayer();
180 } 182 }
181 183
182 TEST_F(AudioPlayerTest, PlayingEndToEnd) { 184 TEST_F(AudioPlayerTest, PlayingEndToEnd) {
183 const int kNumSamples = kDefaultFrameCount * 10; 185 // Ensure that kNumsamples is never over kMaxFrameCount.
Charlie 2015/01/29 17:35:03 This and the additional instance below should be D
rkc 2015/01/29 17:42:42 Added the DCHECK to PlayAndVerifySamples instead,
186 const int kNumSamples = kDefaultFrameCount * 32;
184 CreatePlayer(); 187 CreatePlayer();
185 188
186 PlayAndVerifySamples(CreateRandomAudioRefCounted(0x1337, 1, kNumSamples)); 189 PlayAndVerifySamples(CreateRandomAudioRefCounted(0x1337, 1, kNumSamples));
190
191 DeletePlayer();
192 }
193
194 TEST_F(AudioPlayerTest, PlayingEndToEndOddSizes) {
195 // Ensure that kNumsamples is never over kMaxFrameCount.
196 const int kNumSamples = kDefaultFrameCount * 7 + 321;
197 CreatePlayer();
198
199 PlayAndVerifySamples(CreateRandomAudioRefCounted(0x1337, 1, kNumSamples));
187 200
188 DeletePlayer(); 201 DeletePlayer();
189 } 202 }
190 203
191 } // namespace copresence 204 } // 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