diff options
author | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-15 02:10:46 +0000 |
---|---|---|
committer | scherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-15 02:10:46 +0000 |
commit | e93e25629859d7d7f08428abd5bdad8a403515d4 (patch) | |
tree | 7226891aaed52aeed48922e8293ab05df72e42e1 /media/base/mock_callback.h | |
parent | 86809eba59ca96feb557e98bbc5bdcf03c0c149b (diff) | |
download | chromium_src-e93e25629859d7d7f08428abd5bdad8a403515d4.zip chromium_src-e93e25629859d7d7f08428abd5bdad8a403515d4.tar.gz chromium_src-e93e25629859d7d7f08428abd5bdad8a403515d4.tar.bz2 |
Replace MockFilterCallback with MockCallback and simplify unit tests.
We had a ton of unnecessarily duplicated code, most of which could be solved by introducing NewExpectedCallback().
BUG=none
TEST=media_unittests
Review URL: http://codereview.chromium.org/6350001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71537 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/mock_callback.h')
-rw-r--r-- | media/base/mock_callback.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/media/base/mock_callback.h b/media/base/mock_callback.h new file mode 100644 index 0000000..2aef84a --- /dev/null +++ b/media/base/mock_callback.h @@ -0,0 +1,57 @@ +// Copyright (c) 2011 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_MOCK_CALLBACK_H_ +#define MEDIA_BASE_MOCK_CALLBACK_H_ + +#include "base/callback.h" +#include "testing/gmock/include/gmock/gmock.h" + +namespace media { + +// Helper class used to test that callbacks are executed. +// +// In most cases NewExpectedCallback() can be used but if need be you can +// manually set expectations on an MockCallback object: +// +// StrictMock<MockCallback>* callback = +// new StrictMock<MockCallback>(); +// EXPECT_CALL(*callback, RunWithParams(_)); +// EXPECT_CALL(*callback, Destructor()); +// +// ...or the equivalent and less verbose: +// StrictMock<MockCallback>* callback = +// new StrictMock<MockCallback>(); +// callback->ExpectRunAndDelete(); +// +// ...or if you don't care about verifying callback deletion: +// +// NiceMock<MockCallback>* callback = +// new NiceMock<MockCallback>(); +// EXPECT_CALL(*callback, RunWithParams(_)); +class MockCallback : public CallbackRunner<Tuple0> { + public: + MockCallback(); + virtual ~MockCallback(); + + MOCK_METHOD1(RunWithParams, void(const Tuple0& params)); + + // Can be used to verify the object is destroyed. + MOCK_METHOD0(Destructor, void()); + + // Convenience function to set expectations for the callback to execute and + // deleted. + void ExpectRunAndDelete(); + + private: + DISALLOW_COPY_AND_ASSIGN(MockCallback); +}; + +// Convenience function that automatically creates and sets an expectation for +// the callback to run. +MockCallback* NewExpectedCallback(); + +} // namespace media + +#endif // MEDIA_BASE_MOCK_CALLBACK_H_ |