2 $$ This is a Pump source file. Please use Pump to convert it to
3 $$ gmock-generated-actions.h.
5 $var n = 10 $$ The maximum arity we support.
6 $$}} This meta comment fixes auto-indentation in editors.
7 // Copyright 2007, Google Inc.
8 // All rights reserved.
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
14 // * Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 // * Redistributions in binary form must reproduce the above
17 // copyright notice, this list of conditions and the following disclaimer
18 // in the documentation and/or other materials provided with the
20 // * Neither the name of Google Inc. nor the names of its
21 // contributors may be used to endorse or promote products derived from
22 // this software without specific prior written permission.
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 // Author: wan@google.com (Zhanyong Wan)
38 // Google Mock - a framework for writing C++ mock classes.
40 // This file implements some commonly used variadic actions.
42 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
43 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
45 #include "gmock/gmock-actions.h"
46 #include "gmock/internal/gmock-port.h"
51 // InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary
52 // function or method with the unpacked values, where F is a function
53 // type that takes N arguments.
54 template <typename Result, typename ArgumentTuple>
61 $var types = [[$for j [[, typename A$j]]]]
62 $var as = [[$for j, [[A$j]]]]
63 $var args = [[$if i==0 [[]] $else [[ args]]]]
64 $var gets = [[$for j, [[get<$(j - 1)>(args)]]]]
65 template <typename R$types>
66 class InvokeHelper<R, ::testing::tuple<$as> > {
68 template <typename Function>
69 static R Invoke(Function function, const ::testing::tuple<$as>&$args) {
70 return function($gets);
73 template <class Class, typename MethodPtr>
74 static R InvokeMethod(Class* obj_ptr,
76 const ::testing::tuple<$as>&$args) {
77 return (obj_ptr->*method_ptr)($gets);
83 // CallableHelper has static methods for invoking "callables",
84 // i.e. function pointers and functors. It uses overloading to
85 // provide a uniform interface for invoking different kinds of
86 // callables. In particular, you can use:
88 // CallableHelper<R>::Call(callable, a1, a2, ..., an)
90 // to invoke an n-ary callable, where R is its return type. If an
91 // argument, say a2, needs to be passed by reference, you should write
92 // ByRef(a2) instead of a2 in the above expression.
94 class CallableHelper {
96 // Calls a nullary callable.
97 template <typename Function>
98 static R Call(Function function) { return function(); }
100 // Calls a unary callable.
102 // We deliberately pass a1 by value instead of const reference here
103 // in case it is a C-string literal. If we had declared the
104 // parameter as 'const A1& a1' and write Call(function, "Hi"), the
105 // compiler would've thought A1 is 'char[3]', which causes trouble
106 // when you need to copy a value of type A1. By declaring the
107 // parameter as 'A1 a1', the compiler will correctly infer that A1
108 // is 'const char*' when it sees Call(function, "Hi").
110 // Since this function is defined inline, the compiler can get rid
111 // of the copying of the arguments. Therefore the performance won't
113 template <typename Function, typename A1>
114 static R Call(Function function, A1 a1) { return function(a1); }
119 $var arity = [[$if i==2 [[binary]] $elif i==3 [[ternary]] $else [[$i-ary]]]]
121 // Calls a $arity callable.
124 $var typename_As = [[$for j, [[typename A$j]]]]
125 $var Aas = [[$for j, [[A$j a$j]]]]
126 $var as = [[$for j, [[a$j]]]]
127 $var typename_Ts = [[$for j, [[typename T$j]]]]
128 $var Ts = [[$for j, [[T$j]]]]
129 template <typename Function, $typename_As>
130 static R Call(Function function, $Aas) {
131 return function($as);
135 }; // class CallableHelper
137 // An INTERNAL macro for extracting the type of a tuple field. It's
138 // subject to change without notice - DO NOT USE IN USER CODE!
139 #define GMOCK_FIELD_(Tuple, N) \
140 typename ::testing::tuple_element<N, Tuple>::type
144 // SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::type is the
145 // type of an n-ary function whose i-th (1-based) argument type is the
146 // k{i}-th (0-based) field of ArgumentTuple, which must be a tuple
147 // type, and whose return type is Result. For example,
148 // SelectArgs<int, ::testing::tuple<bool, char, double, long>, 0, 3>::type
149 // is int(bool, long).
151 // SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::Select(args)
152 // returns the selected fields (k1, k2, ..., k_n) of args as a tuple.
154 // SelectArgs<int, tuple<bool, char, double>, 2, 0>::Select(
155 // ::testing::make_tuple(true, 'a', 2.5))
156 // returns tuple (2.5, true).
158 // The numbers in list k1, k2, ..., k_n must be >= 0, where n can be
159 // in the range [0, $n]. Duplicates are allowed and they don't have
160 // to be in an ascending or descending order.
162 template <typename Result, typename ArgumentTuple, $for i, [[int k$i]]>
165 typedef Result type($for i, [[GMOCK_FIELD_(ArgumentTuple, k$i)]]);
166 typedef typename Function<type>::ArgumentTuple SelectedArgs;
167 static SelectedArgs Select(const ArgumentTuple& args) {
168 return SelectedArgs($for i, [[get<k$i>(args)]]);
176 template <typename Result, typename ArgumentTuple$for j1[[, int k$j1]]>
177 class SelectArgs<Result, ArgumentTuple,
178 $for j, [[$if j <= i-1 [[k$j]] $else [[-1]]]]> {
180 typedef Result type($for j1, [[GMOCK_FIELD_(ArgumentTuple, k$j1)]]);
181 typedef typename Function<type>::ArgumentTuple SelectedArgs;
182 static SelectedArgs Select(const ArgumentTuple& [[]]
183 $if i == 1 [[/* args */]] $else [[args]]) {
184 return SelectedArgs($for j1, [[get<k$j1>(args)]]);
192 $var ks = [[$for i, [[k$i]]]]
194 // Implements the WithArgs action.
195 template <typename InnerAction, $for i, [[int k$i = -1]]>
196 class WithArgsAction {
198 explicit WithArgsAction(const InnerAction& action) : action_(action) {}
200 template <typename F>
201 operator Action<F>() const { return MakeAction(new Impl<F>(action_)); }
204 template <typename F>
205 class Impl : public ActionInterface<F> {
207 typedef typename Function<F>::Result Result;
208 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
210 explicit Impl(const InnerAction& action) : action_(action) {}
212 virtual Result Perform(const ArgumentTuple& args) {
213 return action_.Perform(SelectArgs<Result, ArgumentTuple, $ks>::Select(args));
217 typedef typename SelectArgs<Result, ArgumentTuple,
218 $ks>::type InnerFunctionType;
220 Action<InnerFunctionType> action_;
223 const InnerAction action_;
225 GTEST_DISALLOW_ASSIGN_(WithArgsAction);
228 // A macro from the ACTION* family (defined later in this file)
229 // defines an action that can be used in a mock function. Typically,
230 // these actions only care about a subset of the arguments of the mock
231 // function. For example, if such an action only uses the second
232 // argument, it can be used in any mock function that takes >= 2
233 // arguments where the type of the second argument is compatible.
235 // Therefore, the action implementation must be prepared to take more
236 // arguments than it needs. The ExcessiveArg type is used to
237 // represent those excessive arguments. In order to keep the compiler
238 // error messages tractable, we define it in the testing namespace
239 // instead of testing::internal. However, this is an INTERNAL TYPE
240 // and subject to change without notice, so a user MUST NOT USE THIS
242 struct ExcessiveArg {};
244 // A helper class needed for implementing the ACTION* macros.
245 template <typename Result, class Impl>
252 $var template = [[$if i==0 [[]] $else [[
254 template <$for j, [[typename A$j]]>
257 $var As = [[$for j, [[A$j]]]]
258 $var as = [[$for j, [[get<$j>(args)]]]]
260 $var eas = [[$for k, [[ExcessiveArg()]]]]
261 $var arg_list = [[$if (i==0) | (i==n) [[$as$eas]] $else [[$as, $eas]]]]
263 static Result Perform(Impl* impl, const ::testing::tuple<$As>& args) {
264 return impl->template gmock_PerformImpl<$As>(args, $arg_list);
270 } // namespace internal
272 // Various overloads for Invoke().
274 // WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
275 // the selected arguments of the mock function to an_action and
276 // performs it. It serves as an adaptor between actions with
277 // different argument lists. C++ doesn't support default arguments for
278 // function templates, so we have to overload it.
283 template <$for j [[int k$j, ]]typename InnerAction>
284 inline internal::WithArgsAction<InnerAction$for j [[, k$j]]>
285 WithArgs(const InnerAction& action) {
286 return internal::WithArgsAction<InnerAction$for j [[, k$j]]>(action);
291 // Creates an action that does actions a1, a2, ..., sequentially in
296 $var types = [[$for j, [[typename Action$j]]]]
297 $var Aas = [[$for j [[, Action$j a$j]]]]
299 template <typename Action1, $types>
302 inline $for k [[internal::DoBothAction<Action$k, ]]Action$i$for k [[>]]
304 DoAll(Action1 a1$Aas) {
307 return internal::DoBothAction<Action1, Action2>(a1, a2);
311 return DoAll(a1, DoAll($for j2, [[a$j2]]));
318 } // namespace testing
320 // The ACTION* family of macros can be used in a namespace scope to
321 // define custom actions easily. The syntax:
323 // ACTION(name) { statements; }
325 // will define an action with the given name that executes the
326 // statements. The value returned by the statements will be used as
327 // the return value of the action. Inside the statements, you can
328 // refer to the K-th (0-based) argument of the mock function by
329 // 'argK', and refer to its type by 'argK_type'. For example:
331 // ACTION(IncrementArg1) {
332 // arg1_type temp = arg1;
336 // allows you to write
338 // ...WillOnce(IncrementArg1());
340 // You can also refer to the entire argument tuple and its type by
341 // 'args' and 'args_type', and refer to the mock function type and its
342 // return type by 'function_type' and 'return_type'.
344 // Note that you don't need to specify the types of the mock function
345 // arguments. However rest assured that your code is still type-safe:
346 // you'll get a compiler error if *arg1 doesn't support the ++
347 // operator, or if the type of ++(*arg1) isn't compatible with the
348 // mock function's return type, for example.
350 // Sometimes you'll want to parameterize the action. For that you can use
353 // ACTION_P(name, param_name) { statements; }
357 // ACTION_P(Add, n) { return arg0 + n; }
359 // will allow you to write:
361 // ...WillOnce(Add(5));
363 // Note that you don't need to provide the type of the parameter
364 // either. If you need to reference the type of a parameter named
365 // 'foo', you can write 'foo_type'. For example, in the body of
366 // ACTION_P(Add, n) above, you can write 'n_type' to refer to the type
369 // We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P$n to support
370 // multi-parameter actions.
372 // For the purpose of typing, you can view
374 // ACTION_Pk(Foo, p1, ..., pk) { ... }
378 // template <typename p1_type, ..., typename pk_type>
379 // FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... }
381 // In particular, you can provide the template type arguments
382 // explicitly when invoking Foo(), as in Foo<long, bool>(5, false);
383 // although usually you can rely on the compiler to infer the types
384 // for you automatically. You can assign the result of expression
385 // Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ...,
386 // pk_type>. This can be useful when composing actions.
388 // You can also overload actions with different numbers of parameters:
390 // ACTION_P(Plus, a) { ... }
391 // ACTION_P2(Plus, a, b) { ... }
393 // While it's tempting to always use the ACTION* macros when defining
394 // a new action, you should also consider implementing ActionInterface
395 // or using MakePolymorphicAction() instead, especially if you need to
396 // use the action a lot. While these approaches require more work,
397 // they give you more control on the types of the mock function
398 // arguments and the action parameters, which in general leads to
399 // better compiler error messages that pay off in the long run. They
400 // also allow overloading actions based on parameter types (as opposed
401 // to just based on the number of parameters).
405 // ACTION*() can only be used in a namespace scope. The reason is
406 // that C++ doesn't yet allow function-local types to be used to
407 // instantiate templates. The up-coming C++0x standard will fix this.
408 // Once that's done, we'll consider supporting using ACTION*() inside
413 // To learn more about using these macros, please search for 'ACTION'
414 // on http://code.google.com/p/googlemock/wiki/CookBook.
419 // An internal macro needed for implementing ACTION*().
420 #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\
421 const args_type& args GTEST_ATTRIBUTE_UNUSED_
423 arg$k[[]]_type arg$k GTEST_ATTRIBUTE_UNUSED_]]
426 // Sometimes you want to give an action explicit template parameters
427 // that cannot be inferred from its value parameters. ACTION() and
428 // ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that
429 // and can be viewed as an extension to ACTION() and ACTION_P*().
433 // ACTION_TEMPLATE(ActionName,
434 // HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m),
435 // AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; }
437 // defines an action template that takes m explicit template
438 // parameters and n value parameters. name_i is the name of the i-th
439 // template parameter, and kind_i specifies whether it's a typename,
440 // an integral constant, or a template. p_i is the name of the i-th
445 // // DuplicateArg<k, T>(output) converts the k-th argument of the mock
446 // // function to type T and copies it to *output.
447 // ACTION_TEMPLATE(DuplicateArg,
448 // HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
449 // AND_1_VALUE_PARAMS(output)) {
450 // *output = T(::testing::get<k>(args));
454 // EXPECT_CALL(mock, Foo(_, _))
455 // .WillOnce(DuplicateArg<1, unsigned char>(&n));
457 // To create an instance of an action template, write:
459 // ActionName<t1, ..., t_m>(v1, ..., v_n)
461 // where the ts are the template arguments and the vs are the value
462 // arguments. The value argument types are inferred by the compiler.
463 // If you want to explicitly specify the value argument types, you can
464 // provide additional template arguments:
466 // ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n)
468 // where u_i is the desired type of v_i.
470 // ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the
471 // number of value parameters, but not on the number of template
472 // parameters. Without the restriction, the meaning of the following
475 // OverloadedAction<int, bool>(x);
477 // Are we using a single-template-parameter action where 'bool' refers
478 // to the type of x, or are we using a two-template-parameter action
479 // where the compiler is asked to infer the type of x?
481 // Implementation notes:
483 // GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and
484 // GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for
485 // implementing ACTION_TEMPLATE. The main trick we use is to create
486 // new macro invocations when expanding a macro. For example, we have
488 // #define ACTION_TEMPLATE(name, template_params, value_params)
489 // ... GMOCK_INTERNAL_DECL_##template_params ...
491 // which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...)
494 // ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ...
496 // Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the
497 // preprocessor will continue to expand it to
499 // ... typename T ...
501 // This technique conforms to the C++ standard and is portable. It
502 // allows us to implement action templates using O(N) code, where N is
503 // the maximum number of template/value parameters supported. Without
504 // using it, we'd have to devote O(N^2) amount of code to implement all
505 // combinations of m and n.
507 // Declares the template parameters.
512 #define GMOCK_INTERNAL_DECL_HAS_$j[[]]
513 _TEMPLATE_PARAMS($for m, [[kind$m, name$m]]) $for m, [[kind$m name$m]]
518 // Lists the template parameters.
522 #define GMOCK_INTERNAL_LIST_HAS_$j[[]]
523 _TEMPLATE_PARAMS($for m, [[kind$m, name$m]]) $for m, [[name$m]]
528 // Declares the types of value parameters.
532 #define GMOCK_INTERNAL_DECL_TYPE_AND_$i[[]]
533 _VALUE_PARAMS($for j, [[p$j]]) $for j [[, typename p$j##_type]]
538 // Initializes the value parameters.
542 #define GMOCK_INTERNAL_INIT_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])\
543 ($for j, [[p$j##_type gmock_p$j]])$if i>0 [[ : ]]$for j, [[p$j(gmock_p$j)]]
548 // Declares the fields for storing the value parameters.
552 #define GMOCK_INTERNAL_DEFN_AND_$i[[]]
553 _VALUE_PARAMS($for j, [[p$j]]) $for j [[p$j##_type p$j; ]]
558 // Lists the value parameters.
562 #define GMOCK_INTERNAL_LIST_AND_$i[[]]
563 _VALUE_PARAMS($for j, [[p$j]]) $for j, [[p$j]]
568 // Lists the value parameter types.
572 #define GMOCK_INTERNAL_LIST_TYPE_AND_$i[[]]
573 _VALUE_PARAMS($for j, [[p$j]]) $for j [[, p$j##_type]]
578 // Declares the value parameters.
582 #define GMOCK_INTERNAL_DECL_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]]) [[]]
583 $for j, [[p$j##_type p$j]]
588 // The suffix of the class template implementing the action template.
593 #define GMOCK_INTERNAL_COUNT_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]]) [[]]
594 $if i==1 [[P]] $elif i>=2 [[P$i]]
598 // The name of the class template implementing the action template.
599 #define GMOCK_ACTION_CLASS_(name, value_params)\
600 GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params)
604 #define ACTION_TEMPLATE(name, template_params, value_params)\
605 template <GMOCK_INTERNAL_DECL_##template_params\
606 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
607 class GMOCK_ACTION_CLASS_(name, value_params) {\
609 explicit GMOCK_ACTION_CLASS_(name, value_params)\
610 GMOCK_INTERNAL_INIT_##value_params {}\
611 template <typename F>\
612 class gmock_Impl : public ::testing::ActionInterface<F> {\
614 typedef F function_type;\
615 typedef typename ::testing::internal::Function<F>::Result return_type;\
616 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
618 explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\
619 virtual return_type Perform(const args_type& args) {\
620 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
621 Perform(this, args);\
623 template <$for k, [[typename arg$k[[]]_type]]>\
624 return_type gmock_PerformImpl(const args_type& args[[]]
625 $for k [[, arg$k[[]]_type arg$k]]) const;\
626 GMOCK_INTERNAL_DEFN_##value_params\
628 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
630 template <typename F> operator ::testing::Action<F>() const {\
631 return ::testing::Action<F>(\
632 new gmock_Impl<F>(GMOCK_INTERNAL_LIST_##value_params));\
634 GMOCK_INTERNAL_DEFN_##value_params\
636 GTEST_DISALLOW_ASSIGN_(GMOCK_ACTION_CLASS_(name, value_params));\
638 template <GMOCK_INTERNAL_DECL_##template_params\
639 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
640 inline GMOCK_ACTION_CLASS_(name, value_params)<\
641 GMOCK_INTERNAL_LIST_##template_params\
642 GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\
643 GMOCK_INTERNAL_DECL_##value_params) {\
644 return GMOCK_ACTION_CLASS_(name, value_params)<\
645 GMOCK_INTERNAL_LIST_##template_params\
646 GMOCK_INTERNAL_LIST_TYPE_##value_params>(\
647 GMOCK_INTERNAL_LIST_##value_params);\
649 template <GMOCK_INTERNAL_DECL_##template_params\
650 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
651 template <typename F>\
652 template <typename arg0_type, typename arg1_type, typename arg2_type, \
653 typename arg3_type, typename arg4_type, typename arg5_type, \
654 typename arg6_type, typename arg7_type, typename arg8_type, \
656 typename ::testing::internal::Function<F>::Result\
657 GMOCK_ACTION_CLASS_(name, value_params)<\
658 GMOCK_INTERNAL_LIST_##template_params\
659 GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl<F>::\
661 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
666 $var template = [[$if i==0 [[]] $else [[
669 template <$for j, [[typename p$j##_type]]>\
671 $var class_name = [[name##Action[[$if i==0 [[]] $elif i==1 [[P]]
674 $var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
675 $var param_types_and_names = [[$for j, [[p$j##_type p$j]]]]
676 $var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]]
677 $var param_field_decls = [[$for j
682 $var param_field_decls2 = [[$for j
687 $var params = [[$for j, [[p$j]]]]
688 $var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]]
689 $var typename_arg_types = [[$for k, [[typename arg$k[[]]_type]]]]
690 $var arg_types_and_names = [[$for k, [[arg$k[[]]_type arg$k]]]]
691 $var macro_name = [[$if i==0 [[ACTION]] $elif i==1 [[ACTION_P]]
692 $else [[ACTION_P$i]]]]
694 #define $macro_name(name$for j [[, p$j]])\$template
697 [[$if i==1 [[explicit ]]]]$class_name($ctor_param_list)$inits {}\
698 template <typename F>\
699 class gmock_Impl : public ::testing::ActionInterface<F> {\
701 typedef F function_type;\
702 typedef typename ::testing::internal::Function<F>::Result return_type;\
703 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
705 [[$if i==1 [[explicit ]]]]gmock_Impl($ctor_param_list)$inits {}\
706 virtual return_type Perform(const args_type& args) {\
707 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
708 Perform(this, args);\
710 template <$typename_arg_types>\
711 return_type gmock_PerformImpl(const args_type& args, [[]]
712 $arg_types_and_names) const;\$param_field_decls
714 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
716 template <typename F> operator ::testing::Action<F>() const {\
717 return ::testing::Action<F>(new gmock_Impl<F>($params));\
718 }\$param_field_decls2
720 GTEST_DISALLOW_ASSIGN_($class_name);\
722 inline $class_name$param_types name($param_types_and_names) {\
723 return $class_name$param_types($params);\
725 template <typename F>\
726 template <$typename_arg_types>\
727 typename ::testing::internal::Function<F>::Result\
728 $class_name$param_types::gmock_Impl<F>::gmock_PerformImpl(\
729 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
731 $$ } // This meta comment fixes auto-indentation in Emacs. It won't
732 $$ // show up in the generated code.
737 // The ACTION*() macros trigger warning C4100 (unreferenced formal
738 // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
739 // the macro definition, as the warnings are generated when the macro
740 // is expanded and macro expansion cannot contain #pragma. Therefore
741 // we suppress them here.
743 # pragma warning(push)
744 # pragma warning(disable:4100)
747 // Various overloads for InvokeArgument<N>().
749 // The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
750 // (0-based) argument, which must be a k-ary callable, of the mock
751 // function, with arguments a1, a2, ..., a_k.
755 // 1. The arguments are passed by value by default. If you need to
756 // pass an argument by reference, wrap it inside ByRef(). For
759 // InvokeArgument<1>(5, string("Hello"), ByRef(foo))
761 // passes 5 and string("Hello") by value, and passes foo by
764 // 2. If the callable takes an argument by reference but ByRef() is
765 // not used, it will receive the reference to a copy of the value,
766 // instead of the original value. For example, when the 0-th
767 // argument of the mock function takes a const string&, the action
769 // InvokeArgument<0>(string("Hello"))
771 // makes a copy of the temporary string("Hello") object and passes a
772 // reference of the copy, instead of the original temporary object,
773 // to the callable. This makes it easy for a user to define an
774 // InvokeArgument action from temporary values and have it performed
781 ACTION_TEMPLATE(InvokeArgument,
782 HAS_1_TEMPLATE_PARAMS(int, k),
783 AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])) {
784 return internal::CallableHelper<return_type>::Call(
785 ::testing::get<k>(args)$for j [[, p$j]]);
790 // Various overloads for ReturnNew<T>().
792 // The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new
793 // instance of type T, constructed on the heap with constructor arguments
794 // a1, a2, ..., and a_k. The caller assumes ownership of the returned value.
798 $var ps = [[$for j, [[p$j]]]]
800 ACTION_TEMPLATE(ReturnNew,
801 HAS_1_TEMPLATE_PARAMS(typename, T),
802 AND_$i[[]]_VALUE_PARAMS($ps)) {
809 # pragma warning(pop)
812 } // namespace testing
814 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_