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

Side by Side Diff: media/filters/audio_renderer_impl_unittest.cc

Issue 11359100: Add RunCallback to invoke a callback parameter in unittests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rename Created 8 years, 1 month 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 | « media/base/pipeline_unittest.cc ('k') | media/filters/decrypting_audio_decoder_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) 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback_helpers.h" 6 #include "base/callback_helpers.h"
7 #include "base/gtest_prod_util.h" 7 #include "base/gtest_prod_util.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "media/base/data_buffer.h" 10 #include "media/base/data_buffer.h"
11 #include "media/base/gmock_callback_support.h"
11 #include "media/base/mock_audio_renderer_sink.h" 12 #include "media/base/mock_audio_renderer_sink.h"
12 #include "media/base/mock_callback.h" 13 #include "media/base/mock_callback.h"
13 #include "media/base/mock_filters.h" 14 #include "media/base/mock_filters.h"
14 #include "media/filters/audio_renderer_impl.h" 15 #include "media/filters/audio_renderer_impl.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 using ::testing::_; 18 using ::testing::_;
18 using ::testing::AnyNumber; 19 using ::testing::AnyNumber;
19 using ::testing::Invoke; 20 using ::testing::Invoke;
20 using ::testing::Return; 21 using ::testing::Return;
21 using ::testing::NiceMock; 22 using ::testing::NiceMock;
22 using ::testing::StrictMock; 23 using ::testing::StrictMock;
23 24
24 ACTION_P(RunPipelineStatusCB1, status) {
25 arg1.Run(status);
26 }
27
28 namespace media { 25 namespace media {
29 26
30 // Constants for distinguishing between muted audio and playing audio when using 27 // Constants for distinguishing between muted audio and playing audio when using
31 // ConsumeBufferedData(). 28 // ConsumeBufferedData().
32 static uint8 kMutedAudio = 0x00; 29 static uint8 kMutedAudio = 0x00;
33 static uint8 kPlayingAudio = 0x99; 30 static uint8 kPlayingAudio = 0x99;
34 31
35 class AudioRendererImplTest : public ::testing::Test { 32 class AudioRendererImplTest : public ::testing::Test {
36 public: 33 public:
37 // Give the decoder some non-garbage media properties. 34 // Give the decoder some non-garbage media properties.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 MOCK_METHOD0(OnDisabled, void()); 90 MOCK_METHOD0(OnDisabled, void());
94 MOCK_METHOD1(OnError, void(PipelineStatus)); 91 MOCK_METHOD1(OnError, void(PipelineStatus));
95 92
96 void OnAudioTimeCallback( 93 void OnAudioTimeCallback(
97 base::TimeDelta current_time, base::TimeDelta max_time) { 94 base::TimeDelta current_time, base::TimeDelta max_time) {
98 CHECK(current_time <= max_time); 95 CHECK(current_time <= max_time);
99 } 96 }
100 97
101 void Initialize() { 98 void Initialize() {
102 EXPECT_CALL(*decoder_, Initialize(_, _, _)) 99 EXPECT_CALL(*decoder_, Initialize(_, _, _))
103 .WillOnce(RunPipelineStatusCB1(PIPELINE_OK)); 100 .WillOnce(RunCallback<1>(PIPELINE_OK));
104 101
105 InitializeWithStatus(PIPELINE_OK); 102 InitializeWithStatus(PIPELINE_OK);
106 message_loop_.RunUntilIdle(); 103 message_loop_.RunUntilIdle();
107 } 104 }
108 105
109 void InitializeWithStatus(PipelineStatus expected) { 106 void InitializeWithStatus(PipelineStatus expected) {
110 renderer_->Initialize( 107 renderer_->Initialize(
111 demuxer_stream_, 108 demuxer_stream_,
112 decoders_, 109 decoders_,
113 NewExpectedStatusCB(expected), 110 NewExpectedStatusCB(expected),
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 void SaveReadCallback(const AudioDecoder::ReadCB& callback) { 236 void SaveReadCallback(const AudioDecoder::ReadCB& callback) {
240 CHECK(read_cb_.is_null()) << "Overlapping reads are not permitted"; 237 CHECK(read_cb_.is_null()) << "Overlapping reads are not permitted";
241 read_cb_ = callback; 238 read_cb_ = callback;
242 } 239 }
243 240
244 DISALLOW_COPY_AND_ASSIGN(AudioRendererImplTest); 241 DISALLOW_COPY_AND_ASSIGN(AudioRendererImplTest);
245 }; 242 };
246 243
247 TEST_F(AudioRendererImplTest, Initialize_Failed) { 244 TEST_F(AudioRendererImplTest, Initialize_Failed) {
248 EXPECT_CALL(*decoder_, Initialize(_, _, _)) 245 EXPECT_CALL(*decoder_, Initialize(_, _, _))
249 .WillOnce(RunPipelineStatusCB1(PIPELINE_OK)); 246 .WillOnce(RunCallback<1>(PIPELINE_OK));
250 SetUnsupportedAudioDecoderProperties(); 247 SetUnsupportedAudioDecoderProperties();
251 248
252 InitializeWithStatus(PIPELINE_ERROR_INITIALIZATION_FAILED); 249 InitializeWithStatus(PIPELINE_ERROR_INITIALIZATION_FAILED);
253 250
254 // We should have no reads. 251 // We should have no reads.
255 EXPECT_TRUE(read_cb_.is_null()); 252 EXPECT_TRUE(read_cb_.is_null());
256 } 253 }
257 254
258 TEST_F(AudioRendererImplTest, Initialize_Successful) { 255 TEST_F(AudioRendererImplTest, Initialize_Successful) {
259 Initialize(); 256 Initialize();
260 257
261 // We should have no reads. 258 // We should have no reads.
262 EXPECT_TRUE(read_cb_.is_null()); 259 EXPECT_TRUE(read_cb_.is_null());
263 } 260 }
264 261
265 TEST_F(AudioRendererImplTest, Initialize_DecoderInitFailure) { 262 TEST_F(AudioRendererImplTest, Initialize_DecoderInitFailure) {
266 EXPECT_CALL(*decoder_, Initialize(_, _, _)) 263 EXPECT_CALL(*decoder_, Initialize(_, _, _))
267 .WillOnce(RunPipelineStatusCB1(PIPELINE_ERROR_DECODE)); 264 .WillOnce(RunCallback<1>(PIPELINE_ERROR_DECODE));
268 InitializeWithStatus(PIPELINE_ERROR_DECODE); 265 InitializeWithStatus(PIPELINE_ERROR_DECODE);
269 266
270 // We should have no reads. 267 // We should have no reads.
271 EXPECT_TRUE(read_cb_.is_null()); 268 EXPECT_TRUE(read_cb_.is_null());
272 } 269 }
273 270
274 TEST_F(AudioRendererImplTest, Initialize_MultipleDecoders) { 271 TEST_F(AudioRendererImplTest, Initialize_MultipleDecoders) {
275 scoped_refptr<MockAudioDecoder> decoder1 = new MockAudioDecoder(); 272 scoped_refptr<MockAudioDecoder> decoder1 = new MockAudioDecoder();
276 // Insert |decoder1| as the first decoder in the list. 273 // Insert |decoder1| as the first decoder in the list.
277 decoders_.push_front(decoder1); 274 decoders_.push_front(decoder1);
278 EXPECT_CALL(*decoder1, Initialize(_, _, _)) 275 EXPECT_CALL(*decoder1, Initialize(_, _, _))
279 .WillOnce(RunPipelineStatusCB1(DECODER_ERROR_NOT_SUPPORTED)); 276 .WillOnce(RunCallback<1>(DECODER_ERROR_NOT_SUPPORTED));
280 EXPECT_CALL(*decoder_, Initialize(_, _, _)) 277 EXPECT_CALL(*decoder_, Initialize(_, _, _))
281 .WillOnce(RunPipelineStatusCB1(PIPELINE_OK)); 278 .WillOnce(RunCallback<1>(PIPELINE_OK));
282 InitializeWithStatus(PIPELINE_OK); 279 InitializeWithStatus(PIPELINE_OK);
283 280
284 // We should have no reads. 281 // We should have no reads.
285 EXPECT_TRUE(read_cb_.is_null()); 282 EXPECT_TRUE(read_cb_.is_null());
286 } 283 }
287 284
288 TEST_F(AudioRendererImplTest, Preroll) { 285 TEST_F(AudioRendererImplTest, Preroll) {
289 Initialize(); 286 Initialize();
290 Preroll(); 287 Preroll();
291 } 288 }
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 EXPECT_TRUE(ConsumeBufferedData(bytes_buffered() / 2, NULL)); 469 EXPECT_TRUE(ConsumeBufferedData(bytes_buffered() / 2, NULL));
473 470
474 renderer_->Pause(NewExpectedClosure()); 471 renderer_->Pause(NewExpectedClosure());
475 472
476 AbortPendingRead(); 473 AbortPendingRead();
477 474
478 Preroll(base::TimeDelta::FromSeconds(1)); 475 Preroll(base::TimeDelta::FromSeconds(1));
479 } 476 }
480 477
481 } // namespace media 478 } // namespace media
OLDNEW
« no previous file with comments | « media/base/pipeline_unittest.cc ('k') | media/filters/decrypting_audio_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698