Warning, /JETSCAPE/external_packages/googletest/googlemock/include/gmock/gmock-generated-actions.h.pump is written in an unsupported language. File is not indexed.
0001 $$ -*- mode: c++; -*-
0002 $$ This is a Pump source file. Please use Pump to convert it to
0003 $$ gmock-generated-actions.h.
0004 $$
0005 $var n = 10 $$ The maximum arity we support.
0006 $$}} This meta comment fixes auto-indentation in editors.
0007 // Copyright 2007, Google Inc.
0008 // All rights reserved.
0009 //
0010 // Redistribution and use in source and binary forms, with or without
0011 // modification, are permitted provided that the following conditions are
0012 // met:
0013 //
0014 // * Redistributions of source code must retain the above copyright
0015 // notice, this list of conditions and the following disclaimer.
0016 // * Redistributions in binary form must reproduce the above
0017 // copyright notice, this list of conditions and the following disclaimer
0018 // in the documentation and/or other materials provided with the
0019 // distribution.
0020 // * Neither the name of Google Inc. nor the names of its
0021 // contributors may be used to endorse or promote products derived from
0022 // this software without specific prior written permission.
0023 //
0024 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0025 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0026 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0027 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0028 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0029 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0030 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0031 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0032 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0033 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0034 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0035 //
0036 // Author: wan@google.com (Zhanyong Wan)
0037
0038 // Google Mock - a framework for writing C++ mock classes.
0039 //
0040 // This file implements some commonly used variadic actions.
0041
0042 #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
0043 #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
0044
0045 #include "gmock/gmock-actions.h"
0046 #include "gmock/internal/gmock-port.h"
0047
0048 namespace testing {
0049 namespace internal {
0050
0051 // InvokeHelper<F> knows how to unpack an N-tuple and invoke an N-ary
0052 // function or method with the unpacked values, where F is a function
0053 // type that takes N arguments.
0054 template <typename Result, typename ArgumentTuple>
0055 class InvokeHelper;
0056
0057
0058 $range i 0..n
0059 $for i [[
0060 $range j 1..i
0061 $var types = [[$for j [[, typename A$j]]]]
0062 $var as = [[$for j, [[A$j]]]]
0063 $var args = [[$if i==0 [[]] $else [[ args]]]]
0064 $var gets = [[$for j, [[get<$(j - 1)>(args)]]]]
0065 template <typename R$types>
0066 class InvokeHelper<R, ::testing::tuple<$as> > {
0067 public:
0068 template <typename Function>
0069 static R Invoke(Function function, const ::testing::tuple<$as>&$args) {
0070 return function($gets);
0071 }
0072
0073 template <class Class, typename MethodPtr>
0074 static R InvokeMethod(Class* obj_ptr,
0075 MethodPtr method_ptr,
0076 const ::testing::tuple<$as>&$args) {
0077 return (obj_ptr->*method_ptr)($gets);
0078 }
0079 };
0080
0081
0082 ]]
0083 // An INTERNAL macro for extracting the type of a tuple field. It's
0084 // subject to change without notice - DO NOT USE IN USER CODE!
0085 #define GMOCK_FIELD_(Tuple, N) \
0086 typename ::testing::tuple_element<N, Tuple>::type
0087
0088 $range i 1..n
0089
0090 // SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::type is the
0091 // type of an n-ary function whose i-th (1-based) argument type is the
0092 // k{i}-th (0-based) field of ArgumentTuple, which must be a tuple
0093 // type, and whose return type is Result. For example,
0094 // SelectArgs<int, ::testing::tuple<bool, char, double, long>, 0, 3>::type
0095 // is int(bool, long).
0096 //
0097 // SelectArgs<Result, ArgumentTuple, k1, k2, ..., k_n>::Select(args)
0098 // returns the selected fields (k1, k2, ..., k_n) of args as a tuple.
0099 // For example,
0100 // SelectArgs<int, tuple<bool, char, double>, 2, 0>::Select(
0101 // ::testing::make_tuple(true, 'a', 2.5))
0102 // returns tuple (2.5, true).
0103 //
0104 // The numbers in list k1, k2, ..., k_n must be >= 0, where n can be
0105 // in the range [0, $n]. Duplicates are allowed and they don't have
0106 // to be in an ascending or descending order.
0107
0108 template <typename Result, typename ArgumentTuple, $for i, [[int k$i]]>
0109 class SelectArgs {
0110 public:
0111 typedef Result type($for i, [[GMOCK_FIELD_(ArgumentTuple, k$i)]]);
0112 typedef typename Function<type>::ArgumentTuple SelectedArgs;
0113 static SelectedArgs Select(const ArgumentTuple& args) {
0114 return SelectedArgs($for i, [[get<k$i>(args)]]);
0115 }
0116 };
0117
0118
0119 $for i [[
0120 $range j 1..n
0121 $range j1 1..i-1
0122 template <typename Result, typename ArgumentTuple$for j1[[, int k$j1]]>
0123 class SelectArgs<Result, ArgumentTuple,
0124 $for j, [[$if j <= i-1 [[k$j]] $else [[-1]]]]> {
0125 public:
0126 typedef Result type($for j1, [[GMOCK_FIELD_(ArgumentTuple, k$j1)]]);
0127 typedef typename Function<type>::ArgumentTuple SelectedArgs;
0128 static SelectedArgs Select(const ArgumentTuple& [[]]
0129 $if i == 1 [[/* args */]] $else [[args]]) {
0130 return SelectedArgs($for j1, [[get<k$j1>(args)]]);
0131 }
0132 };
0133
0134
0135 ]]
0136 #undef GMOCK_FIELD_
0137
0138 $var ks = [[$for i, [[k$i]]]]
0139
0140 // Implements the WithArgs action.
0141 template <typename InnerAction, $for i, [[int k$i = -1]]>
0142 class WithArgsAction {
0143 public:
0144 explicit WithArgsAction(const InnerAction& action) : action_(action) {}
0145
0146 template <typename F>
0147 operator Action<F>() const { return MakeAction(new Impl<F>(action_)); }
0148
0149 private:
0150 template <typename F>
0151 class Impl : public ActionInterface<F> {
0152 public:
0153 typedef typename Function<F>::Result Result;
0154 typedef typename Function<F>::ArgumentTuple ArgumentTuple;
0155
0156 explicit Impl(const InnerAction& action) : action_(action) {}
0157
0158 virtual Result Perform(const ArgumentTuple& args) {
0159 return action_.Perform(SelectArgs<Result, ArgumentTuple, $ks>::Select(args));
0160 }
0161
0162 private:
0163 typedef typename SelectArgs<Result, ArgumentTuple,
0164 $ks>::type InnerFunctionType;
0165
0166 Action<InnerFunctionType> action_;
0167 };
0168
0169 const InnerAction action_;
0170
0171 GTEST_DISALLOW_ASSIGN_(WithArgsAction);
0172 };
0173
0174 // A macro from the ACTION* family (defined later in this file)
0175 // defines an action that can be used in a mock function. Typically,
0176 // these actions only care about a subset of the arguments of the mock
0177 // function. For example, if such an action only uses the second
0178 // argument, it can be used in any mock function that takes >= 2
0179 // arguments where the type of the second argument is compatible.
0180 //
0181 // Therefore, the action implementation must be prepared to take more
0182 // arguments than it needs. The ExcessiveArg type is used to
0183 // represent those excessive arguments. In order to keep the compiler
0184 // error messages tractable, we define it in the testing namespace
0185 // instead of testing::internal. However, this is an INTERNAL TYPE
0186 // and subject to change without notice, so a user MUST NOT USE THIS
0187 // TYPE DIRECTLY.
0188 struct ExcessiveArg {};
0189
0190 // A helper class needed for implementing the ACTION* macros.
0191 template <typename Result, class Impl>
0192 class ActionHelper {
0193 public:
0194 $range i 0..n
0195 $for i
0196
0197 [[
0198 $var template = [[$if i==0 [[]] $else [[
0199 $range j 0..i-1
0200 template <$for j, [[typename A$j]]>
0201 ]]]]
0202 $range j 0..i-1
0203 $var As = [[$for j, [[A$j]]]]
0204 $var as = [[$for j, [[get<$j>(args)]]]]
0205 $range k 1..n-i
0206 $var eas = [[$for k, [[ExcessiveArg()]]]]
0207 $var arg_list = [[$if (i==0) | (i==n) [[$as$eas]] $else [[$as, $eas]]]]
0208 $template
0209 static Result Perform(Impl* impl, const ::testing::tuple<$As>& args) {
0210 return impl->template gmock_PerformImpl<$As>(args, $arg_list);
0211 }
0212
0213 ]]
0214 };
0215
0216 } // namespace internal
0217
0218 // Various overloads for Invoke().
0219
0220 // WithArgs<N1, N2, ..., Nk>(an_action) creates an action that passes
0221 // the selected arguments of the mock function to an_action and
0222 // performs it. It serves as an adaptor between actions with
0223 // different argument lists. C++ doesn't support default arguments for
0224 // function templates, so we have to overload it.
0225
0226 $range i 1..n
0227 $for i [[
0228 $range j 1..i
0229 template <$for j [[int k$j, ]]typename InnerAction>
0230 inline internal::WithArgsAction<InnerAction$for j [[, k$j]]>
0231 WithArgs(const InnerAction& action) {
0232 return internal::WithArgsAction<InnerAction$for j [[, k$j]]>(action);
0233 }
0234
0235
0236 ]]
0237 // Creates an action that does actions a1, a2, ..., sequentially in
0238 // each invocation.
0239 $range i 2..n
0240 $for i [[
0241 $range j 2..i
0242 $var types = [[$for j, [[typename Action$j]]]]
0243 $var Aas = [[$for j [[, Action$j a$j]]]]
0244
0245 template <typename Action1, $types>
0246 $range k 1..i-1
0247
0248 inline $for k [[internal::DoBothAction<Action$k, ]]Action$i$for k [[>]]
0249
0250 DoAll(Action1 a1$Aas) {
0251 $if i==2 [[
0252
0253 return internal::DoBothAction<Action1, Action2>(a1, a2);
0254 ]] $else [[
0255 $range j2 2..i
0256
0257 return DoAll(a1, DoAll($for j2, [[a$j2]]));
0258 ]]
0259
0260 }
0261
0262 ]]
0263
0264 } // namespace testing
0265
0266 // The ACTION* family of macros can be used in a namespace scope to
0267 // define custom actions easily. The syntax:
0268 //
0269 // ACTION(name) { statements; }
0270 //
0271 // will define an action with the given name that executes the
0272 // statements. The value returned by the statements will be used as
0273 // the return value of the action. Inside the statements, you can
0274 // refer to the K-th (0-based) argument of the mock function by
0275 // 'argK', and refer to its type by 'argK_type'. For example:
0276 //
0277 // ACTION(IncrementArg1) {
0278 // arg1_type temp = arg1;
0279 // return ++(*temp);
0280 // }
0281 //
0282 // allows you to write
0283 //
0284 // ...WillOnce(IncrementArg1());
0285 //
0286 // You can also refer to the entire argument tuple and its type by
0287 // 'args' and 'args_type', and refer to the mock function type and its
0288 // return type by 'function_type' and 'return_type'.
0289 //
0290 // Note that you don't need to specify the types of the mock function
0291 // arguments. However rest assured that your code is still type-safe:
0292 // you'll get a compiler error if *arg1 doesn't support the ++
0293 // operator, or if the type of ++(*arg1) isn't compatible with the
0294 // mock function's return type, for example.
0295 //
0296 // Sometimes you'll want to parameterize the action. For that you can use
0297 // another macro:
0298 //
0299 // ACTION_P(name, param_name) { statements; }
0300 //
0301 // For example:
0302 //
0303 // ACTION_P(Add, n) { return arg0 + n; }
0304 //
0305 // will allow you to write:
0306 //
0307 // ...WillOnce(Add(5));
0308 //
0309 // Note that you don't need to provide the type of the parameter
0310 // either. If you need to reference the type of a parameter named
0311 // 'foo', you can write 'foo_type'. For example, in the body of
0312 // ACTION_P(Add, n) above, you can write 'n_type' to refer to the type
0313 // of 'n'.
0314 //
0315 // We also provide ACTION_P2, ACTION_P3, ..., up to ACTION_P$n to support
0316 // multi-parameter actions.
0317 //
0318 // For the purpose of typing, you can view
0319 //
0320 // ACTION_Pk(Foo, p1, ..., pk) { ... }
0321 //
0322 // as shorthand for
0323 //
0324 // template <typename p1_type, ..., typename pk_type>
0325 // FooActionPk<p1_type, ..., pk_type> Foo(p1_type p1, ..., pk_type pk) { ... }
0326 //
0327 // In particular, you can provide the template type arguments
0328 // explicitly when invoking Foo(), as in Foo<long, bool>(5, false);
0329 // although usually you can rely on the compiler to infer the types
0330 // for you automatically. You can assign the result of expression
0331 // Foo(p1, ..., pk) to a variable of type FooActionPk<p1_type, ...,
0332 // pk_type>. This can be useful when composing actions.
0333 //
0334 // You can also overload actions with different numbers of parameters:
0335 //
0336 // ACTION_P(Plus, a) { ... }
0337 // ACTION_P2(Plus, a, b) { ... }
0338 //
0339 // While it's tempting to always use the ACTION* macros when defining
0340 // a new action, you should also consider implementing ActionInterface
0341 // or using MakePolymorphicAction() instead, especially if you need to
0342 // use the action a lot. While these approaches require more work,
0343 // they give you more control on the types of the mock function
0344 // arguments and the action parameters, which in general leads to
0345 // better compiler error messages that pay off in the long run. They
0346 // also allow overloading actions based on parameter types (as opposed
0347 // to just based on the number of parameters).
0348 //
0349 // CAVEAT:
0350 //
0351 // ACTION*() can only be used in a namespace scope. The reason is
0352 // that C++ doesn't yet allow function-local types to be used to
0353 // instantiate templates. The up-coming C++0x standard will fix this.
0354 // Once that's done, we'll consider supporting using ACTION*() inside
0355 // a function.
0356 //
0357 // MORE INFORMATION:
0358 //
0359 // To learn more about using these macros, please search for 'ACTION'
0360 // on http://code.google.com/p/googlemock/wiki/CookBook.
0361
0362 $range i 0..n
0363 $range k 0..n-1
0364
0365 // An internal macro needed for implementing ACTION*().
0366 #define GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_\
0367 const args_type& args GTEST_ATTRIBUTE_UNUSED_
0368 $for k [[, \
0369 arg$k[[]]_type arg$k GTEST_ATTRIBUTE_UNUSED_]]
0370
0371
0372 // Sometimes you want to give an action explicit template parameters
0373 // that cannot be inferred from its value parameters. ACTION() and
0374 // ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that
0375 // and can be viewed as an extension to ACTION() and ACTION_P*().
0376 //
0377 // The syntax:
0378 //
0379 // ACTION_TEMPLATE(ActionName,
0380 // HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m),
0381 // AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; }
0382 //
0383 // defines an action template that takes m explicit template
0384 // parameters and n value parameters. name_i is the name of the i-th
0385 // template parameter, and kind_i specifies whether it's a typename,
0386 // an integral constant, or a template. p_i is the name of the i-th
0387 // value parameter.
0388 //
0389 // Example:
0390 //
0391 // // DuplicateArg<k, T>(output) converts the k-th argument of the mock
0392 // // function to type T and copies it to *output.
0393 // ACTION_TEMPLATE(DuplicateArg,
0394 // HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
0395 // AND_1_VALUE_PARAMS(output)) {
0396 // *output = T(::testing::get<k>(args));
0397 // }
0398 // ...
0399 // int n;
0400 // EXPECT_CALL(mock, Foo(_, _))
0401 // .WillOnce(DuplicateArg<1, unsigned char>(&n));
0402 //
0403 // To create an instance of an action template, write:
0404 //
0405 // ActionName<t1, ..., t_m>(v1, ..., v_n)
0406 //
0407 // where the ts are the template arguments and the vs are the value
0408 // arguments. The value argument types are inferred by the compiler.
0409 // If you want to explicitly specify the value argument types, you can
0410 // provide additional template arguments:
0411 //
0412 // ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n)
0413 //
0414 // where u_i is the desired type of v_i.
0415 //
0416 // ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the
0417 // number of value parameters, but not on the number of template
0418 // parameters. Without the restriction, the meaning of the following
0419 // is unclear:
0420 //
0421 // OverloadedAction<int, bool>(x);
0422 //
0423 // Are we using a single-template-parameter action where 'bool' refers
0424 // to the type of x, or are we using a two-template-parameter action
0425 // where the compiler is asked to infer the type of x?
0426 //
0427 // Implementation notes:
0428 //
0429 // GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and
0430 // GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for
0431 // implementing ACTION_TEMPLATE. The main trick we use is to create
0432 // new macro invocations when expanding a macro. For example, we have
0433 //
0434 // #define ACTION_TEMPLATE(name, template_params, value_params)
0435 // ... GMOCK_INTERNAL_DECL_##template_params ...
0436 //
0437 // which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...)
0438 // to expand to
0439 //
0440 // ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ...
0441 //
0442 // Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the
0443 // preprocessor will continue to expand it to
0444 //
0445 // ... typename T ...
0446 //
0447 // This technique conforms to the C++ standard and is portable. It
0448 // allows us to implement action templates using O(N) code, where N is
0449 // the maximum number of template/value parameters supported. Without
0450 // using it, we'd have to devote O(N^2) amount of code to implement all
0451 // combinations of m and n.
0452
0453 // Declares the template parameters.
0454
0455 $range j 1..n
0456 $for j [[
0457 $range m 0..j-1
0458 #define GMOCK_INTERNAL_DECL_HAS_$j[[]]
0459 _TEMPLATE_PARAMS($for m, [[kind$m, name$m]]) $for m, [[kind$m name$m]]
0460
0461
0462 ]]
0463
0464 // Lists the template parameters.
0465
0466 $for j [[
0467 $range m 0..j-1
0468 #define GMOCK_INTERNAL_LIST_HAS_$j[[]]
0469 _TEMPLATE_PARAMS($for m, [[kind$m, name$m]]) $for m, [[name$m]]
0470
0471
0472 ]]
0473
0474 // Declares the types of value parameters.
0475
0476 $for i [[
0477 $range j 0..i-1
0478 #define GMOCK_INTERNAL_DECL_TYPE_AND_$i[[]]
0479 _VALUE_PARAMS($for j, [[p$j]]) $for j [[, typename p$j##_type]]
0480
0481
0482 ]]
0483
0484 // Initializes the value parameters.
0485
0486 $for i [[
0487 $range j 0..i-1
0488 #define GMOCK_INTERNAL_INIT_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])\
0489 ($for j, [[p$j##_type gmock_p$j]])$if i>0 [[ : ]]$for j, [[p$j(gmock_p$j)]]
0490
0491
0492 ]]
0493
0494 // Declares the fields for storing the value parameters.
0495
0496 $for i [[
0497 $range j 0..i-1
0498 #define GMOCK_INTERNAL_DEFN_AND_$i[[]]
0499 _VALUE_PARAMS($for j, [[p$j]]) $for j [[p$j##_type p$j; ]]
0500
0501
0502 ]]
0503
0504 // Lists the value parameters.
0505
0506 $for i [[
0507 $range j 0..i-1
0508 #define GMOCK_INTERNAL_LIST_AND_$i[[]]
0509 _VALUE_PARAMS($for j, [[p$j]]) $for j, [[p$j]]
0510
0511
0512 ]]
0513
0514 // Lists the value parameter types.
0515
0516 $for i [[
0517 $range j 0..i-1
0518 #define GMOCK_INTERNAL_LIST_TYPE_AND_$i[[]]
0519 _VALUE_PARAMS($for j, [[p$j]]) $for j [[, p$j##_type]]
0520
0521
0522 ]]
0523
0524 // Declares the value parameters.
0525
0526 $for i [[
0527 $range j 0..i-1
0528 #define GMOCK_INTERNAL_DECL_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]]) [[]]
0529 $for j, [[p$j##_type p$j]]
0530
0531
0532 ]]
0533
0534 // The suffix of the class template implementing the action template.
0535 $for i [[
0536
0537
0538 $range j 0..i-1
0539 #define GMOCK_INTERNAL_COUNT_AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]]) [[]]
0540 $if i==1 [[P]] $elif i>=2 [[P$i]]
0541 ]]
0542
0543
0544 // The name of the class template implementing the action template.
0545 #define GMOCK_ACTION_CLASS_(name, value_params)\
0546 GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params)
0547
0548 $range k 0..n-1
0549
0550 #define ACTION_TEMPLATE(name, template_params, value_params)\
0551 template <GMOCK_INTERNAL_DECL_##template_params\
0552 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
0553 class GMOCK_ACTION_CLASS_(name, value_params) {\
0554 public:\
0555 explicit GMOCK_ACTION_CLASS_(name, value_params)\
0556 GMOCK_INTERNAL_INIT_##value_params {}\
0557 template <typename F>\
0558 class gmock_Impl : public ::testing::ActionInterface<F> {\
0559 public:\
0560 typedef F function_type;\
0561 typedef typename ::testing::internal::Function<F>::Result return_type;\
0562 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
0563 args_type;\
0564 explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\
0565 virtual return_type Perform(const args_type& args) {\
0566 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
0567 Perform(this, args);\
0568 }\
0569 template <$for k, [[typename arg$k[[]]_type]]>\
0570 return_type gmock_PerformImpl(const args_type& args[[]]
0571 $for k [[, arg$k[[]]_type arg$k]]) const;\
0572 GMOCK_INTERNAL_DEFN_##value_params\
0573 private:\
0574 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
0575 };\
0576 template <typename F> operator ::testing::Action<F>() const {\
0577 return ::testing::Action<F>(\
0578 new gmock_Impl<F>(GMOCK_INTERNAL_LIST_##value_params));\
0579 }\
0580 GMOCK_INTERNAL_DEFN_##value_params\
0581 private:\
0582 GTEST_DISALLOW_ASSIGN_(GMOCK_ACTION_CLASS_(name, value_params));\
0583 };\
0584 template <GMOCK_INTERNAL_DECL_##template_params\
0585 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
0586 inline GMOCK_ACTION_CLASS_(name, value_params)<\
0587 GMOCK_INTERNAL_LIST_##template_params\
0588 GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\
0589 GMOCK_INTERNAL_DECL_##value_params) {\
0590 return GMOCK_ACTION_CLASS_(name, value_params)<\
0591 GMOCK_INTERNAL_LIST_##template_params\
0592 GMOCK_INTERNAL_LIST_TYPE_##value_params>(\
0593 GMOCK_INTERNAL_LIST_##value_params);\
0594 }\
0595 template <GMOCK_INTERNAL_DECL_##template_params\
0596 GMOCK_INTERNAL_DECL_TYPE_##value_params>\
0597 template <typename F>\
0598 template <typename arg0_type, typename arg1_type, typename arg2_type, \
0599 typename arg3_type, typename arg4_type, typename arg5_type, \
0600 typename arg6_type, typename arg7_type, typename arg8_type, \
0601 typename arg9_type>\
0602 typename ::testing::internal::Function<F>::Result\
0603 GMOCK_ACTION_CLASS_(name, value_params)<\
0604 GMOCK_INTERNAL_LIST_##template_params\
0605 GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl<F>::\
0606 gmock_PerformImpl(\
0607 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
0608
0609 $for i
0610
0611 [[
0612 $var template = [[$if i==0 [[]] $else [[
0613 $range j 0..i-1
0614
0615 template <$for j, [[typename p$j##_type]]>\
0616 ]]]]
0617 $var class_name = [[name##Action[[$if i==0 [[]] $elif i==1 [[P]]
0618 $else [[P$i]]]]]]
0619 $range j 0..i-1
0620 $var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
0621 $var param_types_and_names = [[$for j, [[p$j##_type p$j]]]]
0622 $var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]]
0623 $var param_field_decls = [[$for j
0624 [[
0625
0626 p$j##_type p$j;\
0627 ]]]]
0628 $var param_field_decls2 = [[$for j
0629 [[
0630
0631 p$j##_type p$j;\
0632 ]]]]
0633 $var params = [[$for j, [[p$j]]]]
0634 $var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]]
0635 $var typename_arg_types = [[$for k, [[typename arg$k[[]]_type]]]]
0636 $var arg_types_and_names = [[$for k, [[arg$k[[]]_type arg$k]]]]
0637 $var macro_name = [[$if i==0 [[ACTION]] $elif i==1 [[ACTION_P]]
0638 $else [[ACTION_P$i]]]]
0639
0640 #define $macro_name(name$for j [[, p$j]])\$template
0641 class $class_name {\
0642 public:\
0643 [[$if i==1 [[explicit ]]]]$class_name($ctor_param_list)$inits {}\
0644 template <typename F>\
0645 class gmock_Impl : public ::testing::ActionInterface<F> {\
0646 public:\
0647 typedef F function_type;\
0648 typedef typename ::testing::internal::Function<F>::Result return_type;\
0649 typedef typename ::testing::internal::Function<F>::ArgumentTuple\
0650 args_type;\
0651 [[$if i==1 [[explicit ]]]]gmock_Impl($ctor_param_list)$inits {}\
0652 virtual return_type Perform(const args_type& args) {\
0653 return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
0654 Perform(this, args);\
0655 }\
0656 template <$typename_arg_types>\
0657 return_type gmock_PerformImpl(const args_type& args, [[]]
0658 $arg_types_and_names) const;\$param_field_decls
0659 private:\
0660 GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
0661 };\
0662 template <typename F> operator ::testing::Action<F>() const {\
0663 return ::testing::Action<F>(new gmock_Impl<F>($params));\
0664 }\$param_field_decls2
0665 private:\
0666 GTEST_DISALLOW_ASSIGN_($class_name);\
0667 };\$template
0668 inline $class_name$param_types name($param_types_and_names) {\
0669 return $class_name$param_types($params);\
0670 }\$template
0671 template <typename F>\
0672 template <$typename_arg_types>\
0673 typename ::testing::internal::Function<F>::Result\
0674 $class_name$param_types::gmock_Impl<F>::gmock_PerformImpl(\
0675 GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
0676 ]]
0677 $$ } // This meta comment fixes auto-indentation in Emacs. It won't
0678 $$ // show up in the generated code.
0679
0680
0681 namespace testing {
0682
0683
0684 // The ACTION*() macros trigger warning C4100 (unreferenced formal
0685 // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
0686 // the macro definition, as the warnings are generated when the macro
0687 // is expanded and macro expansion cannot contain #pragma. Therefore
0688 // we suppress them here.
0689 #ifdef _MSC_VER
0690 # pragma warning(push)
0691 # pragma warning(disable:4100)
0692 #endif
0693
0694 // Various overloads for InvokeArgument<N>().
0695 //
0696 // The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
0697 // (0-based) argument, which must be a k-ary callable, of the mock
0698 // function, with arguments a1, a2, ..., a_k.
0699 //
0700 // Notes:
0701 //
0702 // 1. The arguments are passed by value by default. If you need to
0703 // pass an argument by reference, wrap it inside ByRef(). For
0704 // example,
0705 //
0706 // InvokeArgument<1>(5, string("Hello"), ByRef(foo))
0707 //
0708 // passes 5 and string("Hello") by value, and passes foo by
0709 // reference.
0710 //
0711 // 2. If the callable takes an argument by reference but ByRef() is
0712 // not used, it will receive the reference to a copy of the value,
0713 // instead of the original value. For example, when the 0-th
0714 // argument of the mock function takes a const string&, the action
0715 //
0716 // InvokeArgument<0>(string("Hello"))
0717 //
0718 // makes a copy of the temporary string("Hello") object and passes a
0719 // reference of the copy, instead of the original temporary object,
0720 // to the callable. This makes it easy for a user to define an
0721 // InvokeArgument action from temporary values and have it performed
0722 // later.
0723
0724 namespace internal {
0725 namespace invoke_argument {
0726
0727 // Appears in InvokeArgumentAdl's argument list to help avoid
0728 // accidental calls to user functions of the same name.
0729 struct AdlTag {};
0730
0731 // InvokeArgumentAdl - a helper for InvokeArgument.
0732 // The basic overloads are provided here for generic functors.
0733 // Overloads for other custom-callables are provided in the
0734 // internal/custom/callback-actions.h header.
0735
0736 $range i 0..n
0737 $for i
0738 [[
0739 $range j 1..i
0740
0741 template <typename R, typename F[[$for j [[, typename A$j]]]]>
0742 R InvokeArgumentAdl(AdlTag, F f[[$for j [[, A$j a$j]]]]) {
0743 return f([[$for j, [[a$j]]]]);
0744 }
0745 ]]
0746
0747 } // namespace invoke_argument
0748 } // namespace internal
0749
0750 $range i 0..n
0751 $for i [[
0752 $range j 0..i-1
0753
0754 ACTION_TEMPLATE(InvokeArgument,
0755 HAS_1_TEMPLATE_PARAMS(int, k),
0756 AND_$i[[]]_VALUE_PARAMS($for j, [[p$j]])) {
0757 using internal::invoke_argument::InvokeArgumentAdl;
0758 return InvokeArgumentAdl<return_type>(
0759 internal::invoke_argument::AdlTag(),
0760 ::testing::get<k>(args)$for j [[, p$j]]);
0761 }
0762
0763 ]]
0764
0765 // Various overloads for ReturnNew<T>().
0766 //
0767 // The ReturnNew<T>(a1, a2, ..., a_k) action returns a pointer to a new
0768 // instance of type T, constructed on the heap with constructor arguments
0769 // a1, a2, ..., and a_k. The caller assumes ownership of the returned value.
0770 $range i 0..n
0771 $for i [[
0772 $range j 0..i-1
0773 $var ps = [[$for j, [[p$j]]]]
0774
0775 ACTION_TEMPLATE(ReturnNew,
0776 HAS_1_TEMPLATE_PARAMS(typename, T),
0777 AND_$i[[]]_VALUE_PARAMS($ps)) {
0778 return new T($ps);
0779 }
0780
0781 ]]
0782
0783 #ifdef _MSC_VER
0784 # pragma warning(pop)
0785 #endif
0786
0787 } // namespace testing
0788
0789 // Include any custom callback actions added by the local installation.
0790 // We must include this header at the end to make sure it can use the
0791 // declarations from this file.
0792 #include "gmock/internal/custom/gmock-generated-actions.h"
0793
0794 #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_