// 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, // MockRepeatingCallback, MockOnceClosure and MockRepeatingClosure. // // Use: // using FooCallback = base::RepeatingCallback; // // TEST(FooTest, RunsCallbackWithBarArgument) { // base::MockCallback callback; // EXPECT_CALL(callback, Run("bar")).WillOnce(Return(1)); // Foo(callback.Get()); // } // // Or equivalently: // // TEST(FooTest, RunsCallbackWithBarArgument) { // base::MockRepeatingCallback 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 class MockCallback; template using MockOnceCallback = MockCallback>; template using MockRepeatingCallback = MockCallback>; using MockOnceClosure = MockCallback; using MockRepeatingClosure = MockCallback; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD0_T(Run, R()); RepeatingCallback Get() { return BindRepeating(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD0_T(Run, R()); OnceCallback Get() { return BindOnce(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD1_T(Run, R(A1)); RepeatingCallback Get() { return BindRepeating(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD1_T(Run, R(A1)); OnceCallback Get() { return BindOnce(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD2_T(Run, R(A1, A2)); RepeatingCallback Get() { return BindRepeating(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD2_T(Run, R(A1, A2)); OnceCallback Get() { return BindOnce(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD3_T(Run, R(A1, A2, A3)); RepeatingCallback Get() { return BindRepeating(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD3_T(Run, R(A1, A2, A3)); OnceCallback Get() { return BindOnce(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD4_T(Run, R(A1, A2, A3, A4)); RepeatingCallback Get() { return BindRepeating(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD4_T(Run, R(A1, A2, A3, A4)); OnceCallback Get() { return BindOnce(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD5_T(Run, R(A1, A2, A3, A4, A5)); RepeatingCallback Get() { return BindRepeating(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD5_T(Run, R(A1, A2, A3, A4, A5)); OnceCallback Get() { return BindOnce(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD6_T(Run, R(A1, A2, A3, A4, A5, A6)); RepeatingCallback Get() { return BindRepeating(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD6_T(Run, R(A1, A2, A3, A4, A5, A6)); OnceCallback Get() { return BindOnce(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD7_T(Run, R(A1, A2, A3, A4, A5, A6, A7)); RepeatingCallback Get() { return BindRepeating(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD7_T(Run, R(A1, A2, A3, A4, A5, A6, A7)); OnceCallback Get() { return BindOnce(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD8_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8)); RepeatingCallback Get() { return BindRepeating(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD8_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8)); OnceCallback Get() { return BindOnce(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD9_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8, A9)); RepeatingCallback Get() { return BindRepeating(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD9_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8, A9)); OnceCallback Get() { return BindOnce(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD10_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)); RepeatingCallback Get() { return BindRepeating(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; template class MockCallback> { public: MockCallback() = default; MOCK_METHOD10_T(Run, R(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)); OnceCallback Get() { return BindOnce(&MockCallback::Run, Unretained(this)); } private: DISALLOW_COPY_AND_ASSIGN(MockCallback); }; // clang-format on } // namespace base #endif // BASE_TEST_MOCK_CALLBACK_H_