123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- // This file was GENERATED by command:
- // pump.py mock_callback.h.pump
- // DO NOT EDIT BY HAND!!!
- // Copyright 2017 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.
- // Analogous to GMock's built-in MockFunction, but for base::Callback instead of
- // std::function. It takes the full callback type as a parameter, so that it can
- // support both OnceCallback and RepeatingCallback. Furthermore, this file
- // defines convenience typedefs in the form of MockOnceCallback<Signature>,
- // MockRepeatingCallback<Signature>, MockOnceClosure and MockRepeatingClosure.
- //
- // Use:
- // using FooCallback = base::RepeatingCallback<int(std::string)>;
- //
- // TEST(FooTest, RunsCallbackWithBarArgument) {
- // base::MockCallback<FooCallback> callback;
- // EXPECT_CALL(callback, Run("bar")).WillOnce(Return(1));
- // Foo(callback.Get());
- // }
- //
- // Or equivalently:
- //
- // TEST(FooTest, RunsCallbackWithBarArgument) {
- // base::MockRepeatingCallback<int(std::string)> callback;
- // EXPECT_CALL(callback, Run("bar")).WillOnce(Return(1));
- // Foo(callback.Get());
- // }
- //
- //
- // Can be used with StrictMock and NiceMock. Caller must ensure that it outlives
- // any base::Callback obtained from it.
- #ifndef BASE_TEST_MOCK_CALLBACK_H_
- #define BASE_TEST_MOCK_CALLBACK_H_
- #include "base/bind.h"
- #include "base/callback.h"
- #include "base/macros.h"
- #include "testing/gmock/include/gmock/gmock.h"
- namespace base {
- // clang-format off
- template <typename F>
- class MockCallback;
- template <typename Signature>
- using MockOnceCallback = MockCallback<OnceCallback<Signature>>;
- template <typename Signature>
- using MockRepeatingCallback = MockCallback<RepeatingCallback<Signature>>;
- using MockOnceClosure = MockCallback<OnceClosure>;
- using MockRepeatingClosure = MockCallback<RepeatingClosure>;
- template <typename R>
- class MockCallback<RepeatingCallback<R()>> {
- public:
- MockCallback() = default;
- MOCK_METHOD0_T(Run, R());
- RepeatingCallback<R()> Get() {
- return BindRepeating(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R>
- class MockCallback<OnceCallback<R()>> {
- public:
- MockCallback() = default;
- MOCK_METHOD0_T(Run, R());
- OnceCallback<R()> Get() {
- return BindOnce(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1>
- class MockCallback<RepeatingCallback<R(A1)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD1_T(Run, R(A1));
- RepeatingCallback<R(A1)> Get() {
- return BindRepeating(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1>
- class MockCallback<OnceCallback<R(A1)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD1_T(Run, R(A1));
- OnceCallback<R(A1)> Get() {
- return BindOnce(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2>
- class MockCallback<RepeatingCallback<R(A1, A2)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD2_T(Run, R(A1, A2));
- RepeatingCallback<R(A1, A2)> Get() {
- return BindRepeating(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2>
- class MockCallback<OnceCallback<R(A1, A2)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD2_T(Run, R(A1, A2));
- OnceCallback<R(A1, A2)> Get() {
- return BindOnce(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2, typename A3>
- class MockCallback<RepeatingCallback<R(A1, A2, A3)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD3_T(Run, R(A1, A2, A3));
- RepeatingCallback<R(A1, A2, A3)> Get() {
- return BindRepeating(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2, typename A3>
- class MockCallback<OnceCallback<R(A1, A2, A3)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD3_T(Run, R(A1, A2, A3));
- OnceCallback<R(A1, A2, A3)> Get() {
- return BindOnce(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2, typename A3, typename A4>
- class MockCallback<RepeatingCallback<R(A1, A2, A3, A4)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD4_T(Run, R(A1, A2, A3, A4));
- RepeatingCallback<R(A1, A2, A3, A4)> Get() {
- return BindRepeating(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2, typename A3, typename A4>
- class MockCallback<OnceCallback<R(A1, A2, A3, A4)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD4_T(Run, R(A1, A2, A3, A4));
- OnceCallback<R(A1, A2, A3, A4)> Get() {
- return BindOnce(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2, typename A3, typename A4,
- typename A5>
- class MockCallback<RepeatingCallback<R(A1, A2, A3, A4, A5)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD5_T(Run, R(A1, A2, A3, A4, A5));
- RepeatingCallback<R(A1, A2, A3, A4, A5)> Get() {
- return BindRepeating(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2, typename A3, typename A4,
- typename A5>
- class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD5_T(Run, R(A1, A2, A3, A4, A5));
- OnceCallback<R(A1, A2, A3, A4, A5)> Get() {
- return BindOnce(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2, typename A3, typename A4,
- typename A5, typename A6>
- class MockCallback<RepeatingCallback<R(A1, A2, A3, A4, A5, A6)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD6_T(Run, R(A1, A2, A3, A4, A5, A6));
- RepeatingCallback<R(A1, A2, A3, A4, A5, A6)> Get() {
- return BindRepeating(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2, typename A3, typename A4,
- typename A5, typename A6>
- class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5, A6)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD6_T(Run, R(A1, A2, A3, A4, A5, A6));
- OnceCallback<R(A1, A2, A3, A4, A5, A6)> Get() {
- return BindOnce(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2, typename A3, typename A4,
- typename A5, typename A6, typename A7>
- class MockCallback<RepeatingCallback<R(A1, A2, A3, A4, A5, A6, A7)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD7_T(Run, R(A1, A2, A3, A4, A5, A6, A7));
- RepeatingCallback<R(A1, A2, A3, A4, A5, A6, A7)> Get() {
- return BindRepeating(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2, typename A3, typename A4,
- typename A5, typename A6, typename A7>
- class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5, A6, A7)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD7_T(Run, R(A1, A2, A3, A4, A5, A6, A7));
- OnceCallback<R(A1, A2, A3, A4, A5, A6, A7)> Get() {
- return BindOnce(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2, typename A3, typename A4,
- typename A5, typename A6, typename A7, typename A8>
- class MockCallback<RepeatingCallback<R(A1, A2, A3, A4, A5, A6, A7, A8)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD8_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8));
- RepeatingCallback<R(A1, A2, A3, A4, A5, A6, A7, A8)> Get() {
- return BindRepeating(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2, typename A3, typename A4,
- typename A5, typename A6, typename A7, typename A8>
- class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD8_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8));
- OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8)> Get() {
- return BindOnce(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2, typename A3, typename A4,
- typename A5, typename A6, typename A7, typename A8, typename A9>
- class MockCallback<RepeatingCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD9_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8, A9));
- RepeatingCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> Get() {
- return BindRepeating(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2, typename A3, typename A4,
- typename A5, typename A6, typename A7, typename A8, typename A9>
- class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD9_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8, A9));
- OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9)> Get() {
- return BindOnce(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2, typename A3, typename A4,
- typename A5, typename A6, typename A7, typename A8, typename A9,
- typename A10>
- class MockCallback<RepeatingCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9,
- A10)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD10_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10));
- RepeatingCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> Get() {
- return BindRepeating(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- template <typename R, typename A1, typename A2, typename A3, typename A4,
- typename A5, typename A6, typename A7, typename A8, typename A9,
- typename A10>
- class MockCallback<OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)>> {
- public:
- MockCallback() = default;
- MOCK_METHOD10_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10));
- OnceCallback<R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)> Get() {
- return BindOnce(&MockCallback::Run, Unretained(this));
- }
- private:
- DISALLOW_COPY_AND_ASSIGN(MockCallback);
- };
- // clang-format on
- } // namespace base
- #endif // BASE_TEST_MOCK_CALLBACK_H_
|