diff options
author | xhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-13 05:49:48 +0000 |
---|---|---|
committer | xhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-13 05:49:48 +0000 |
commit | 8b10f2225bcce231a75e96755f8812f026271c08 (patch) | |
tree | 62ba81d8582d52b6dd8a973cd9227c0ee87d0d71 /media | |
parent | 025f9a7e737e5448d17a882cf37a8ca3fcf3666f (diff) | |
download | chromium_src-8b10f2225bcce231a75e96755f8812f026271c08.zip chromium_src-8b10f2225bcce231a75e96755f8812f026271c08.tar.gz chromium_src-8b10f2225bcce231a75e96755f8812f026271c08.tar.bz2 |
Add RunCallback to invoke a callback parameter in unittests.
In gmock, ::testing::InvokeArgument doesn't support chromium base::Callback. Adding customized templated action RunCallback to support this.
Also added new matchers for base::callback.
BUG=none
TEST=Added unittests to test the new matchers and actions. Updated media_unittests to use the new matchers and actions.
Review URL: https://chromiumcodereview.appspot.com/11359100
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@167309 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/base/gmock_callback_support.h | 107 | ||||
-rw-r--r-- | media/base/gmock_callback_support_unittest.cc | 84 | ||||
-rw-r--r-- | media/base/mock_filters.h | 4 | ||||
-rw-r--r-- | media/base/pipeline_unittest.cc | 188 | ||||
-rw-r--r-- | media/filters/audio_renderer_impl_unittest.cc | 15 | ||||
-rw-r--r-- | media/filters/decrypting_audio_decoder_unittest.cc | 59 | ||||
-rw-r--r-- | media/filters/decrypting_video_decoder_unittest.cc | 51 | ||||
-rw-r--r-- | media/filters/ffmpeg_video_decoder_unittest.cc | 19 | ||||
-rw-r--r-- | media/filters/video_renderer_base_unittest.cc | 13 | ||||
-rw-r--r-- | media/media.gyp | 2 |
10 files changed, 345 insertions, 197 deletions
diff --git a/media/base/gmock_callback_support.h b/media/base/gmock_callback_support.h new file mode 100644 index 0000000..22f4c10 --- /dev/null +++ b/media/base/gmock_callback_support.h @@ -0,0 +1,107 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef MEDIA_BASE_GMOCK_CALLBACK_SUPPORT_H_ +#define MEDIA_BASE_GMOCK_CALLBACK_SUPPORT_H_ + +#include "testing/gmock/include/gmock/gmock.h" + +namespace media { + +// Matchers for base::Callback and base::Closure. + +MATCHER(IsNullCallback, "a null callback") { + return (arg.is_null()); +} + +MATCHER(IsNotNullCallback, "a non-null callback") { + return (!arg.is_null()); +} + +// The RunClosure<N>() action invokes Run() method on the N-th (0-based) +// argument of the mock function. + +ACTION_TEMPLATE(RunClosure, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_0_VALUE_PARAMS()) { + ::std::tr1::get<k>(args).Run(); +} + +// Various overloads for RunCallback<N>(). +// +// The RunCallback<N>(p1, p2, ..., p_k) action invokes Run() method on the N-th +// (0-based) argument of the mock function, with arguments p1, p2, ..., p_k. +// +// Notes: +// +// 1. The arguments are passed by value by default. If you need to +// pass an argument by reference, wrap it inside ByRef(). For example, +// +// RunCallback<1>(5, string("Hello"), ByRef(foo)) +// +// passes 5 and string("Hello") by value, and passes foo by reference. +// +// 2. If the callback takes an argument by reference but ByRef() is +// not used, it will receive the reference to a copy of the value, +// instead of the original value. For example, when the 0-th +// argument of the callback takes a const string&, the action +// +// RunCallback<0>(string("Hello")) +// +// makes a copy of the temporary string("Hello") object and passes a +// reference of the copy, instead of the original temporary object, +// to the callback. This makes it easy for a user to define an +// RunCallback action from temporary values and have it performed later. + +ACTION_TEMPLATE(RunCallback, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_0_VALUE_PARAMS()) { + return ::std::tr1::get<k>(args).Run(); +} + +ACTION_TEMPLATE(RunCallback, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_1_VALUE_PARAMS(p0)) { + return ::std::tr1::get<k>(args).Run(p0); +} + +ACTION_TEMPLATE(RunCallback, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_2_VALUE_PARAMS(p0, p1)) { + return ::std::tr1::get<k>(args).Run(p0, p1); +} + +ACTION_TEMPLATE(RunCallback, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_3_VALUE_PARAMS(p0, p1, p2)) { + return ::std::tr1::get<k>(args).Run(p0, p1, p2); +} + +ACTION_TEMPLATE(RunCallback, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_4_VALUE_PARAMS(p0, p1, p2, p3)) { + return ::std::tr1::get<k>(args).Run(p0, p1, p2, p3); +} + +ACTION_TEMPLATE(RunCallback, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) { + return ::std::tr1::get<k>(args).Run(p0, p1, p2, p3, p4); +} + +ACTION_TEMPLATE(RunCallback, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) { + return ::std::tr1::get<k>(args).Run(p0, p1, p2, p3, p4, p5); +} + +ACTION_TEMPLATE(RunCallback, + HAS_1_TEMPLATE_PARAMS(int, k), + AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) { + return ::std::tr1::get<k>(args).Run(p0, p1, p2, p3, p4, p5, p6); +} + +} // namespace media + +#endif // MEDIA_BASE_GMOCK_CALLBACK_SUPPORT_H_ diff --git a/media/base/gmock_callback_support_unittest.cc b/media/base/gmock_callback_support_unittest.cc new file mode 100644 index 0000000..fb1beb9 --- /dev/null +++ b/media/base/gmock_callback_support_unittest.cc @@ -0,0 +1,84 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "media/base/gmock_callback_support.h" + +#include "base/bind.h" +#include "base/callback.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "testing/gtest/include/gtest/gtest.h" + +using testing::ByRef; +using testing::MockFunction; + +namespace media { + +typedef base::Callback<void(const bool& src, bool* dst)> TestCallback; + +void SetBool(const bool& src, bool* dst) { + *dst = src; +} + +TEST(GmockCallbackSupportTest, IsNullCallback) { + MockFunction<void(const TestCallback&)> check; + EXPECT_CALL(check, Call(IsNullCallback())); + check.Call(TestCallback()); +} + +TEST(GmockCallbackSupportTest, IsNotNullCallback) { + MockFunction<void(const TestCallback&)> check; + EXPECT_CALL(check, Call(IsNotNullCallback())); + check.Call(base::Bind(&SetBool)); +} + +TEST(GmockCallbackSupportTest, RunClosure) { + MockFunction<void(const base::Closure&)> check; + bool dst = false; + EXPECT_CALL(check, Call(IsNotNullCallback())) + .WillOnce(RunClosure<0>()); + check.Call(base::Bind(&SetBool, true, &dst)); + EXPECT_TRUE(dst); +} + +TEST(GmockCallbackSupportTest, RunCallback0) { + MockFunction<void(const TestCallback&)> check; + bool dst = false; + EXPECT_CALL(check, Call(IsNotNullCallback())) + .WillOnce(RunCallback<0>(true, &dst)); + check.Call(base::Bind(&SetBool)); + EXPECT_TRUE(dst); +} + +TEST(GmockCallbackSupportTest, RunCallback1) { + MockFunction<void(int, const TestCallback&)> check; + bool dst = false; + EXPECT_CALL(check, Call(0, IsNotNullCallback())) + .WillOnce(RunCallback<1>(true, &dst)); + check.Call(0, base::Bind(&SetBool)); + EXPECT_TRUE(dst); +} + +TEST(GmockCallbackSupportTest, RunCallbackPassByRef) { + MockFunction<void(const TestCallback&)> check; + bool dst = false; + bool src = false; + EXPECT_CALL(check, Call(IsNotNullCallback())) + .WillOnce(RunCallback<0>(ByRef(src), &dst)); + src = true; + check.Call(base::Bind(&SetBool)); + EXPECT_TRUE(dst); +} + +TEST(GmockCallbackSupportTest, RunCallbackPassByValue) { + MockFunction<void(const TestCallback&)> check; + bool dst = false; + bool src = true; + EXPECT_CALL(check, Call(IsNotNullCallback())) + .WillOnce(RunCallback<0>(src, &dst)); + src = false; + check.Call(base::Bind(&SetBool)); + EXPECT_TRUE(dst); +} + +} // namespace media diff --git a/media/base/mock_filters.h b/media/base/mock_filters.h index b0698df..6e8df1d 100644 --- a/media/base/mock_filters.h +++ b/media/base/mock_filters.h @@ -305,10 +305,6 @@ class MockFilterCollection { DISALLOW_COPY_AND_ASSIGN(MockFilterCollection); }; -ACTION(RunClosure) { - arg0.Run(); -} - // Helper mock statistics callback. class MockStatisticsCB { public: diff --git a/media/base/pipeline_unittest.cc b/media/base/pipeline_unittest.cc index ad2e2fe..8c82933 100644 --- a/media/base/pipeline_unittest.cc +++ b/media/base/pipeline_unittest.cc @@ -9,10 +9,11 @@ #include "base/stl_util.h" #include "base/threading/simple_thread.h" #include "media/base/clock.h" +#include "media/base/gmock_callback_support.h" #include "media/base/media_log.h" -#include "media/base/pipeline.h" #include "media/base/mock_callback.h" #include "media/base/mock_filters.h" +#include "media/base/pipeline.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/gfx/size.h" @@ -50,22 +51,6 @@ ACTION_P2(SetError, pipeline, status) { pipeline->SetErrorForTesting(status); } -ACTION(RunPipelineStatusCB) { - arg1.Run(PIPELINE_OK); -} - -ACTION(RunPipelineStatusCB2) { - arg2.Run(PIPELINE_OK); -} - -ACTION_P(RunPipelineStatusCBWithStatus, status) { - arg1.Run(status); -} - -ACTION_P(RunPipelineStatusCB2WithStatus, status) { - arg2.Run(status); -} - // Used for setting expectations on pipeline callbacks. Using a StrictMock // also lets us test for missing callbacks. class CallbackHelper { @@ -111,13 +96,15 @@ class PipelineTest : public ::testing::Test { // Shutdown sequence. if (pipeline_->IsRunning()) { EXPECT_CALL(*mocks_->demuxer(), Stop(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); if (audio_stream_) - EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); + EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) + .WillOnce(RunClosure<0>()); if (video_stream_) - EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure()); + EXPECT_CALL(*mocks_->video_renderer(), Stop(_)) + .WillOnce(RunClosure<0>()); } // Expect a stop callback if we were started. @@ -137,7 +124,7 @@ class PipelineTest : public ::testing::Test { const base::TimeDelta& duration) { EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) .WillOnce(DoAll(SetDemuxerProperties(duration), - RunPipelineStatusCB())); + RunCallback<1>(PIPELINE_OK))); // Configure the demuxer to return the streams. for (size_t i = 0; i < streams->size(); ++i) { @@ -164,15 +151,15 @@ class PipelineTest : public ::testing::Test { void InitializeVideoRenderer(const scoped_refptr<DemuxerStream>& stream) { EXPECT_CALL(*mocks_->video_renderer(), Initialize(stream, _, _, _, _, _, _, _, _, _)) - .WillOnce(RunPipelineStatusCB2()); + .WillOnce(RunCallback<2>(PIPELINE_OK)); EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); // Startup sequence. EXPECT_CALL(*mocks_->video_renderer(), Preroll(mocks_->demuxer()->GetStartTime(), _)) - .WillOnce(RunPipelineStatusCB()); + .WillOnce(RunCallback<1>(PIPELINE_OK)); EXPECT_CALL(*mocks_->video_renderer(), Play(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); } // Sets up expectations to allow the audio renderer to initialize. @@ -181,13 +168,13 @@ class PipelineTest : public ::testing::Test { if (disable_after_init_cb) { EXPECT_CALL(*mocks_->audio_renderer(), Initialize(stream, _, _, _, _, _, _, _, _)) - .WillOnce(DoAll(RunPipelineStatusCB2(), - WithArg<7>(RunClosure()))); // |disabled_cb|. + .WillOnce(DoAll(RunCallback<2>(PIPELINE_OK), + WithArg<7>(RunClosure<0>()))); // |disabled_cb|. } else { EXPECT_CALL(*mocks_->audio_renderer(), Initialize(stream, _, _, _, _, _, _, _, _)) .WillOnce(DoAll(SaveArg<5>(&audio_time_cb_), - RunPipelineStatusCB2())); + RunCallback<2>(PIPELINE_OK))); } } @@ -206,9 +193,9 @@ class PipelineTest : public ::testing::Test { // Startup sequence. EXPECT_CALL(*mocks_->audio_renderer(), Preroll(base::TimeDelta(), _)) - .WillOnce(RunPipelineStatusCB()); + .WillOnce(RunCallback<1>(PIPELINE_OK)); EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); } EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kPrerollCompleted)); } @@ -244,32 +231,32 @@ class PipelineTest : public ::testing::Test { void ExpectSeek(const base::TimeDelta& seek_time) { // Every filter should receive a call to Seek(). EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) - .WillOnce(RunPipelineStatusCB()); + .WillOnce(RunCallback<1>(PIPELINE_OK)); EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(_)); if (audio_stream_) { EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); EXPECT_CALL(*mocks_->audio_renderer(), Preroll(seek_time, _)) - .WillOnce(RunPipelineStatusCB()); + .WillOnce(RunCallback<1>(PIPELINE_OK)); EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(_)); EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(_)); EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); } if (video_stream_) { EXPECT_CALL(*mocks_->video_renderer(), Pause(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); EXPECT_CALL(*mocks_->video_renderer(), Flush(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); EXPECT_CALL(*mocks_->video_renderer(), Preroll(seek_time, _)) - .WillOnce(RunPipelineStatusCB()); + .WillOnce(RunCallback<1>(PIPELINE_OK)); EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(_)); EXPECT_CALL(*mocks_->video_renderer(), Play(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); } EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kPrerollCompleted)); @@ -365,18 +352,18 @@ TEST_F(PipelineTest, NeverInitializes) { TEST_F(PipelineTest, URLNotFound) { EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) - .WillOnce(RunPipelineStatusCBWithStatus(PIPELINE_ERROR_URL_NOT_FOUND)); + .WillOnce(RunCallback<1>(PIPELINE_ERROR_URL_NOT_FOUND)); EXPECT_CALL(*mocks_->demuxer(), Stop(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND); } TEST_F(PipelineTest, NoStreams) { EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) - .WillOnce(RunPipelineStatusCB()); + .WillOnce(RunCallback<1>(PIPELINE_OK)); EXPECT_CALL(*mocks_->demuxer(), Stop(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); InitializePipeline(PIPELINE_ERROR_COULD_NOT_RENDER); } @@ -670,16 +657,16 @@ TEST_F(PipelineTest, ErrorDuringSeek) { // Preroll() isn't called as the demuxer errors out first. EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) - .WillOnce(RunPipelineStatusCBWithStatus(PIPELINE_ERROR_READ)); + .WillOnce(RunCallback<1>(PIPELINE_ERROR_READ)); EXPECT_CALL(*mocks_->demuxer(), Stop(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); pipeline_->Seek(seek_time, base::Bind(&CallbackHelper::OnSeek, base::Unretained(&callbacks_))); @@ -725,16 +712,16 @@ TEST_F(PipelineTest, NoMessageDuringTearDownFromError) { // Seek() isn't called as the demuxer errors out first. EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) - .WillOnce(RunPipelineStatusCBWithStatus(PIPELINE_ERROR_READ)); + .WillOnce(RunCallback<1>(PIPELINE_ERROR_READ)); EXPECT_CALL(*mocks_->demuxer(), Stop(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); pipeline_->Seek(seek_time, base::Bind(&CallbackHelper::OnSeek, base::Unretained(&callbacks_))); @@ -814,19 +801,19 @@ TEST_F(PipelineTest, AudioTimeUpdateDuringSeek) { base::Closure closure = base::Bind(&RunTimeCB, audio_time_cb_, 300, 700); EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) .WillOnce(DoAll(InvokeWithoutArgs(&closure, &base::Closure::Run), - RunPipelineStatusCB())); + RunCallback<1>(PIPELINE_OK))); EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); EXPECT_CALL(*mocks_->audio_renderer(), Preroll(seek_time, _)) - .WillOnce(RunPipelineStatusCB()); + .WillOnce(RunCallback<1>(PIPELINE_OK)); EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(_)); EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(_)); EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(_)); EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kPrerollCompleted)); EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); @@ -969,15 +956,16 @@ class PipelineTeardownTest : public PipelineTest { if (state == kInitDemuxer) { if (stop_or_error == kStop) { EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) - .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB())); + .WillOnce(DoAll(Stop(pipeline_, stop_cb), + RunCallback<1>(PIPELINE_OK))); EXPECT_CALL(callbacks_, OnStop()); } else { status = DEMUXER_ERROR_COULD_NOT_OPEN; EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) - .WillOnce(RunPipelineStatusCBWithStatus(status)); + .WillOnce(RunCallback<1>(status)); } - EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); + EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure<0>()); return status; } @@ -992,54 +980,56 @@ class PipelineTeardownTest : public PipelineTest { if (stop_or_error == kStop) { EXPECT_CALL(*mocks_->audio_renderer(), Initialize(_, _, _, _, _, _, _, _, _)) - .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB2())); + .WillOnce(DoAll(Stop(pipeline_, stop_cb), + RunCallback<2>(PIPELINE_OK))); EXPECT_CALL(callbacks_, OnStop()); } else { status = PIPELINE_ERROR_INITIALIZATION_FAILED; EXPECT_CALL(*mocks_->audio_renderer(), Initialize(_, _, _, _, _, _, _, _, _)) - .WillOnce(RunPipelineStatusCB2WithStatus(status)); + .WillOnce(RunCallback<2>(status)); } - EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); - EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); + EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure<0>()); + EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure<0>()); return status; } EXPECT_CALL(*mocks_->audio_renderer(), Initialize(_, _, _, _, _, _, _, _, _)) - .WillOnce(RunPipelineStatusCB2()); + .WillOnce(RunCallback<2>(PIPELINE_OK)); if (state == kInitVideoRenderer) { if (stop_or_error == kStop) { EXPECT_CALL(*mocks_->video_renderer(), Initialize(_, _, _, _, _, _, _, _, _, _)) - .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB2())); + .WillOnce(DoAll(Stop(pipeline_, stop_cb), + RunCallback<2>(PIPELINE_OK))); EXPECT_CALL(callbacks_, OnStop()); } else { status = PIPELINE_ERROR_INITIALIZATION_FAILED; EXPECT_CALL(*mocks_->video_renderer(), Initialize(_, _, _, _, _, _, _, _, _, _)) - .WillOnce(RunPipelineStatusCB2WithStatus(status)); + .WillOnce(RunCallback<2>(status)); } - EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); - EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); - EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure()); + EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure<0>()); + EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure<0>()); + EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure<0>()); return status; } EXPECT_CALL(*mocks_->video_renderer(), Initialize(_, _, _, _, _, _, _, _, _, _)) - .WillOnce(RunPipelineStatusCB2()); + .WillOnce(RunCallback<2>(PIPELINE_OK)); EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kHaveMetadata)); // If we get here it's a successful initialization. EXPECT_CALL(*mocks_->audio_renderer(), Preroll(base::TimeDelta(), _)) - .WillOnce(RunPipelineStatusCB()); + .WillOnce(RunCallback<1>(PIPELINE_OK)); EXPECT_CALL(*mocks_->video_renderer(), Preroll(base::TimeDelta(), _)) - .WillOnce(RunPipelineStatusCB()); + .WillOnce(RunCallback<1>(PIPELINE_OK)); EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); @@ -1047,9 +1037,9 @@ class PipelineTeardownTest : public PipelineTest { EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); EXPECT_CALL(*mocks_->video_renderer(), Play(_)) - .WillOnce(RunClosure()); + .WillOnce(RunClosure<0>()); if (status == PIPELINE_OK) EXPECT_CALL(callbacks_, OnBufferingState(Pipeline::kPrerollCompleted)); @@ -1061,9 +1051,9 @@ class PipelineTeardownTest : public PipelineTest { InSequence s; PipelineStatus status = SetSeekExpectations(state, stop_or_error); - EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); - EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); - EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure()); + EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure<0>()); + EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure<0>()); + EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure<0>()); EXPECT_CALL(callbacks_, OnSeek(status)); if (status == PIPELINE_OK) { @@ -1084,68 +1074,70 @@ class PipelineTeardownTest : public PipelineTest { if (state == kPausing) { if (stop_or_error == kStop) { EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) - .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure())); + .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure<0>())); } else { status = PIPELINE_ERROR_READ; EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) - .WillOnce(DoAll(SetError(pipeline_, status), RunClosure())); + .WillOnce(DoAll(SetError(pipeline_, status), RunClosure<0>())); } return status; } - EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); - EXPECT_CALL(*mocks_->video_renderer(), Pause(_)).WillOnce(RunClosure()); + EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure<0>()); + EXPECT_CALL(*mocks_->video_renderer(), Pause(_)).WillOnce(RunClosure<0>()); if (state == kFlushing) { if (stop_or_error == kStop) { EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) - .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure())); + .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure<0>())); } else { status = PIPELINE_ERROR_READ; EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) - .WillOnce(DoAll(SetError(pipeline_, status), RunClosure())); + .WillOnce(DoAll(SetError(pipeline_, status), RunClosure<0>())); } return status; } - EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); - EXPECT_CALL(*mocks_->video_renderer(), Flush(_)).WillOnce(RunClosure()); + EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure<0>()); + EXPECT_CALL(*mocks_->video_renderer(), Flush(_)).WillOnce(RunClosure<0>()); if (state == kSeeking) { if (stop_or_error == kStop) { EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) - .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB())); + .WillOnce(DoAll(Stop(pipeline_, stop_cb), + RunCallback<1>(PIPELINE_OK))); } else { status = PIPELINE_ERROR_READ; EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) - .WillOnce(RunPipelineStatusCBWithStatus(status)); + .WillOnce(RunCallback<1>(status)); } return status; } EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) - .WillOnce(RunPipelineStatusCB()); + .WillOnce(RunCallback<1>(PIPELINE_OK)); if (state == kPrerolling) { if (stop_or_error == kStop) { EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) - .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB())); + .WillOnce(DoAll(Stop(pipeline_, stop_cb), + RunCallback<1>(PIPELINE_OK))); } else { status = PIPELINE_ERROR_READ; EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) - .WillOnce(RunPipelineStatusCBWithStatus(status)); + .WillOnce(RunCallback<1>(status)); } return status; } EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) - .WillOnce(RunPipelineStatusCB()); + .WillOnce(RunCallback<1>(PIPELINE_OK)); EXPECT_CALL(*mocks_->video_renderer(), Preroll(_, _)) - .WillOnce(RunPipelineStatusCB()); + .WillOnce(RunCallback<1>(PIPELINE_OK)); // Playback rate and volume are updated prior to starting. EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); @@ -1156,11 +1148,11 @@ class PipelineTeardownTest : public PipelineTest { if (state == kStarting) { if (stop_or_error == kStop) { EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) - .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure())); + .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure<0>())); } else { status = PIPELINE_ERROR_READ; EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) - .WillOnce(DoAll(SetError(pipeline_, status), RunClosure())); + .WillOnce(DoAll(SetError(pipeline_, status), RunClosure<0>())); } return status; } @@ -1172,9 +1164,9 @@ class PipelineTeardownTest : public PipelineTest { void DoStopOrError(StopOrError stop_or_error) { InSequence s; - EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); - EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); - EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure()); + EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure<0>()); + EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure<0>()); + EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure<0>()); if (stop_or_error == kStop) { EXPECT_CALL(callbacks_, OnStop()); diff --git a/media/filters/audio_renderer_impl_unittest.cc b/media/filters/audio_renderer_impl_unittest.cc index dff1733..cfc3144 100644 --- a/media/filters/audio_renderer_impl_unittest.cc +++ b/media/filters/audio_renderer_impl_unittest.cc @@ -8,6 +8,7 @@ #include "base/message_loop.h" #include "base/stl_util.h" #include "media/base/data_buffer.h" +#include "media/base/gmock_callback_support.h" #include "media/base/mock_audio_renderer_sink.h" #include "media/base/mock_callback.h" #include "media/base/mock_filters.h" @@ -21,10 +22,6 @@ using ::testing::Return; using ::testing::NiceMock; using ::testing::StrictMock; -ACTION_P(RunPipelineStatusCB1, status) { - arg1.Run(status); -} - namespace media { // Constants for distinguishing between muted audio and playing audio when using @@ -100,7 +97,7 @@ class AudioRendererImplTest : public ::testing::Test { void Initialize() { EXPECT_CALL(*decoder_, Initialize(_, _, _)) - .WillOnce(RunPipelineStatusCB1(PIPELINE_OK)); + .WillOnce(RunCallback<1>(PIPELINE_OK)); InitializeWithStatus(PIPELINE_OK); message_loop_.RunUntilIdle(); @@ -246,7 +243,7 @@ class AudioRendererImplTest : public ::testing::Test { TEST_F(AudioRendererImplTest, Initialize_Failed) { EXPECT_CALL(*decoder_, Initialize(_, _, _)) - .WillOnce(RunPipelineStatusCB1(PIPELINE_OK)); + .WillOnce(RunCallback<1>(PIPELINE_OK)); SetUnsupportedAudioDecoderProperties(); InitializeWithStatus(PIPELINE_ERROR_INITIALIZATION_FAILED); @@ -264,7 +261,7 @@ TEST_F(AudioRendererImplTest, Initialize_Successful) { TEST_F(AudioRendererImplTest, Initialize_DecoderInitFailure) { EXPECT_CALL(*decoder_, Initialize(_, _, _)) - .WillOnce(RunPipelineStatusCB1(PIPELINE_ERROR_DECODE)); + .WillOnce(RunCallback<1>(PIPELINE_ERROR_DECODE)); InitializeWithStatus(PIPELINE_ERROR_DECODE); // We should have no reads. @@ -276,9 +273,9 @@ TEST_F(AudioRendererImplTest, Initialize_MultipleDecoders) { // Insert |decoder1| as the first decoder in the list. decoders_.push_front(decoder1); EXPECT_CALL(*decoder1, Initialize(_, _, _)) - .WillOnce(RunPipelineStatusCB1(DECODER_ERROR_NOT_SUPPORTED)); + .WillOnce(RunCallback<1>(DECODER_ERROR_NOT_SUPPORTED)); EXPECT_CALL(*decoder_, Initialize(_, _, _)) - .WillOnce(RunPipelineStatusCB1(PIPELINE_OK)); + .WillOnce(RunCallback<1>(PIPELINE_OK)); InitializeWithStatus(PIPELINE_OK); // We should have no reads. diff --git a/media/filters/decrypting_audio_decoder_unittest.cc b/media/filters/decrypting_audio_decoder_unittest.cc index bf3684fc..24e9eba 100644 --- a/media/filters/decrypting_audio_decoder_unittest.cc +++ b/media/filters/decrypting_audio_decoder_unittest.cc @@ -12,6 +12,7 @@ #include "media/base/data_buffer.h" #include "media/base/decoder_buffer.h" #include "media/base/decrypt_config.h" +#include "media/base/gmock_callback_support.h" #include "media/base/mock_callback.h" #include "media/base/mock_filters.h" #include "media/filters/decrypting_audio_decoder.h" @@ -53,32 +54,16 @@ ACTION_P(ReturnBuffer, buffer) { arg0.Run(buffer ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer); } -ACTION(ReturnConfigChanged) { - arg0.Run(DemuxerStream::kConfigChanged, scoped_refptr<DecoderBuffer>(NULL)); -} - -ACTION_P(RunCallback0, param) { +ACTION_P(RunCallbackIfNotNull, param) { if (!arg0.is_null()) arg0.Run(param); } -ACTION_P(RunCallback1, param) { - arg1.Run(param); -} - -ACTION_P2(RunCallback2, param1, param2) { - arg1.Run(param1, param2); -} - ACTION_P2(ResetAndRunCallback, callback, param) { base::ResetAndReturn(callback).Run(param); } -MATCHER(IsNullCallback, "") { - return (arg.is_null()); -} - -MATCHER(IsEndOfStream, "") { +MATCHER(IsEndOfStream, "end of stream") { return (arg->IsEndOfStream()); } @@ -120,9 +105,9 @@ class DecryptingAudioDecoderTest : public testing::Test { void Initialize() { EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _)) .Times(AtMost(1)) - .WillOnce(RunCallback1(true)); + .WillOnce(RunCallback<1>(true)); EXPECT_CALL(*this, RequestDecryptorNotification(_)) - .WillOnce(RunCallback0(decryptor_.get())); + .WillOnce(RunCallbackIfNotNull(decryptor_.get())); EXPECT_CALL(*decryptor_, RegisterKeyAddedCB(Decryptor::kAudio, _)) .WillOnce(SaveArg<1>(&key_added_cb_)); @@ -159,10 +144,9 @@ class DecryptingAudioDecoderTest : public testing::Test { .WillOnce(ReturnBuffer(encrypted_buffer_)) .WillRepeatedly(ReturnBuffer(DecoderBuffer::CreateEOSBuffer())); EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) - .WillOnce(RunCallback2(Decryptor::kSuccess, - decoded_frame_list_)) - .WillRepeatedly(RunCallback2(Decryptor::kNeedMoreData, - Decryptor::AudioBuffers())); + .WillOnce(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)) + .WillRepeatedly(RunCallback<1>(Decryptor::kNeedMoreData, + Decryptor::AudioBuffers())); EXPECT_CALL(statistics_cb_, OnStatistics(_)); ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_); @@ -207,8 +191,8 @@ class DecryptingAudioDecoderTest : public testing::Test { EXPECT_CALL(*demuxer_, Read(_)) .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) - .WillRepeatedly(RunCallback2(Decryptor::kNoKey, - Decryptor::AudioBuffers())); + .WillRepeatedly(RunCallback<1>(Decryptor::kNoKey, + Decryptor::AudioBuffers())); decoder_->Read(base::Bind(&DecryptingAudioDecoderTest::FrameReady, base::Unretained(this))); message_loop_.RunAllPending(); @@ -281,9 +265,9 @@ TEST_F(DecryptingAudioDecoderTest, Initialize_InvalidAudioConfig) { // Ensure decoder handles unsupported audio configs without crashing. TEST_F(DecryptingAudioDecoderTest, Initialize_UnsupportedAudioConfig) { EXPECT_CALL(*decryptor_, InitializeAudioDecoderMock(_, _)) - .WillOnce(RunCallback1(false)); + .WillOnce(RunCallback<1>(false)); EXPECT_CALL(*this, RequestDecryptorNotification(_)) - .WillOnce(RunCallback0(decryptor_.get())); + .WillOnce(RunCallbackIfNotNull(decryptor_.get())); AudioDecoderConfig config(kCodecVorbis, 16, CHANNEL_LAYOUT_STEREO, 44100, NULL, 0, true); @@ -304,8 +288,8 @@ TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_DecodeError) { EXPECT_CALL(*demuxer_, Read(_)) .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) - .WillRepeatedly(RunCallback2(Decryptor::kError, - Decryptor::AudioBuffers())); + .WillRepeatedly(RunCallback<1>(Decryptor::kError, + Decryptor::AudioBuffers())); ReadAndExpectFrameReadyWith(AudioDecoder::kDecodeError, NULL); } @@ -319,9 +303,9 @@ TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_NeedMoreData) { .Times(2) .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) - .WillOnce(RunCallback2(Decryptor::kNeedMoreData, - Decryptor::AudioBuffers())) - .WillRepeatedly(RunCallback2(Decryptor::kSuccess, decoded_frame_list_)); + .WillOnce(RunCallback<1>(Decryptor::kNeedMoreData, + Decryptor::AudioBuffers())) + .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); EXPECT_CALL(statistics_cb_, OnStatistics(_)) .Times(2); @@ -342,7 +326,7 @@ TEST_F(DecryptingAudioDecoderTest, DecryptAndDecode_MultipleFrames) { EXPECT_CALL(*demuxer_, Read(_)) .WillOnce(ReturnBuffer(encrypted_buffer_)); EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) - .WillOnce(RunCallback2(Decryptor::kSuccess, decoded_frame_list_)); + .WillOnce(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); EXPECT_CALL(statistics_cb_, OnStatistics(_)); ReadAndExpectFrameReadyWith(AudioDecoder::kOk, decoded_frame_); @@ -364,7 +348,7 @@ TEST_F(DecryptingAudioDecoderTest, KeyAdded_DuringWaitingForKey) { EnterWaitingForKeyState(); EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) - .WillRepeatedly(RunCallback2(Decryptor::kSuccess, decoded_frame_list_)); + .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); EXPECT_CALL(statistics_cb_, OnStatistics(_)); EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, decoded_frame_)); key_added_cb_.Run(); @@ -378,7 +362,7 @@ TEST_F(DecryptingAudioDecoderTest, KeyAdded_DruingPendingDecode) { EnterPendingDecodeState(); EXPECT_CALL(*decryptor_, DecryptAndDecodeAudio(_, _)) - .WillRepeatedly(RunCallback2(Decryptor::kSuccess, decoded_frame_list_)); + .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, decoded_frame_list_)); EXPECT_CALL(statistics_cb_, OnStatistics(_)); EXPECT_CALL(*this, FrameReady(AudioDecoder::kOk, decoded_frame_)); // The audio decode callback is returned after the correct decryption key is @@ -484,7 +468,8 @@ TEST_F(DecryptingAudioDecoderTest, DemuxerRead_ConfigChanged) { Initialize(); EXPECT_CALL(*demuxer_, Read(_)) - .WillOnce(ReturnConfigChanged()); + .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged, + scoped_refptr<DecoderBuffer>())); // TODO(xhwang): Update this test when kConfigChanged is supported in // DecryptingAudioDecoder. diff --git a/media/filters/decrypting_video_decoder_unittest.cc b/media/filters/decrypting_video_decoder_unittest.cc index 2b3666b..d35facf 100644 --- a/media/filters/decrypting_video_decoder_unittest.cc +++ b/media/filters/decrypting_video_decoder_unittest.cc @@ -10,6 +10,7 @@ #include "base/message_loop.h" #include "media/base/decoder_buffer.h" #include "media/base/decrypt_config.h" +#include "media/base/gmock_callback_support.h" #include "media/base/mock_callback.h" #include "media/base/mock_filters.h" #include "media/base/video_frame.h" @@ -55,32 +56,16 @@ ACTION_P(ReturnBuffer, buffer) { arg0.Run(buffer ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer); } -ACTION(ReturnConfigChanged) { - arg0.Run(DemuxerStream::kConfigChanged, scoped_refptr<DecoderBuffer>(NULL)); -} - -ACTION_P(RunCallback0, param) { +ACTION_P(RunCallbackIfNotNull, param) { if (!arg0.is_null()) arg0.Run(param); } -ACTION_P(RunCallback1, param) { - arg1.Run(param); -} - -ACTION_P2(RunCallback2, param1, param2) { - arg1.Run(param1, param2); -} - ACTION_P2(ResetAndRunCallback, callback, param) { base::ResetAndReturn(callback).Run(param); } -MATCHER(IsNullCallback, "") { - return (arg.is_null()); -} - -MATCHER(IsEndOfStream, "") { +MATCHER(IsEndOfStream, "end of stream") { return (arg->IsEndOfStream()); } @@ -112,7 +97,7 @@ class DecryptingVideoDecoderTest : public testing::Test { EXPECT_CALL(*demuxer_, video_decoder_config()) .WillRepeatedly(ReturnRef(config)); EXPECT_CALL(*this, RequestDecryptorNotification(_)) - .WillOnce(RunCallback0(decryptor_.get())); + .WillOnce(RunCallbackIfNotNull(decryptor_.get())); decoder_->Initialize(demuxer_, NewExpectedStatusCB(status), base::Bind(&MockStatisticsCB::OnStatistics, @@ -123,7 +108,7 @@ class DecryptingVideoDecoderTest : public testing::Test { void Initialize() { EXPECT_CALL(*decryptor_, InitializeVideoDecoderMock(_, _)) .Times(AtMost(1)) - .WillOnce(RunCallback1(true)); + .WillOnce(RunCallback<1>(true)); EXPECT_CALL(*decryptor_, RegisterKeyAddedCB(Decryptor::kVideo, _)) .WillOnce(SaveArg<1>(&key_added_cb_)); @@ -156,9 +141,9 @@ class DecryptingVideoDecoderTest : public testing::Test { .WillOnce(ReturnBuffer(encrypted_buffer_)) .WillRepeatedly(ReturnBuffer(DecoderBuffer::CreateEOSBuffer())); EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) - .WillOnce(RunCallback2(Decryptor::kSuccess, decoded_video_frame_)) - .WillRepeatedly(RunCallback2(Decryptor::kNeedMoreData, - scoped_refptr<VideoFrame>())); + .WillOnce(RunCallback<1>(Decryptor::kSuccess, decoded_video_frame_)) + .WillRepeatedly(RunCallback<1>(Decryptor::kNeedMoreData, + scoped_refptr<VideoFrame>())); EXPECT_CALL(statistics_cb_, OnStatistics(_)); ReadAndExpectFrameReadyWith(VideoDecoder::kOk, decoded_video_frame_); @@ -203,7 +188,7 @@ class DecryptingVideoDecoderTest : public testing::Test { EXPECT_CALL(*demuxer_, Read(_)) .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) - .WillRepeatedly(RunCallback2(Decryptor::kNoKey, null_video_frame_)); + .WillRepeatedly(RunCallback<1>(Decryptor::kNoKey, null_video_frame_)); decoder_->Read(base::Bind(&DecryptingVideoDecoderTest::FrameReady, base::Unretained(this))); message_loop_.RunAllPending(); @@ -302,7 +287,7 @@ TEST_F(DecryptingVideoDecoderTest, Initialize_InvalidVideoConfig) { // Ensure decoder handles unsupported video configs without crashing. TEST_F(DecryptingVideoDecoderTest, Initialize_UnsupportedVideoConfig) { EXPECT_CALL(*decryptor_, InitializeVideoDecoderMock(_, _)) - .WillOnce(RunCallback1(false)); + .WillOnce(RunCallback<1>(false)); VideoDecoderConfig config(kCodecVP8, VIDEO_CODEC_PROFILE_UNKNOWN, kVideoFormat, @@ -326,7 +311,7 @@ TEST_F(DecryptingVideoDecoderTest, DecryptAndDecode_DecodeError) { EXPECT_CALL(*demuxer_, Read(_)) .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) - .WillRepeatedly(RunCallback2(Decryptor::kError, + .WillRepeatedly(RunCallback<1>(Decryptor::kError, scoped_refptr<VideoFrame>(NULL))); ReadAndExpectFrameReadyWith(VideoDecoder::kDecodeError, null_video_frame_); @@ -341,9 +326,10 @@ TEST_F(DecryptingVideoDecoderTest, DecryptAndDecode_NeedMoreData) { .Times(2) .WillRepeatedly(ReturnBuffer(encrypted_buffer_)); EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) - .WillOnce(RunCallback2(Decryptor::kNeedMoreData, + .WillOnce(RunCallback<1>(Decryptor::kNeedMoreData, scoped_refptr<VideoFrame>())) - .WillRepeatedly(RunCallback2(Decryptor::kSuccess, decoded_video_frame_)); + .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, + decoded_video_frame_)); EXPECT_CALL(statistics_cb_, OnStatistics(_)) .Times(2); @@ -364,7 +350,8 @@ TEST_F(DecryptingVideoDecoderTest, KeyAdded_DuringWaitingForKey) { EnterWaitingForKeyState(); EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) - .WillRepeatedly(RunCallback2(Decryptor::kSuccess, decoded_video_frame_)); + .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, + decoded_video_frame_)); EXPECT_CALL(statistics_cb_, OnStatistics(_)); EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, decoded_video_frame_)); key_added_cb_.Run(); @@ -378,7 +365,8 @@ TEST_F(DecryptingVideoDecoderTest, KeyAdded_DruingPendingDecode) { EnterPendingDecodeState(); EXPECT_CALL(*decryptor_, DecryptAndDecodeVideo(_, _)) - .WillRepeatedly(RunCallback2(Decryptor::kSuccess, decoded_video_frame_)); + .WillRepeatedly(RunCallback<1>(Decryptor::kSuccess, + decoded_video_frame_)); EXPECT_CALL(statistics_cb_, OnStatistics(_)); EXPECT_CALL(*this, FrameReady(VideoDecoder::kOk, decoded_video_frame_)); // The video decode callback is returned after the correct decryption key is @@ -611,7 +599,8 @@ TEST_F(DecryptingVideoDecoderTest, DemuxerRead_ConfigChanged) { Initialize(); EXPECT_CALL(*demuxer_, Read(_)) - .WillOnce(ReturnConfigChanged()); + .WillOnce(RunCallback<0>(DemuxerStream::kConfigChanged, + scoped_refptr<DecoderBuffer>())); // TODO(xhwang): Update this test when kConfigChanged is supported in // DecryptingVideoDecoder. diff --git a/media/filters/ffmpeg_video_decoder_unittest.cc b/media/filters/ffmpeg_video_decoder_unittest.cc index 52e02d2..9186ca3 100644 --- a/media/filters/ffmpeg_video_decoder_unittest.cc +++ b/media/filters/ffmpeg_video_decoder_unittest.cc @@ -12,6 +12,7 @@ #include "base/string_util.h" #include "media/base/decoder_buffer.h" #include "media/base/decrypt_config.h" +#include "media/base/gmock_callback_support.h" #include "media/base/limits.h" #include "media/base/mock_callback.h" #include "media/base/mock_filters.h" @@ -62,10 +63,6 @@ ACTION_P(ReturnBuffer, buffer) { arg0.Run(buffer ? DemuxerStream::kOk : DemuxerStream::kAborted, buffer); } -ACTION_P2(RunDecryptCB, status, buffer) { - arg2.Run(status, buffer); -} - class FFmpegVideoDecoderTest : public testing::Test { public: FFmpegVideoDecoderTest() @@ -471,7 +468,7 @@ TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_Normal) { // Simulate decoding a single encrypted frame. EXPECT_CALL(*decryptor_, Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _)) - .WillRepeatedly(RunDecryptCB(Decryptor::kSuccess, i_frame_buffer_)); + .WillRepeatedly(RunCallback<2>(Decryptor::kSuccess, i_frame_buffer_)); VideoDecoder::Status status; scoped_refptr<VideoFrame> video_frame; @@ -491,8 +488,8 @@ TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_DecryptError) { .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); EXPECT_CALL(*decryptor_, Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _)) - .WillRepeatedly(RunDecryptCB(Decryptor::kError, - scoped_refptr<media::DecoderBuffer>())); + .WillRepeatedly(RunCallback<2>(Decryptor::kError, + scoped_refptr<media::DecoderBuffer>())); // Our read should still get satisfied with end of stream frame during an // error. @@ -514,8 +511,8 @@ TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_NoDecryptionKey) { .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); EXPECT_CALL(*decryptor_, Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _)) - .WillRepeatedly(RunDecryptCB(Decryptor::kNoKey, - scoped_refptr<media::DecoderBuffer>())); + .WillRepeatedly(RunCallback<2>(Decryptor::kNoKey, + scoped_refptr<media::DecoderBuffer>())); // Our read should still get satisfied with end of stream frame during an // error. @@ -538,8 +535,8 @@ TEST_F(FFmpegVideoDecoderTest, DecodeEncryptedFrame_CorruptedBufferReturned) { .WillRepeatedly(ReturnBuffer(encrypted_i_frame_buffer_)); EXPECT_CALL(*decryptor_, Decrypt(Decryptor::kVideo, encrypted_i_frame_buffer_, _)) - .WillRepeatedly(RunDecryptCB(Decryptor::kSuccess, - corrupt_i_frame_buffer_)); + .WillRepeatedly(RunCallback<2>(Decryptor::kSuccess, + corrupt_i_frame_buffer_)); // The decoder only detects the error at the second decoding call. So // |statistics_cb_| still gets called once. EXPECT_CALL(statistics_cb_, OnStatistics(_)); diff --git a/media/filters/video_renderer_base_unittest.cc b/media/filters/video_renderer_base_unittest.cc index 9ce8a9c..2e6cc12 100644 --- a/media/filters/video_renderer_base_unittest.cc +++ b/media/filters/video_renderer_base_unittest.cc @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <algorithm> + #include "base/bind.h" #include "base/callback.h" #include "base/stl_util.h" @@ -11,6 +13,7 @@ #include "base/synchronization/waitable_event.h" #include "base/test/test_timeouts.h" #include "media/base/data_buffer.h" +#include "media/base/gmock_callback_support.h" #include "media/base/limits.h" #include "media/base/mock_callback.h" #include "media/base/mock_filters.h" @@ -34,10 +37,6 @@ static const int kVideoDuration = kFrameDuration * 100; static const int kEndOfStream = -1; static const gfx::Size kNaturalSize(16u, 16u); -ACTION_P(RunPipelineStatusCB1, status) { - arg1.Run(status); -} - class VideoRendererBaseTest : public ::testing::Test { public: VideoRendererBaseTest() @@ -61,7 +60,7 @@ class VideoRendererBaseTest : public ::testing::Test { // We expect these to be called but we don't care how/when. EXPECT_CALL(*decoder_, Stop(_)) - .WillRepeatedly(RunClosure()); + .WillRepeatedly(RunClosure<0>()); EXPECT_CALL(statistics_cb_object_, OnStatistics(_)) .Times(AnyNumber()); EXPECT_CALL(*this, OnTimeUpdate(_)) @@ -107,7 +106,7 @@ class VideoRendererBaseTest : public ::testing::Test { InSequence s; EXPECT_CALL(*decoder_, Initialize(_, _, _)) - .WillOnce(RunPipelineStatusCB1(PIPELINE_OK)); + .WillOnce(RunCallback<1>(PIPELINE_OK)); // Set playback rate before anything else happens. renderer_->SetPlaybackRate(1.0f); @@ -695,7 +694,7 @@ TEST_F(VideoRendererBaseTest, VideoDecoder_InitFailure) { InSequence s; EXPECT_CALL(*decoder_, Initialize(_, _, _)) - .WillOnce(RunPipelineStatusCB1(PIPELINE_ERROR_DECODE)); + .WillOnce(RunCallback<1>(PIPELINE_ERROR_DECODE)); InitializeRenderer(PIPELINE_ERROR_DECODE); } diff --git a/media/media.gyp b/media/media.gyp index 2031926..9fb5f37 100644 --- a/media/media.gyp +++ b/media/media.gyp @@ -629,6 +629,7 @@ 'base/decoder_buffer_unittest.cc', 'base/djb2_unittest.cc', 'base/filter_collection_unittest.cc', + 'base/gmock_callback_support_unittest.cc', 'base/multi_channel_resampler_unittest.cc', 'base/pipeline_unittest.cc', 'base/ranges_unittest.cc', @@ -778,6 +779,7 @@ 'audio/test_audio_input_controller_factory.h', 'base/fake_audio_render_callback.cc', 'base/fake_audio_render_callback.h', + 'base/gmock_callback_support.h', 'base/mock_audio_renderer_sink.cc', 'base/mock_audio_renderer_sink.h', 'base/mock_callback.cc', |