123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- $$ -*- mode: c++; -*-
- $$ This is a Pump source file. Please use Pump to convert
- $$ it to gmock-generated-function-mockers.h.
- $$
- $var n = 10 $$ The maximum arity we support.
- #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
- #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_FUNCTION_MOCKERS_H_
- #include "gmock/gmock-spec-builders.h"
- #include "gmock/internal/gmock-internal-utils.h"
- #if GTEST_HAS_STD_FUNCTION_
- # include <functional>
- #endif
- namespace testing {
- namespace internal {
- template <typename F>
- class FunctionMockerBase;
- template <typename F>
- class FunctionMocker;
- $range i 0..n
- $for i [[
- $range j 1..i
- $var typename_As = [[$for j [[, typename A$j]]]]
- $var As = [[$for j, [[A$j]]]]
- $var as = [[$for j, [[internal::forward<A$j>(a$j)]]]]
- $var Aas = [[$for j, [[A$j a$j]]]]
- $var ms = [[$for j, [[m$j]]]]
- $var matchers = [[$for j, [[const Matcher<A$j>& m$j]]]]
- template <typename R$typename_As>
- class FunctionMocker<R($As)> : public
- internal::FunctionMockerBase<R($As)> {
- public:
- typedef R F($As);
- typedef typename internal::Function<F>::ArgumentTuple ArgumentTuple;
- MockSpec<F> With($matchers) {
- return MockSpec<F>(this, ::testing::make_tuple($ms));
- }
- R Invoke($Aas) {
-
-
-
-
- return this->InvokeWith(ArgumentTuple($as));
- }
- };
- ]]
- template <typename MockType>
- const MockType* AdjustConstness_const(const MockType* mock) {
- return mock;
- }
- template <typename MockType>
- MockType* AdjustConstness_(const MockType* mock) {
- return const_cast<MockType*>(mock);
- }
- }
- using internal::FunctionMocker;
- #define GMOCK_RESULT_(tn, ...) \
- tn ::testing::internal::Function<__VA_ARGS__>::Result
- #define GMOCK_ARG_(tn, N, ...) \
- tn ::testing::internal::Function<__VA_ARGS__>::Argument##N
- #define GMOCK_MATCHER_(tn, N, ...) \
- const ::testing::Matcher<GMOCK_ARG_(tn, N, __VA_ARGS__)>&
- #define GMOCK_MOCKER_(arity, constness, Method) \
- GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__)
- $for i [[
- $range j 1..i
- $var arg_as = [[$for j, [[GMOCK_ARG_(tn, $j, __VA_ARGS__) gmock_a$j]]]]
- $var as = [[$for j, \
- [[::testing::internal::forward<GMOCK_ARG_(tn, $j, __VA_ARGS__)>(gmock_a$j)]]]]
- $var matcher_arg_as = [[$for j, \
- [[GMOCK_MATCHER_(tn, $j, __VA_ARGS__) gmock_a$j]]]]
- $var matcher_as = [[$for j, [[gmock_a$j]]]]
- $var anything_matchers = [[$for j, \
- [[::testing::A<GMOCK_ARG_(tn, $j, __VA_ARGS__)>()]]]]
- #define GMOCK_METHOD$i[[]]_(tn, constness, ct, Method, ...) \
- GMOCK_RESULT_(tn, __VA_ARGS__) ct Method( \
- $arg_as) constness { \
- GTEST_COMPILE_ASSERT_((::testing::tuple_size< \
- tn ::testing::internal::Function<__VA_ARGS__>::ArgumentTuple>::value == $i), \
- this_method_does_not_take_$i[[]]_argument[[$if i != 1 [[s]]]]); \
- GMOCK_MOCKER_($i, constness, Method).SetOwnerAndName(this, #Method); \
- return GMOCK_MOCKER_($i, constness, Method).Invoke($as); \
- } \
- ::testing::MockSpec<__VA_ARGS__> \
- gmock_##Method($matcher_arg_as) constness { \
- GMOCK_MOCKER_($i, constness, Method).RegisterOwner(this); \
- return GMOCK_MOCKER_($i, constness, Method).With($matcher_as); \
- } \
- ::testing::MockSpec<__VA_ARGS__> gmock_##Method( \
- const ::testing::internal::WithoutMatchers&, \
- constness ::testing::internal::Function<__VA_ARGS__>* ) const { \
- return ::testing::internal::AdjustConstness_##constness(this)-> \
- gmock_##Method($anything_matchers); \
- } \
- mutable ::testing::FunctionMocker<__VA_ARGS__> GMOCK_MOCKER_($i, constness, Method)
- ]]
- $for i [[
- #define MOCK_METHOD$i(m, ...) GMOCK_METHOD$i[[]]_(, , , m, __VA_ARGS__)
- ]]
- $for i [[
- #define MOCK_CONST_METHOD$i(m, ...) GMOCK_METHOD$i[[]]_(, const, , m, __VA_ARGS__)
- ]]
- $for i [[
- #define MOCK_METHOD$i[[]]_T(m, ...) GMOCK_METHOD$i[[]]_(typename, , , m, __VA_ARGS__)
- ]]
- $for i [[
- #define MOCK_CONST_METHOD$i[[]]_T(m, ...) \
- GMOCK_METHOD$i[[]]_(typename, const, , m, __VA_ARGS__)
- ]]
- $for i [[
- #define MOCK_METHOD$i[[]]_WITH_CALLTYPE(ct, m, ...) \
- GMOCK_METHOD$i[[]]_(, , ct, m, __VA_ARGS__)
- ]]
- $for i [[
- #define MOCK_CONST_METHOD$i[[]]_WITH_CALLTYPE(ct, m, ...) \
- GMOCK_METHOD$i[[]]_(, const, ct, m, __VA_ARGS__)
- ]]
- $for i [[
- #define MOCK_METHOD$i[[]]_T_WITH_CALLTYPE(ct, m, ...) \
- GMOCK_METHOD$i[[]]_(typename, , ct, m, __VA_ARGS__)
- ]]
- $for i [[
- #define MOCK_CONST_METHOD$i[[]]_T_WITH_CALLTYPE(ct, m, ...) \
- GMOCK_METHOD$i[[]]_(typename, const, ct, m, __VA_ARGS__)
- ]]
- template <typename F>
- class MockFunction;
- $for i [[
- $range j 0..i-1
- $var ArgTypes = [[$for j, [[A$j]]]]
- $var ArgValues = [[$for j, [[::std::move(a$j)]]]]
- $var ArgDecls = [[$for j, [[A$j a$j]]]]
- template <typename R$for j [[, typename A$j]]>
- class MockFunction<R($ArgTypes)> {
- public:
- MockFunction() {}
- MOCK_METHOD$i[[]]_T(Call, R($ArgTypes));
- #if GTEST_HAS_STD_FUNCTION_
- ::std::function<R($ArgTypes)> AsStdFunction() {
- return [this]($ArgDecls) -> R {
- return this->Call($ArgValues);
- };
- }
- #endif
- private:
- GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFunction);
- };
- ]]
- }
- #endif
|