Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:03:07

0001 // Copyright 2007, Google Inc.
0002 // All rights reserved.
0003 //
0004 // Redistribution and use in source and binary forms, with or without
0005 // modification, are permitted provided that the following conditions are
0006 // met:
0007 //
0008 //     * Redistributions of source code must retain the above copyright
0009 // notice, this list of conditions and the following disclaimer.
0010 //     * Redistributions in binary form must reproduce the above
0011 // copyright notice, this list of conditions and the following disclaimer
0012 // in the documentation and/or other materials provided with the
0013 // distribution.
0014 //     * Neither the name of Google Inc. nor the names of its
0015 // contributors may be used to endorse or promote products derived from
0016 // this software without specific prior written permission.
0017 //
0018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0022 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0029 
0030 // Google Mock - a framework for writing C++ mock classes.
0031 //
0032 // This file implements some commonly used variadic actions.
0033 
0034 // IWYU pragma: private, include "gmock/gmock.h"
0035 // IWYU pragma: friend gmock/.*
0036 
0037 #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
0038 #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_
0039 
0040 #include <memory>
0041 #include <utility>
0042 
0043 #include "gmock/gmock-actions.h"
0044 #include "gmock/internal/gmock-port.h"
0045 
0046 // Include any custom callback actions added by the local installation.
0047 #include "gmock/internal/custom/gmock-generated-actions.h"
0048 
0049 // Sometimes you want to give an action explicit template parameters
0050 // that cannot be inferred from its value parameters.  ACTION() and
0051 // ACTION_P*() don't support that.  ACTION_TEMPLATE() remedies that
0052 // and can be viewed as an extension to ACTION() and ACTION_P*().
0053 //
0054 // The syntax:
0055 //
0056 //   ACTION_TEMPLATE(ActionName,
0057 //                   HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m),
0058 //                   AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; }
0059 //
0060 // defines an action template that takes m explicit template
0061 // parameters and n value parameters.  name_i is the name of the i-th
0062 // template parameter, and kind_i specifies whether it's a typename,
0063 // an integral constant, or a template.  p_i is the name of the i-th
0064 // value parameter.
0065 //
0066 // Example:
0067 //
0068 //   // DuplicateArg<k, T>(output) converts the k-th argument of the mock
0069 //   // function to type T and copies it to *output.
0070 //   ACTION_TEMPLATE(DuplicateArg,
0071 //                   HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
0072 //                   AND_1_VALUE_PARAMS(output)) {
0073 //     *output = T(::std::get<k>(args));
0074 //   }
0075 //   ...
0076 //     int n;
0077 //     EXPECT_CALL(mock, Foo(_, _))
0078 //         .WillOnce(DuplicateArg<1, unsigned char>(&n));
0079 //
0080 // To create an instance of an action template, write:
0081 //
0082 //   ActionName<t1, ..., t_m>(v1, ..., v_n)
0083 //
0084 // where the ts are the template arguments and the vs are the value
0085 // arguments.  The value argument types are inferred by the compiler.
0086 // If you want to explicitly specify the value argument types, you can
0087 // provide additional template arguments:
0088 //
0089 //   ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n)
0090 //
0091 // where u_i is the desired type of v_i.
0092 //
0093 // ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the
0094 // number of value parameters, but not on the number of template
0095 // parameters.  Without the restriction, the meaning of the following
0096 // is unclear:
0097 //
0098 //   OverloadedAction<int, bool>(x);
0099 //
0100 // Are we using a single-template-parameter action where 'bool' refers
0101 // to the type of x, or are we using a two-template-parameter action
0102 // where the compiler is asked to infer the type of x?
0103 //
0104 // Implementation notes:
0105 //
0106 // GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and
0107 // GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for
0108 // implementing ACTION_TEMPLATE.  The main trick we use is to create
0109 // new macro invocations when expanding a macro.  For example, we have
0110 //
0111 //   #define ACTION_TEMPLATE(name, template_params, value_params)
0112 //       ... GMOCK_INTERNAL_DECL_##template_params ...
0113 //
0114 // which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...)
0115 // to expand to
0116 //
0117 //       ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ...
0118 //
0119 // Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the
0120 // preprocessor will continue to expand it to
0121 //
0122 //       ... typename T ...
0123 //
0124 // This technique conforms to the C++ standard and is portable.  It
0125 // allows us to implement action templates using O(N) code, where N is
0126 // the maximum number of template/value parameters supported.  Without
0127 // using it, we'd have to devote O(N^2) amount of code to implement all
0128 // combinations of m and n.
0129 
0130 // Declares the template parameters.
0131 #define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0
0132 #define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, name1) \
0133   kind0 name0, kind1 name1
0134 #define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
0135                                                   kind2, name2)               \
0136   kind0 name0, kind1 name1, kind2 name2
0137 #define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
0138                                                   kind2, name2, kind3, name3) \
0139   kind0 name0, kind1 name1, kind2 name2, kind3 name3
0140 #define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(                        \
0141     kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4) \
0142   kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4
0143 #define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
0144                                                   kind2, name2, kind3, name3, \
0145                                                   kind4, name4, kind5, name5) \
0146   kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5
0147 #define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(                        \
0148     kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \
0149     kind5, name5, kind6, name6)                                           \
0150   kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4,        \
0151       kind5 name5, kind6 name6
0152 #define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(                        \
0153     kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \
0154     kind5, name5, kind6, name6, kind7, name7)                             \
0155   kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4,        \
0156       kind5 name5, kind6 name6, kind7 name7
0157 #define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(                        \
0158     kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \
0159     kind5, name5, kind6, name6, kind7, name7, kind8, name8)               \
0160   kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4,        \
0161       kind5 name5, kind6 name6, kind7 name7, kind8 name8
0162 #define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(                       \
0163     kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \
0164     kind5, name5, kind6, name6, kind7, name7, kind8, name8, kind9, name9) \
0165   kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4,        \
0166       kind5 name5, kind6 name6, kind7 name7, kind8 name8, kind9 name9
0167 
0168 // Lists the template parameters.
0169 #define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0
0170 #define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, name1) \
0171   name0, name1
0172 #define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
0173                                                   kind2, name2)               \
0174   name0, name1, name2
0175 #define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
0176                                                   kind2, name2, kind3, name3) \
0177   name0, name1, name2, name3
0178 #define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(                        \
0179     kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4) \
0180   name0, name1, name2, name3, name4
0181 #define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
0182                                                   kind2, name2, kind3, name3, \
0183                                                   kind4, name4, kind5, name5) \
0184   name0, name1, name2, name3, name4, name5
0185 #define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(                        \
0186     kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \
0187     kind5, name5, kind6, name6)                                           \
0188   name0, name1, name2, name3, name4, name5, name6
0189 #define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(                        \
0190     kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \
0191     kind5, name5, kind6, name6, kind7, name7)                             \
0192   name0, name1, name2, name3, name4, name5, name6, name7
0193 #define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(                        \
0194     kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \
0195     kind5, name5, kind6, name6, kind7, name7, kind8, name8)               \
0196   name0, name1, name2, name3, name4, name5, name6, name7, name8
0197 #define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(                       \
0198     kind0, name0, kind1, name1, kind2, name2, kind3, name3, kind4, name4, \
0199     kind5, name5, kind6, name6, kind7, name7, kind8, name8, kind9, name9) \
0200   name0, name1, name2, name3, name4, name5, name6, name7, name8, name9
0201 
0202 // Declares the types of value parameters.
0203 #define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS()
0204 #define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type
0205 #define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) \
0206   , typename p0##_type, typename p1##_type
0207 #define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) \
0208   , typename p0##_type, typename p1##_type, typename p2##_type
0209 #define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) \
0210   , typename p0##_type, typename p1##_type, typename p2##_type,     \
0211       typename p3##_type
0212 #define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \
0213   , typename p0##_type, typename p1##_type, typename p2##_type,         \
0214       typename p3##_type, typename p4##_type
0215 #define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) \
0216   , typename p0##_type, typename p1##_type, typename p2##_type,             \
0217       typename p3##_type, typename p4##_type, typename p5##_type
0218 #define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
0219                                                     p6)                     \
0220   , typename p0##_type, typename p1##_type, typename p2##_type,             \
0221       typename p3##_type, typename p4##_type, typename p5##_type,           \
0222       typename p6##_type
0223 #define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
0224                                                     p6, p7)                 \
0225   , typename p0##_type, typename p1##_type, typename p2##_type,             \
0226       typename p3##_type, typename p4##_type, typename p5##_type,           \
0227       typename p6##_type, typename p7##_type
0228 #define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
0229                                                     p6, p7, p8)             \
0230   , typename p0##_type, typename p1##_type, typename p2##_type,             \
0231       typename p3##_type, typename p4##_type, typename p5##_type,           \
0232       typename p6##_type, typename p7##_type, typename p8##_type
0233 #define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
0234                                                      p6, p7, p8, p9)         \
0235   , typename p0##_type, typename p1##_type, typename p2##_type,              \
0236       typename p3##_type, typename p4##_type, typename p5##_type,            \
0237       typename p6##_type, typename p7##_type, typename p8##_type,            \
0238       typename p9##_type
0239 
0240 // Initializes the value parameters.
0241 #define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS() ()
0242 #define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0) \
0243   (p0##_type gmock_p0) : p0(::std::move(gmock_p0))
0244 #define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1) \
0245   (p0##_type gmock_p0, p1##_type gmock_p1)             \
0246       : p0(::std::move(gmock_p0)), p1(::std::move(gmock_p1))
0247 #define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)     \
0248   (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2) \
0249       : p0(::std::move(gmock_p0)),                             \
0250         p1(::std::move(gmock_p1)),                             \
0251         p2(::std::move(gmock_p2))
0252 #define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) \
0253   (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
0254    p3##_type gmock_p3)                                         \
0255       : p0(::std::move(gmock_p0)),                             \
0256         p1(::std::move(gmock_p1)),                             \
0257         p2(::std::move(gmock_p2)),                             \
0258         p3(::std::move(gmock_p3))
0259 #define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \
0260   (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2,     \
0261    p3##_type gmock_p3, p4##_type gmock_p4)                         \
0262       : p0(::std::move(gmock_p0)),                                 \
0263         p1(::std::move(gmock_p1)),                                 \
0264         p2(::std::move(gmock_p2)),                                 \
0265         p3(::std::move(gmock_p3)),                                 \
0266         p4(::std::move(gmock_p4))
0267 #define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) \
0268   (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2,         \
0269    p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5)         \
0270       : p0(::std::move(gmock_p0)),                                     \
0271         p1(::std::move(gmock_p1)),                                     \
0272         p2(::std::move(gmock_p2)),                                     \
0273         p3(::std::move(gmock_p3)),                                     \
0274         p4(::std::move(gmock_p4)),                                     \
0275         p5(::std::move(gmock_p5))
0276 #define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) \
0277   (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2,             \
0278    p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5,             \
0279    p6##_type gmock_p6)                                                     \
0280       : p0(::std::move(gmock_p0)),                                         \
0281         p1(::std::move(gmock_p1)),                                         \
0282         p2(::std::move(gmock_p2)),                                         \
0283         p3(::std::move(gmock_p3)),                                         \
0284         p4(::std::move(gmock_p4)),                                         \
0285         p5(::std::move(gmock_p5)),                                         \
0286         p6(::std::move(gmock_p6))
0287 #define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7) \
0288   (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2,                 \
0289    p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5,                 \
0290    p6##_type gmock_p6, p7##_type gmock_p7)                                     \
0291       : p0(::std::move(gmock_p0)),                                             \
0292         p1(::std::move(gmock_p1)),                                             \
0293         p2(::std::move(gmock_p2)),                                             \
0294         p3(::std::move(gmock_p3)),                                             \
0295         p4(::std::move(gmock_p4)),                                             \
0296         p5(::std::move(gmock_p5)),                                             \
0297         p6(::std::move(gmock_p6)),                                             \
0298         p7(::std::move(gmock_p7))
0299 #define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, \
0300                                                p8)                             \
0301   (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2,                 \
0302    p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5,                 \
0303    p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8)                 \
0304       : p0(::std::move(gmock_p0)),                                             \
0305         p1(::std::move(gmock_p1)),                                             \
0306         p2(::std::move(gmock_p2)),                                             \
0307         p3(::std::move(gmock_p3)),                                             \
0308         p4(::std::move(gmock_p4)),                                             \
0309         p5(::std::move(gmock_p5)),                                             \
0310         p6(::std::move(gmock_p6)),                                             \
0311         p7(::std::move(gmock_p7)),                                             \
0312         p8(::std::move(gmock_p8))
0313 #define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
0314                                                 p7, p8, p9)                 \
0315   (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2,              \
0316    p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5,              \
0317    p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8,              \
0318    p9##_type gmock_p9)                                                      \
0319       : p0(::std::move(gmock_p0)),                                          \
0320         p1(::std::move(gmock_p1)),                                          \
0321         p2(::std::move(gmock_p2)),                                          \
0322         p3(::std::move(gmock_p3)),                                          \
0323         p4(::std::move(gmock_p4)),                                          \
0324         p5(::std::move(gmock_p5)),                                          \
0325         p6(::std::move(gmock_p6)),                                          \
0326         p7(::std::move(gmock_p7)),                                          \
0327         p8(::std::move(gmock_p8)),                                          \
0328         p9(::std::move(gmock_p9))
0329 
0330 // Defines the copy constructor
0331 #define GMOCK_INTERNAL_DEFN_COPY_AND_0_VALUE_PARAMS() \
0332   {}  // Avoid https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82134
0333 #define GMOCK_INTERNAL_DEFN_COPY_AND_1_VALUE_PARAMS(...) = default;
0334 #define GMOCK_INTERNAL_DEFN_COPY_AND_2_VALUE_PARAMS(...) = default;
0335 #define GMOCK_INTERNAL_DEFN_COPY_AND_3_VALUE_PARAMS(...) = default;
0336 #define GMOCK_INTERNAL_DEFN_COPY_AND_4_VALUE_PARAMS(...) = default;
0337 #define GMOCK_INTERNAL_DEFN_COPY_AND_5_VALUE_PARAMS(...) = default;
0338 #define GMOCK_INTERNAL_DEFN_COPY_AND_6_VALUE_PARAMS(...) = default;
0339 #define GMOCK_INTERNAL_DEFN_COPY_AND_7_VALUE_PARAMS(...) = default;
0340 #define GMOCK_INTERNAL_DEFN_COPY_AND_8_VALUE_PARAMS(...) = default;
0341 #define GMOCK_INTERNAL_DEFN_COPY_AND_9_VALUE_PARAMS(...) = default;
0342 #define GMOCK_INTERNAL_DEFN_COPY_AND_10_VALUE_PARAMS(...) = default;
0343 
0344 // Declares the fields for storing the value parameters.
0345 #define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS()
0346 #define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0;
0347 #define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) \
0348   p0##_type p0;                                        \
0349   p1##_type p1;
0350 #define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) \
0351   p0##_type p0;                                            \
0352   p1##_type p1;                                            \
0353   p2##_type p2;
0354 #define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) \
0355   p0##_type p0;                                                \
0356   p1##_type p1;                                                \
0357   p2##_type p2;                                                \
0358   p3##_type p3;
0359 #define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \
0360   p0##_type p0;                                                    \
0361   p1##_type p1;                                                    \
0362   p2##_type p2;                                                    \
0363   p3##_type p3;                                                    \
0364   p4##_type p4;
0365 #define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) \
0366   p0##_type p0;                                                        \
0367   p1##_type p1;                                                        \
0368   p2##_type p2;                                                        \
0369   p3##_type p3;                                                        \
0370   p4##_type p4;                                                        \
0371   p5##_type p5;
0372 #define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) \
0373   p0##_type p0;                                                            \
0374   p1##_type p1;                                                            \
0375   p2##_type p2;                                                            \
0376   p3##_type p3;                                                            \
0377   p4##_type p4;                                                            \
0378   p5##_type p5;                                                            \
0379   p6##_type p6;
0380 #define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7) \
0381   p0##_type p0;                                                                \
0382   p1##_type p1;                                                                \
0383   p2##_type p2;                                                                \
0384   p3##_type p3;                                                                \
0385   p4##_type p4;                                                                \
0386   p5##_type p5;                                                                \
0387   p6##_type p6;                                                                \
0388   p7##_type p7;
0389 #define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, \
0390                                                p8)                             \
0391   p0##_type p0;                                                                \
0392   p1##_type p1;                                                                \
0393   p2##_type p2;                                                                \
0394   p3##_type p3;                                                                \
0395   p4##_type p4;                                                                \
0396   p5##_type p5;                                                                \
0397   p6##_type p6;                                                                \
0398   p7##_type p7;                                                                \
0399   p8##_type p8;
0400 #define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
0401                                                 p7, p8, p9)                 \
0402   p0##_type p0;                                                             \
0403   p1##_type p1;                                                             \
0404   p2##_type p2;                                                             \
0405   p3##_type p3;                                                             \
0406   p4##_type p4;                                                             \
0407   p5##_type p5;                                                             \
0408   p6##_type p6;                                                             \
0409   p7##_type p7;                                                             \
0410   p8##_type p8;                                                             \
0411   p9##_type p9;
0412 
0413 // Lists the value parameters.
0414 #define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS()
0415 #define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0
0416 #define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1
0417 #define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2
0418 #define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3
0419 #define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \
0420   p0, p1, p2, p3, p4
0421 #define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) \
0422   p0, p1, p2, p3, p4, p5
0423 #define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) \
0424   p0, p1, p2, p3, p4, p5, p6
0425 #define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7) \
0426   p0, p1, p2, p3, p4, p5, p6, p7
0427 #define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, \
0428                                                p8)                             \
0429   p0, p1, p2, p3, p4, p5, p6, p7, p8
0430 #define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
0431                                                 p7, p8, p9)                 \
0432   p0, p1, p2, p3, p4, p5, p6, p7, p8, p9
0433 
0434 // Lists the value parameter types.
0435 #define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS()
0436 #define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type
0437 #define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) \
0438   , p0##_type, p1##_type
0439 #define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) \
0440   , p0##_type, p1##_type, p2##_type
0441 #define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) \
0442   , p0##_type, p1##_type, p2##_type, p3##_type
0443 #define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \
0444   , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type
0445 #define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) \
0446   , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type
0447 #define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
0448                                                     p6)                     \
0449   , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, p6##_type
0450 #define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
0451                                                     p6, p7)                 \
0452   , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type,       \
0453       p6##_type, p7##_type
0454 #define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
0455                                                     p6, p7, p8)             \
0456   , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type,       \
0457       p6##_type, p7##_type, p8##_type
0458 #define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
0459                                                      p6, p7, p8, p9)         \
0460   , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type,        \
0461       p6##_type, p7##_type, p8##_type, p9##_type
0462 
0463 // Declares the value parameters.
0464 #define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS()
0465 #define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0
0466 #define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) \
0467   p0##_type p0, p1##_type p1
0468 #define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) \
0469   p0##_type p0, p1##_type p1, p2##_type p2
0470 #define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) \
0471   p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3
0472 #define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) \
0473   p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4
0474 #define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)  \
0475   p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
0476       p5##_type p5
0477 #define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) \
0478   p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4,    \
0479       p5##_type p5, p6##_type p6
0480 #define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7) \
0481   p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4,        \
0482       p5##_type p5, p6##_type p6, p7##_type p7
0483 #define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, \
0484                                                p8)                             \
0485   p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4,        \
0486       p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8
0487 #define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
0488                                                 p7, p8, p9)                 \
0489   p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4,     \
0490       p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, p9##_type p9
0491 
0492 // The suffix of the class template implementing the action template.
0493 #define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS()
0494 #define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P
0495 #define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2
0496 #define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3
0497 #define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4
0498 #define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5
0499 #define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6
0500 #define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7
0501 #define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
0502                                                 p7)                         \
0503   P8
0504 #define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
0505                                                 p7, p8)                     \
0506   P9
0507 #define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
0508                                                  p7, p8, p9)                 \
0509   P10
0510 
0511 // The name of the class template implementing the action template.
0512 #define GMOCK_ACTION_CLASS_(name, value_params) \
0513   GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params)
0514 
0515 #define ACTION_TEMPLATE(name, template_params, value_params)                   \
0516   template <GMOCK_INTERNAL_DECL_##template_params                              \
0517                 GMOCK_INTERNAL_DECL_TYPE_##value_params>                       \
0518   class GMOCK_ACTION_CLASS_(name, value_params) {                              \
0519    public:                                                                     \
0520     explicit GMOCK_ACTION_CLASS_(name, value_params)(                          \
0521         GMOCK_INTERNAL_DECL_##value_params)                                    \
0522         GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params),    \
0523                     = default;                                                 \
0524                     ,                                                          \
0525                     : impl_(std::make_shared<gmock_Impl>(                      \
0526                         GMOCK_INTERNAL_LIST_##value_params)){})                \
0527             GMOCK_ACTION_CLASS_(name, value_params)(const GMOCK_ACTION_CLASS_( \
0528                 name, value_params) &) noexcept GMOCK_INTERNAL_DEFN_COPY_      \
0529         ##value_params GMOCK_ACTION_CLASS_(name, value_params)(                \
0530             GMOCK_ACTION_CLASS_(name, value_params) &&) noexcept               \
0531         GMOCK_INTERNAL_DEFN_COPY_##value_params template <typename F>          \
0532         operator ::testing::Action<F>() const {                                \
0533       return GMOCK_PP_IF(                                                      \
0534           GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params),              \
0535           (::testing::internal::MakeAction<F, gmock_Impl>()),                  \
0536           (::testing::internal::MakeAction<F>(impl_)));                        \
0537     }                                                                          \
0538                                                                                \
0539    private:                                                                    \
0540     class gmock_Impl {                                                         \
0541      public:                                                                   \
0542       explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}                \
0543       template <typename function_type, typename return_type,                  \
0544                 typename args_type, GMOCK_ACTION_TEMPLATE_ARGS_NAMES_>         \
0545       return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;  \
0546       GMOCK_INTERNAL_DEFN_##value_params                                       \
0547     };                                                                         \
0548     GMOCK_PP_IF(GMOCK_PP_IS_EMPTY(GMOCK_INTERNAL_COUNT_##value_params), ,      \
0549                 std::shared_ptr<const gmock_Impl> impl_;)                      \
0550   };                                                                           \
0551   template <GMOCK_INTERNAL_DECL_##template_params                              \
0552                 GMOCK_INTERNAL_DECL_TYPE_##value_params>                       \
0553   GMOCK_ACTION_CLASS_(                                                         \
0554       name, value_params)<GMOCK_INTERNAL_LIST_##template_params                \
0555                               GMOCK_INTERNAL_LIST_TYPE_##value_params>         \
0556       name(GMOCK_INTERNAL_DECL_##value_params) GTEST_MUST_USE_RESULT_;         \
0557   template <GMOCK_INTERNAL_DECL_##template_params                              \
0558                 GMOCK_INTERNAL_DECL_TYPE_##value_params>                       \
0559   inline GMOCK_ACTION_CLASS_(                                                  \
0560       name, value_params)<GMOCK_INTERNAL_LIST_##template_params                \
0561                               GMOCK_INTERNAL_LIST_TYPE_##value_params>         \
0562   name(GMOCK_INTERNAL_DECL_##value_params) {                                   \
0563     return GMOCK_ACTION_CLASS_(                                                \
0564         name, value_params)<GMOCK_INTERNAL_LIST_##template_params              \
0565                                 GMOCK_INTERNAL_LIST_TYPE_##value_params>(      \
0566         GMOCK_INTERNAL_LIST_##value_params);                                   \
0567   }                                                                            \
0568   template <GMOCK_INTERNAL_DECL_##template_params                              \
0569                 GMOCK_INTERNAL_DECL_TYPE_##value_params>                       \
0570   template <typename function_type, typename return_type, typename args_type,  \
0571             GMOCK_ACTION_TEMPLATE_ARGS_NAMES_>                                 \
0572   return_type GMOCK_ACTION_CLASS_(                                             \
0573       name, value_params)<GMOCK_INTERNAL_LIST_##template_params                \
0574                               GMOCK_INTERNAL_LIST_TYPE_##value_params>::       \
0575       gmock_Impl::gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_)  \
0576           const
0577 
0578 namespace testing {
0579 
0580 // The ACTION*() macros trigger warning C4100 (unreferenced formal
0581 // parameter) in MSVC with -W4.  Unfortunately they cannot be fixed in
0582 // the macro definition, as the warnings are generated when the macro
0583 // is expanded and macro expansion cannot contain #pragma.  Therefore
0584 // we suppress them here.
0585 #ifdef _MSC_VER
0586 #pragma warning(push)
0587 #pragma warning(disable : 4100)
0588 #endif
0589 
0590 namespace internal {
0591 
0592 // internal::InvokeArgument - a helper for InvokeArgument action.
0593 // The basic overloads are provided here for generic functors.
0594 // Overloads for other custom-callables are provided in the
0595 // internal/custom/gmock-generated-actions.h header.
0596 template <typename F, typename... Args>
0597 auto InvokeArgument(F f, Args... args) -> decltype(f(args...)) {
0598   return f(args...);
0599 }
0600 
0601 template <std::size_t index, typename... Params>
0602 struct InvokeArgumentAction {
0603   template <typename... Args,
0604             typename = typename std::enable_if<(index < sizeof...(Args))>::type>
0605   auto operator()(Args&&... args) const -> decltype(internal::InvokeArgument(
0606       std::get<index>(std::forward_as_tuple(std::forward<Args>(args)...)),
0607       std::declval<const Params&>()...)) {
0608     internal::FlatTuple<Args&&...> args_tuple(FlatTupleConstructTag{},
0609                                               std::forward<Args>(args)...);
0610     return params.Apply([&](const Params&... unpacked_params) {
0611       auto&& callable = args_tuple.template Get<index>();
0612       return internal::InvokeArgument(
0613           std::forward<decltype(callable)>(callable), unpacked_params...);
0614     });
0615   }
0616 
0617   internal::FlatTuple<Params...> params;
0618 };
0619 
0620 }  // namespace internal
0621 
0622 // The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
0623 // (0-based) argument, which must be a k-ary callable, of the mock
0624 // function, with arguments a1, a2, ..., a_k.
0625 //
0626 // Notes:
0627 //
0628 //   1. The arguments are passed by value by default.  If you need to
0629 //   pass an argument by reference, wrap it inside std::ref().  For
0630 //   example,
0631 //
0632 //     InvokeArgument<1>(5, string("Hello"), std::ref(foo))
0633 //
0634 //   passes 5 and string("Hello") by value, and passes foo by
0635 //   reference.
0636 //
0637 //   2. If the callable takes an argument by reference but std::ref() is
0638 //   not used, it will receive the reference to a copy of the value,
0639 //   instead of the original value.  For example, when the 0-th
0640 //   argument of the mock function takes a const string&, the action
0641 //
0642 //     InvokeArgument<0>(string("Hello"))
0643 //
0644 //   makes a copy of the temporary string("Hello") object and passes a
0645 //   reference of the copy, instead of the original temporary object,
0646 //   to the callable.  This makes it easy for a user to define an
0647 //   InvokeArgument action from temporary values and have it performed
0648 //   later.
0649 template <std::size_t index, typename... Params>
0650 internal::InvokeArgumentAction<index, typename std::decay<Params>::type...>
0651 InvokeArgument(Params&&... params) {
0652   return {internal::FlatTuple<typename std::decay<Params>::type...>(
0653       internal::FlatTupleConstructTag{}, std::forward<Params>(params)...)};
0654 }
0655 
0656 #ifdef _MSC_VER
0657 #pragma warning(pop)
0658 #endif
0659 
0660 }  // namespace testing
0661 
0662 #endif  // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_MORE_ACTIONS_H_