gmock-generated-actions.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. // This file was GENERATED by command:
  2. // pump.py gmock-generated-actions.h.pump
  3. // DO NOT EDIT BY HAND!!!
  4. // Copyright 2007, Google Inc.
  5. // All rights reserved.
  6. //
  7. // Redistribution and use in source and binary forms, with or without
  8. // modification, are permitted provided that the following conditions are
  9. // met:
  10. //
  11. // * Redistributions of source code must retain the above copyright
  12. // notice, this list of conditions and the following disclaimer.
  13. // * Redistributions in binary form must reproduce the above
  14. // copyright notice, this list of conditions and the following disclaimer
  15. // in the documentation and/or other materials provided with the
  16. // distribution.
  17. // * Neither the name of Google Inc. nor the names of its
  18. // contributors may be used to endorse or promote products derived from
  19. // this software without specific prior written permission.
  20. //
  21. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. // Google Mock - a framework for writing C++ mock classes.
  33. //
  34. // This file implements some commonly used variadic actions.
  35. // GOOGLETEST_CM0002 DO NOT DELETE
  36. #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
  37. #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_
  38. #include <memory>
  39. #include <utility>
  40. #include "gmock/gmock-actions.h"
  41. #include "gmock/internal/gmock-port.h"
  42. // Sometimes you want to give an action explicit template parameters
  43. // that cannot be inferred from its value parameters. ACTION() and
  44. // ACTION_P*() don't support that. ACTION_TEMPLATE() remedies that
  45. // and can be viewed as an extension to ACTION() and ACTION_P*().
  46. //
  47. // The syntax:
  48. //
  49. // ACTION_TEMPLATE(ActionName,
  50. // HAS_m_TEMPLATE_PARAMS(kind1, name1, ..., kind_m, name_m),
  51. // AND_n_VALUE_PARAMS(p1, ..., p_n)) { statements; }
  52. //
  53. // defines an action template that takes m explicit template
  54. // parameters and n value parameters. name_i is the name of the i-th
  55. // template parameter, and kind_i specifies whether it's a typename,
  56. // an integral constant, or a template. p_i is the name of the i-th
  57. // value parameter.
  58. //
  59. // Example:
  60. //
  61. // // DuplicateArg<k, T>(output) converts the k-th argument of the mock
  62. // // function to type T and copies it to *output.
  63. // ACTION_TEMPLATE(DuplicateArg,
  64. // HAS_2_TEMPLATE_PARAMS(int, k, typename, T),
  65. // AND_1_VALUE_PARAMS(output)) {
  66. // *output = T(::std::get<k>(args));
  67. // }
  68. // ...
  69. // int n;
  70. // EXPECT_CALL(mock, Foo(_, _))
  71. // .WillOnce(DuplicateArg<1, unsigned char>(&n));
  72. //
  73. // To create an instance of an action template, write:
  74. //
  75. // ActionName<t1, ..., t_m>(v1, ..., v_n)
  76. //
  77. // where the ts are the template arguments and the vs are the value
  78. // arguments. The value argument types are inferred by the compiler.
  79. // If you want to explicitly specify the value argument types, you can
  80. // provide additional template arguments:
  81. //
  82. // ActionName<t1, ..., t_m, u1, ..., u_k>(v1, ..., v_n)
  83. //
  84. // where u_i is the desired type of v_i.
  85. //
  86. // ACTION_TEMPLATE and ACTION/ACTION_P* can be overloaded on the
  87. // number of value parameters, but not on the number of template
  88. // parameters. Without the restriction, the meaning of the following
  89. // is unclear:
  90. //
  91. // OverloadedAction<int, bool>(x);
  92. //
  93. // Are we using a single-template-parameter action where 'bool' refers
  94. // to the type of x, or are we using a two-template-parameter action
  95. // where the compiler is asked to infer the type of x?
  96. //
  97. // Implementation notes:
  98. //
  99. // GMOCK_INTERNAL_*_HAS_m_TEMPLATE_PARAMS and
  100. // GMOCK_INTERNAL_*_AND_n_VALUE_PARAMS are internal macros for
  101. // implementing ACTION_TEMPLATE. The main trick we use is to create
  102. // new macro invocations when expanding a macro. For example, we have
  103. //
  104. // #define ACTION_TEMPLATE(name, template_params, value_params)
  105. // ... GMOCK_INTERNAL_DECL_##template_params ...
  106. //
  107. // which causes ACTION_TEMPLATE(..., HAS_1_TEMPLATE_PARAMS(typename, T), ...)
  108. // to expand to
  109. //
  110. // ... GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(typename, T) ...
  111. //
  112. // Since GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS is a macro, the
  113. // preprocessor will continue to expand it to
  114. //
  115. // ... typename T ...
  116. //
  117. // This technique conforms to the C++ standard and is portable. It
  118. // allows us to implement action templates using O(N) code, where N is
  119. // the maximum number of template/value parameters supported. Without
  120. // using it, we'd have to devote O(N^2) amount of code to implement all
  121. // combinations of m and n.
  122. // Declares the template parameters.
  123. #define GMOCK_INTERNAL_DECL_HAS_1_TEMPLATE_PARAMS(kind0, name0) kind0 name0
  124. #define GMOCK_INTERNAL_DECL_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
  125. name1) kind0 name0, kind1 name1
  126. #define GMOCK_INTERNAL_DECL_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
  127. kind2, name2) kind0 name0, kind1 name1, kind2 name2
  128. #define GMOCK_INTERNAL_DECL_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
  129. kind2, name2, kind3, name3) kind0 name0, kind1 name1, kind2 name2, \
  130. kind3 name3
  131. #define GMOCK_INTERNAL_DECL_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
  132. kind2, name2, kind3, name3, kind4, name4) kind0 name0, kind1 name1, \
  133. kind2 name2, kind3 name3, kind4 name4
  134. #define GMOCK_INTERNAL_DECL_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
  135. kind2, name2, kind3, name3, kind4, name4, kind5, name5) kind0 name0, \
  136. kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5
  137. #define GMOCK_INTERNAL_DECL_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
  138. kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
  139. name6) kind0 name0, kind1 name1, kind2 name2, kind3 name3, kind4 name4, \
  140. kind5 name5, kind6 name6
  141. #define GMOCK_INTERNAL_DECL_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
  142. kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
  143. kind7, name7) kind0 name0, kind1 name1, kind2 name2, kind3 name3, \
  144. kind4 name4, kind5 name5, kind6 name6, kind7 name7
  145. #define GMOCK_INTERNAL_DECL_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
  146. kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
  147. kind7, name7, kind8, name8) kind0 name0, kind1 name1, kind2 name2, \
  148. kind3 name3, kind4 name4, kind5 name5, kind6 name6, kind7 name7, \
  149. kind8 name8
  150. #define GMOCK_INTERNAL_DECL_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
  151. name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
  152. name6, kind7, name7, kind8, name8, kind9, name9) kind0 name0, \
  153. kind1 name1, kind2 name2, kind3 name3, kind4 name4, kind5 name5, \
  154. kind6 name6, kind7 name7, kind8 name8, kind9 name9
  155. // Lists the template parameters.
  156. #define GMOCK_INTERNAL_LIST_HAS_1_TEMPLATE_PARAMS(kind0, name0) name0
  157. #define GMOCK_INTERNAL_LIST_HAS_2_TEMPLATE_PARAMS(kind0, name0, kind1, \
  158. name1) name0, name1
  159. #define GMOCK_INTERNAL_LIST_HAS_3_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
  160. kind2, name2) name0, name1, name2
  161. #define GMOCK_INTERNAL_LIST_HAS_4_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
  162. kind2, name2, kind3, name3) name0, name1, name2, name3
  163. #define GMOCK_INTERNAL_LIST_HAS_5_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
  164. kind2, name2, kind3, name3, kind4, name4) name0, name1, name2, name3, \
  165. name4
  166. #define GMOCK_INTERNAL_LIST_HAS_6_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
  167. kind2, name2, kind3, name3, kind4, name4, kind5, name5) name0, name1, \
  168. name2, name3, name4, name5
  169. #define GMOCK_INTERNAL_LIST_HAS_7_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
  170. kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
  171. name6) name0, name1, name2, name3, name4, name5, name6
  172. #define GMOCK_INTERNAL_LIST_HAS_8_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
  173. kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
  174. kind7, name7) name0, name1, name2, name3, name4, name5, name6, name7
  175. #define GMOCK_INTERNAL_LIST_HAS_9_TEMPLATE_PARAMS(kind0, name0, kind1, name1, \
  176. kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, name6, \
  177. kind7, name7, kind8, name8) name0, name1, name2, name3, name4, name5, \
  178. name6, name7, name8
  179. #define GMOCK_INTERNAL_LIST_HAS_10_TEMPLATE_PARAMS(kind0, name0, kind1, \
  180. name1, kind2, name2, kind3, name3, kind4, name4, kind5, name5, kind6, \
  181. name6, kind7, name7, kind8, name8, kind9, name9) name0, name1, name2, \
  182. name3, name4, name5, name6, name7, name8, name9
  183. // Declares the types of value parameters.
  184. #define GMOCK_INTERNAL_DECL_TYPE_AND_0_VALUE_PARAMS()
  185. #define GMOCK_INTERNAL_DECL_TYPE_AND_1_VALUE_PARAMS(p0) , typename p0##_type
  186. #define GMOCK_INTERNAL_DECL_TYPE_AND_2_VALUE_PARAMS(p0, p1) , \
  187. typename p0##_type, typename p1##_type
  188. #define GMOCK_INTERNAL_DECL_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , \
  189. typename p0##_type, typename p1##_type, typename p2##_type
  190. #define GMOCK_INTERNAL_DECL_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
  191. typename p0##_type, typename p1##_type, typename p2##_type, \
  192. typename p3##_type
  193. #define GMOCK_INTERNAL_DECL_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
  194. typename p0##_type, typename p1##_type, typename p2##_type, \
  195. typename p3##_type, typename p4##_type
  196. #define GMOCK_INTERNAL_DECL_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
  197. typename p0##_type, typename p1##_type, typename p2##_type, \
  198. typename p3##_type, typename p4##_type, typename p5##_type
  199. #define GMOCK_INTERNAL_DECL_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
  200. p6) , typename p0##_type, typename p1##_type, typename p2##_type, \
  201. typename p3##_type, typename p4##_type, typename p5##_type, \
  202. typename p6##_type
  203. #define GMOCK_INTERNAL_DECL_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
  204. p6, p7) , typename p0##_type, typename p1##_type, typename p2##_type, \
  205. typename p3##_type, typename p4##_type, typename p5##_type, \
  206. typename p6##_type, typename p7##_type
  207. #define GMOCK_INTERNAL_DECL_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
  208. p6, p7, p8) , typename p0##_type, typename p1##_type, typename p2##_type, \
  209. typename p3##_type, typename p4##_type, typename p5##_type, \
  210. typename p6##_type, typename p7##_type, typename p8##_type
  211. #define GMOCK_INTERNAL_DECL_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
  212. p6, p7, p8, p9) , typename p0##_type, typename p1##_type, \
  213. typename p2##_type, typename p3##_type, typename p4##_type, \
  214. typename p5##_type, typename p6##_type, typename p7##_type, \
  215. typename p8##_type, typename p9##_type
  216. // Initializes the value parameters.
  217. #define GMOCK_INTERNAL_INIT_AND_0_VALUE_PARAMS()\
  218. ()
  219. #define GMOCK_INTERNAL_INIT_AND_1_VALUE_PARAMS(p0)\
  220. (p0##_type gmock_p0) : p0(::std::move(gmock_p0))
  221. #define GMOCK_INTERNAL_INIT_AND_2_VALUE_PARAMS(p0, p1)\
  222. (p0##_type gmock_p0, p1##_type gmock_p1) : p0(::std::move(gmock_p0)), \
  223. p1(::std::move(gmock_p1))
  224. #define GMOCK_INTERNAL_INIT_AND_3_VALUE_PARAMS(p0, p1, p2)\
  225. (p0##_type gmock_p0, p1##_type gmock_p1, \
  226. p2##_type gmock_p2) : p0(::std::move(gmock_p0)), \
  227. p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2))
  228. #define GMOCK_INTERNAL_INIT_AND_4_VALUE_PARAMS(p0, p1, p2, p3)\
  229. (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
  230. p3##_type gmock_p3) : p0(::std::move(gmock_p0)), \
  231. p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
  232. p3(::std::move(gmock_p3))
  233. #define GMOCK_INTERNAL_INIT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)\
  234. (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
  235. p3##_type gmock_p3, p4##_type gmock_p4) : p0(::std::move(gmock_p0)), \
  236. p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
  237. p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4))
  238. #define GMOCK_INTERNAL_INIT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)\
  239. (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
  240. p3##_type gmock_p3, p4##_type gmock_p4, \
  241. p5##_type gmock_p5) : p0(::std::move(gmock_p0)), \
  242. p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
  243. p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
  244. p5(::std::move(gmock_p5))
  245. #define GMOCK_INTERNAL_INIT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)\
  246. (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
  247. p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
  248. p6##_type gmock_p6) : p0(::std::move(gmock_p0)), \
  249. p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
  250. p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
  251. p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6))
  252. #define GMOCK_INTERNAL_INIT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)\
  253. (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
  254. p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
  255. p6##_type gmock_p6, p7##_type gmock_p7) : p0(::std::move(gmock_p0)), \
  256. p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
  257. p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
  258. p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
  259. p7(::std::move(gmock_p7))
  260. #define GMOCK_INTERNAL_INIT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
  261. p7, p8)\
  262. (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
  263. p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
  264. p6##_type gmock_p6, p7##_type gmock_p7, \
  265. p8##_type gmock_p8) : p0(::std::move(gmock_p0)), \
  266. p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
  267. p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
  268. p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
  269. p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8))
  270. #define GMOCK_INTERNAL_INIT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
  271. p7, p8, p9)\
  272. (p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
  273. p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
  274. p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
  275. p9##_type gmock_p9) : p0(::std::move(gmock_p0)), \
  276. p1(::std::move(gmock_p1)), p2(::std::move(gmock_p2)), \
  277. p3(::std::move(gmock_p3)), p4(::std::move(gmock_p4)), \
  278. p5(::std::move(gmock_p5)), p6(::std::move(gmock_p6)), \
  279. p7(::std::move(gmock_p7)), p8(::std::move(gmock_p8)), \
  280. p9(::std::move(gmock_p9))
  281. // Declares the fields for storing the value parameters.
  282. #define GMOCK_INTERNAL_DEFN_AND_0_VALUE_PARAMS()
  283. #define GMOCK_INTERNAL_DEFN_AND_1_VALUE_PARAMS(p0) p0##_type p0;
  284. #define GMOCK_INTERNAL_DEFN_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0; \
  285. p1##_type p1;
  286. #define GMOCK_INTERNAL_DEFN_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0; \
  287. p1##_type p1; p2##_type p2;
  288. #define GMOCK_INTERNAL_DEFN_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0; \
  289. p1##_type p1; p2##_type p2; p3##_type p3;
  290. #define GMOCK_INTERNAL_DEFN_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
  291. p4) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4;
  292. #define GMOCK_INTERNAL_DEFN_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
  293. p5) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
  294. p5##_type p5;
  295. #define GMOCK_INTERNAL_DEFN_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
  296. p6) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
  297. p5##_type p5; p6##_type p6;
  298. #define GMOCK_INTERNAL_DEFN_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
  299. p7) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; p4##_type p4; \
  300. p5##_type p5; p6##_type p6; p7##_type p7;
  301. #define GMOCK_INTERNAL_DEFN_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
  302. p7, p8) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
  303. p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8;
  304. #define GMOCK_INTERNAL_DEFN_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
  305. p7, p8, p9) p0##_type p0; p1##_type p1; p2##_type p2; p3##_type p3; \
  306. p4##_type p4; p5##_type p5; p6##_type p6; p7##_type p7; p8##_type p8; \
  307. p9##_type p9;
  308. // Lists the value parameters.
  309. #define GMOCK_INTERNAL_LIST_AND_0_VALUE_PARAMS()
  310. #define GMOCK_INTERNAL_LIST_AND_1_VALUE_PARAMS(p0) p0
  311. #define GMOCK_INTERNAL_LIST_AND_2_VALUE_PARAMS(p0, p1) p0, p1
  312. #define GMOCK_INTERNAL_LIST_AND_3_VALUE_PARAMS(p0, p1, p2) p0, p1, p2
  313. #define GMOCK_INTERNAL_LIST_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0, p1, p2, p3
  314. #define GMOCK_INTERNAL_LIST_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) p0, p1, \
  315. p2, p3, p4
  316. #define GMOCK_INTERNAL_LIST_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) p0, \
  317. p1, p2, p3, p4, p5
  318. #define GMOCK_INTERNAL_LIST_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
  319. p6) p0, p1, p2, p3, p4, p5, p6
  320. #define GMOCK_INTERNAL_LIST_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
  321. p7) p0, p1, p2, p3, p4, p5, p6, p7
  322. #define GMOCK_INTERNAL_LIST_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
  323. p7, p8) p0, p1, p2, p3, p4, p5, p6, p7, p8
  324. #define GMOCK_INTERNAL_LIST_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
  325. p7, p8, p9) p0, p1, p2, p3, p4, p5, p6, p7, p8, p9
  326. // Lists the value parameter types.
  327. #define GMOCK_INTERNAL_LIST_TYPE_AND_0_VALUE_PARAMS()
  328. #define GMOCK_INTERNAL_LIST_TYPE_AND_1_VALUE_PARAMS(p0) , p0##_type
  329. #define GMOCK_INTERNAL_LIST_TYPE_AND_2_VALUE_PARAMS(p0, p1) , p0##_type, \
  330. p1##_type
  331. #define GMOCK_INTERNAL_LIST_TYPE_AND_3_VALUE_PARAMS(p0, p1, p2) , p0##_type, \
  332. p1##_type, p2##_type
  333. #define GMOCK_INTERNAL_LIST_TYPE_AND_4_VALUE_PARAMS(p0, p1, p2, p3) , \
  334. p0##_type, p1##_type, p2##_type, p3##_type
  335. #define GMOCK_INTERNAL_LIST_TYPE_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) , \
  336. p0##_type, p1##_type, p2##_type, p3##_type, p4##_type
  337. #define GMOCK_INTERNAL_LIST_TYPE_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) , \
  338. p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type
  339. #define GMOCK_INTERNAL_LIST_TYPE_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
  340. p6) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, p5##_type, \
  341. p6##_type
  342. #define GMOCK_INTERNAL_LIST_TYPE_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
  343. p6, p7) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
  344. p5##_type, p6##_type, p7##_type
  345. #define GMOCK_INTERNAL_LIST_TYPE_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
  346. p6, p7, p8) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
  347. p5##_type, p6##_type, p7##_type, p8##_type
  348. #define GMOCK_INTERNAL_LIST_TYPE_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
  349. p6, p7, p8, p9) , p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
  350. p5##_type, p6##_type, p7##_type, p8##_type, p9##_type
  351. // Declares the value parameters.
  352. #define GMOCK_INTERNAL_DECL_AND_0_VALUE_PARAMS()
  353. #define GMOCK_INTERNAL_DECL_AND_1_VALUE_PARAMS(p0) p0##_type p0
  354. #define GMOCK_INTERNAL_DECL_AND_2_VALUE_PARAMS(p0, p1) p0##_type p0, \
  355. p1##_type p1
  356. #define GMOCK_INTERNAL_DECL_AND_3_VALUE_PARAMS(p0, p1, p2) p0##_type p0, \
  357. p1##_type p1, p2##_type p2
  358. #define GMOCK_INTERNAL_DECL_AND_4_VALUE_PARAMS(p0, p1, p2, p3) p0##_type p0, \
  359. p1##_type p1, p2##_type p2, p3##_type p3
  360. #define GMOCK_INTERNAL_DECL_AND_5_VALUE_PARAMS(p0, p1, p2, p3, \
  361. p4) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4
  362. #define GMOCK_INTERNAL_DECL_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, \
  363. p5) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
  364. p5##_type p5
  365. #define GMOCK_INTERNAL_DECL_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, \
  366. p6) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
  367. p5##_type p5, p6##_type p6
  368. #define GMOCK_INTERNAL_DECL_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
  369. p7) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, \
  370. p5##_type p5, p6##_type p6, p7##_type p7
  371. #define GMOCK_INTERNAL_DECL_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
  372. p7, p8) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
  373. p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8
  374. #define GMOCK_INTERNAL_DECL_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
  375. p7, p8, p9) p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
  376. p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
  377. p9##_type p9
  378. // The suffix of the class template implementing the action template.
  379. #define GMOCK_INTERNAL_COUNT_AND_0_VALUE_PARAMS()
  380. #define GMOCK_INTERNAL_COUNT_AND_1_VALUE_PARAMS(p0) P
  381. #define GMOCK_INTERNAL_COUNT_AND_2_VALUE_PARAMS(p0, p1) P2
  382. #define GMOCK_INTERNAL_COUNT_AND_3_VALUE_PARAMS(p0, p1, p2) P3
  383. #define GMOCK_INTERNAL_COUNT_AND_4_VALUE_PARAMS(p0, p1, p2, p3) P4
  384. #define GMOCK_INTERNAL_COUNT_AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4) P5
  385. #define GMOCK_INTERNAL_COUNT_AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5) P6
  386. #define GMOCK_INTERNAL_COUNT_AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6) P7
  387. #define GMOCK_INTERNAL_COUNT_AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
  388. p7) P8
  389. #define GMOCK_INTERNAL_COUNT_AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
  390. p7, p8) P9
  391. #define GMOCK_INTERNAL_COUNT_AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, \
  392. p7, p8, p9) P10
  393. // The name of the class template implementing the action template.
  394. #define GMOCK_ACTION_CLASS_(name, value_params)\
  395. GTEST_CONCAT_TOKEN_(name##Action, GMOCK_INTERNAL_COUNT_##value_params)
  396. #define ACTION_TEMPLATE(name, template_params, value_params)\
  397. template <GMOCK_INTERNAL_DECL_##template_params\
  398. GMOCK_INTERNAL_DECL_TYPE_##value_params>\
  399. class GMOCK_ACTION_CLASS_(name, value_params) {\
  400. public:\
  401. explicit GMOCK_ACTION_CLASS_(name, value_params)\
  402. GMOCK_INTERNAL_INIT_##value_params {}\
  403. template <typename F>\
  404. class gmock_Impl : public ::testing::ActionInterface<F> {\
  405. public:\
  406. typedef F function_type;\
  407. typedef typename ::testing::internal::Function<F>::Result return_type;\
  408. typedef typename ::testing::internal::Function<F>::ArgumentTuple\
  409. args_type;\
  410. explicit gmock_Impl GMOCK_INTERNAL_INIT_##value_params {}\
  411. return_type Perform(const args_type& args) override {\
  412. return ::testing::internal::ActionHelper<return_type, gmock_Impl>::\
  413. Perform(this, args);\
  414. }\
  415. template <GMOCK_ACTION_TEMPLATE_ARGS_NAMES_>\
  416. return_type gmock_PerformImpl(GMOCK_ACTION_ARG_TYPES_AND_NAMES_) const;\
  417. GMOCK_INTERNAL_DEFN_##value_params\
  418. };\
  419. template <typename F> operator ::testing::Action<F>() const {\
  420. return ::testing::Action<F>(\
  421. new gmock_Impl<F>(GMOCK_INTERNAL_LIST_##value_params));\
  422. }\
  423. GMOCK_INTERNAL_DEFN_##value_params\
  424. };\
  425. template <GMOCK_INTERNAL_DECL_##template_params\
  426. GMOCK_INTERNAL_DECL_TYPE_##value_params>\
  427. inline GMOCK_ACTION_CLASS_(name, value_params)<\
  428. GMOCK_INTERNAL_LIST_##template_params\
  429. GMOCK_INTERNAL_LIST_TYPE_##value_params> name(\
  430. GMOCK_INTERNAL_DECL_##value_params) {\
  431. return GMOCK_ACTION_CLASS_(name, value_params)<\
  432. GMOCK_INTERNAL_LIST_##template_params\
  433. GMOCK_INTERNAL_LIST_TYPE_##value_params>(\
  434. GMOCK_INTERNAL_LIST_##value_params);\
  435. }\
  436. template <GMOCK_INTERNAL_DECL_##template_params\
  437. GMOCK_INTERNAL_DECL_TYPE_##value_params>\
  438. template <typename F>\
  439. template <GMOCK_ACTION_TEMPLATE_ARGS_NAMES_>\
  440. typename ::testing::internal::Function<F>::Result\
  441. GMOCK_ACTION_CLASS_(name, value_params)<\
  442. GMOCK_INTERNAL_LIST_##template_params\
  443. GMOCK_INTERNAL_LIST_TYPE_##value_params>::gmock_Impl<F>::\
  444. gmock_PerformImpl(\
  445. GMOCK_ACTION_ARG_TYPES_AND_NAMES_UNUSED_) const
  446. namespace testing {
  447. // The ACTION*() macros trigger warning C4100 (unreferenced formal
  448. // parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
  449. // the macro definition, as the warnings are generated when the macro
  450. // is expanded and macro expansion cannot contain #pragma. Therefore
  451. // we suppress them here.
  452. #ifdef _MSC_VER
  453. # pragma warning(push)
  454. # pragma warning(disable:4100)
  455. #endif
  456. // Various overloads for InvokeArgument<N>().
  457. //
  458. // The InvokeArgument<N>(a1, a2, ..., a_k) action invokes the N-th
  459. // (0-based) argument, which must be a k-ary callable, of the mock
  460. // function, with arguments a1, a2, ..., a_k.
  461. //
  462. // Notes:
  463. //
  464. // 1. The arguments are passed by value by default. If you need to
  465. // pass an argument by reference, wrap it inside ByRef(). For
  466. // example,
  467. //
  468. // InvokeArgument<1>(5, string("Hello"), ByRef(foo))
  469. //
  470. // passes 5 and string("Hello") by value, and passes foo by
  471. // reference.
  472. //
  473. // 2. If the callable takes an argument by reference but ByRef() is
  474. // not used, it will receive the reference to a copy of the value,
  475. // instead of the original value. For example, when the 0-th
  476. // argument of the mock function takes a const string&, the action
  477. //
  478. // InvokeArgument<0>(string("Hello"))
  479. //
  480. // makes a copy of the temporary string("Hello") object and passes a
  481. // reference of the copy, instead of the original temporary object,
  482. // to the callable. This makes it easy for a user to define an
  483. // InvokeArgument action from temporary values and have it performed
  484. // later.
  485. ACTION_TEMPLATE(InvokeArgument,
  486. HAS_1_TEMPLATE_PARAMS(int, k),
  487. AND_0_VALUE_PARAMS()) {
  488. using internal::invoke_argument::InvokeArgumentAdl;
  489. return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
  490. ::std::get<k>(args));
  491. }
  492. ACTION_TEMPLATE(InvokeArgument,
  493. HAS_1_TEMPLATE_PARAMS(int, k),
  494. AND_1_VALUE_PARAMS(p0)) {
  495. using internal::invoke_argument::InvokeArgumentAdl;
  496. return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
  497. ::std::get<k>(args), p0);
  498. }
  499. ACTION_TEMPLATE(InvokeArgument,
  500. HAS_1_TEMPLATE_PARAMS(int, k),
  501. AND_2_VALUE_PARAMS(p0, p1)) {
  502. using internal::invoke_argument::InvokeArgumentAdl;
  503. return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
  504. ::std::get<k>(args), p0, p1);
  505. }
  506. ACTION_TEMPLATE(InvokeArgument,
  507. HAS_1_TEMPLATE_PARAMS(int, k),
  508. AND_3_VALUE_PARAMS(p0, p1, p2)) {
  509. using internal::invoke_argument::InvokeArgumentAdl;
  510. return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
  511. ::std::get<k>(args), p0, p1, p2);
  512. }
  513. ACTION_TEMPLATE(InvokeArgument,
  514. HAS_1_TEMPLATE_PARAMS(int, k),
  515. AND_4_VALUE_PARAMS(p0, p1, p2, p3)) {
  516. using internal::invoke_argument::InvokeArgumentAdl;
  517. return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
  518. ::std::get<k>(args), p0, p1, p2, p3);
  519. }
  520. ACTION_TEMPLATE(InvokeArgument,
  521. HAS_1_TEMPLATE_PARAMS(int, k),
  522. AND_5_VALUE_PARAMS(p0, p1, p2, p3, p4)) {
  523. using internal::invoke_argument::InvokeArgumentAdl;
  524. return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
  525. ::std::get<k>(args), p0, p1, p2, p3, p4);
  526. }
  527. ACTION_TEMPLATE(InvokeArgument,
  528. HAS_1_TEMPLATE_PARAMS(int, k),
  529. AND_6_VALUE_PARAMS(p0, p1, p2, p3, p4, p5)) {
  530. using internal::invoke_argument::InvokeArgumentAdl;
  531. return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
  532. ::std::get<k>(args), p0, p1, p2, p3, p4, p5);
  533. }
  534. ACTION_TEMPLATE(InvokeArgument,
  535. HAS_1_TEMPLATE_PARAMS(int, k),
  536. AND_7_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6)) {
  537. using internal::invoke_argument::InvokeArgumentAdl;
  538. return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
  539. ::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6);
  540. }
  541. ACTION_TEMPLATE(InvokeArgument,
  542. HAS_1_TEMPLATE_PARAMS(int, k),
  543. AND_8_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7)) {
  544. using internal::invoke_argument::InvokeArgumentAdl;
  545. return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
  546. ::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7);
  547. }
  548. ACTION_TEMPLATE(InvokeArgument,
  549. HAS_1_TEMPLATE_PARAMS(int, k),
  550. AND_9_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8)) {
  551. using internal::invoke_argument::InvokeArgumentAdl;
  552. return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
  553. ::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7,
  554. p8);
  555. }
  556. ACTION_TEMPLATE(InvokeArgument,
  557. HAS_1_TEMPLATE_PARAMS(int, k),
  558. AND_10_VALUE_PARAMS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)) {
  559. using internal::invoke_argument::InvokeArgumentAdl;
  560. return InvokeArgumentAdl(internal::invoke_argument::AdlTag(),
  561. ::std::get<k>(args), p0, p1, p2, p3, p4, p5, p6, p7,
  562. p8, p9);
  563. }
  564. #ifdef _MSC_VER
  565. # pragma warning(pop)
  566. #endif
  567. } // namespace testing
  568. // Include any custom callback actions added by the local installation.
  569. // We must include this header at the end to make sure it can use the
  570. // declarations from this file.
  571. #include "gmock/internal/custom/gmock-generated-actions.h"
  572. #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_ACTIONS_H_