gmock-function-mocker.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. // Copyright 2007, Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. // Google Mock - a framework for writing C++ mock classes.
  30. //
  31. // This file implements MOCK_METHOD.
  32. // IWYU pragma: private, include "gmock/gmock.h"
  33. // IWYU pragma: friend gmock/.*
  34. #ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_FUNCTION_MOCKER_H_
  35. #define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_FUNCTION_MOCKER_H_
  36. #include <type_traits> // IWYU pragma: keep
  37. #include <utility> // IWYU pragma: keep
  38. #include "gmock/gmock-spec-builders.h"
  39. #include "gmock/internal/gmock-internal-utils.h"
  40. #include "gmock/internal/gmock-pp.h"
  41. namespace testing {
  42. namespace internal {
  43. template <typename T>
  44. using identity_t = T;
  45. template <typename Pattern>
  46. struct ThisRefAdjuster {
  47. template <typename T>
  48. using AdjustT = typename std::conditional<
  49. std::is_const<typename std::remove_reference<Pattern>::type>::value,
  50. typename std::conditional<std::is_lvalue_reference<Pattern>::value,
  51. const T&, const T&&>::type,
  52. typename std::conditional<std::is_lvalue_reference<Pattern>::value, T&,
  53. T&&>::type>::type;
  54. template <typename MockType>
  55. static AdjustT<MockType> Adjust(const MockType& mock) {
  56. return static_cast<AdjustT<MockType>>(const_cast<MockType&>(mock));
  57. }
  58. };
  59. constexpr bool PrefixOf(const char* a, const char* b) {
  60. return *a == 0 || (*a == *b && internal::PrefixOf(a + 1, b + 1));
  61. }
  62. template <int N, int M>
  63. constexpr bool StartsWith(const char (&prefix)[N], const char (&str)[M]) {
  64. return N <= M && internal::PrefixOf(prefix, str);
  65. }
  66. template <int N, int M>
  67. constexpr bool EndsWith(const char (&suffix)[N], const char (&str)[M]) {
  68. return N <= M && internal::PrefixOf(suffix, str + M - N);
  69. }
  70. template <int N, int M>
  71. constexpr bool Equals(const char (&a)[N], const char (&b)[M]) {
  72. return N == M && internal::PrefixOf(a, b);
  73. }
  74. template <int N>
  75. constexpr bool ValidateSpec(const char (&spec)[N]) {
  76. return internal::Equals("const", spec) ||
  77. internal::Equals("override", spec) ||
  78. internal::Equals("final", spec) ||
  79. internal::Equals("noexcept", spec) ||
  80. (internal::StartsWith("noexcept(", spec) &&
  81. internal::EndsWith(")", spec)) ||
  82. internal::Equals("ref(&)", spec) ||
  83. internal::Equals("ref(&&)", spec) ||
  84. (internal::StartsWith("Calltype(", spec) &&
  85. internal::EndsWith(")", spec));
  86. }
  87. } // namespace internal
  88. // The style guide prohibits "using" statements in a namespace scope
  89. // inside a header file. However, the FunctionMocker class template
  90. // is meant to be defined in the ::testing namespace. The following
  91. // line is just a trick for working around a bug in MSVC 8.0, which
  92. // cannot handle it if we define FunctionMocker in ::testing.
  93. using internal::FunctionMocker;
  94. } // namespace testing
  95. #define MOCK_METHOD(...) \
  96. GMOCK_INTERNAL_WARNING_PUSH() \
  97. GMOCK_INTERNAL_WARNING_CLANG(ignored, "-Wunused-member-function") \
  98. GMOCK_PP_VARIADIC_CALL(GMOCK_INTERNAL_MOCK_METHOD_ARG_, __VA_ARGS__) \
  99. GMOCK_INTERNAL_WARNING_POP()
  100. #define GMOCK_INTERNAL_MOCK_METHOD_ARG_1(...) \
  101. GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
  102. #define GMOCK_INTERNAL_MOCK_METHOD_ARG_2(...) \
  103. GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
  104. #define GMOCK_INTERNAL_MOCK_METHOD_ARG_3(_Ret, _MethodName, _Args) \
  105. GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, ())
  106. #define GMOCK_INTERNAL_MOCK_METHOD_ARG_4(_Ret, _MethodName, _Args, _Spec) \
  107. GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Args); \
  108. GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Spec); \
  109. GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \
  110. GMOCK_PP_NARG0 _Args, GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)); \
  111. GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \
  112. GMOCK_INTERNAL_MOCK_METHOD_IMPL( \
  113. GMOCK_PP_NARG0 _Args, _MethodName, GMOCK_INTERNAL_HAS_CONST(_Spec), \
  114. GMOCK_INTERNAL_HAS_OVERRIDE(_Spec), GMOCK_INTERNAL_HAS_FINAL(_Spec), \
  115. GMOCK_INTERNAL_GET_NOEXCEPT_SPEC(_Spec), \
  116. GMOCK_INTERNAL_GET_CALLTYPE_SPEC(_Spec), \
  117. GMOCK_INTERNAL_GET_REF_SPEC(_Spec), \
  118. (GMOCK_INTERNAL_SIGNATURE(_Ret, _Args)))
  119. #define GMOCK_INTERNAL_MOCK_METHOD_ARG_5(...) \
  120. GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
  121. #define GMOCK_INTERNAL_MOCK_METHOD_ARG_6(...) \
  122. GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
  123. #define GMOCK_INTERNAL_MOCK_METHOD_ARG_7(...) \
  124. GMOCK_INTERNAL_WRONG_ARITY(__VA_ARGS__)
  125. #define GMOCK_INTERNAL_WRONG_ARITY(...) \
  126. static_assert( \
  127. false, \
  128. "MOCK_METHOD must be called with 3 or 4 arguments. _Ret, " \
  129. "_MethodName, _Args and optionally _Spec. _Args and _Spec must be " \
  130. "enclosed in parentheses. If _Ret is a type with unprotected commas, " \
  131. "it must also be enclosed in parentheses.")
  132. #define GMOCK_INTERNAL_ASSERT_PARENTHESIS(_Tuple) \
  133. static_assert( \
  134. GMOCK_PP_IS_ENCLOSED_PARENS(_Tuple), \
  135. GMOCK_PP_STRINGIZE(_Tuple) " should be enclosed in parentheses.")
  136. #define GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE(_N, ...) \
  137. static_assert( \
  138. std::is_function<__VA_ARGS__>::value, \
  139. "Signature must be a function type, maybe return type contains " \
  140. "unprotected comma."); \
  141. static_assert( \
  142. ::testing::tuple_size<typename ::testing::internal::Function< \
  143. __VA_ARGS__>::ArgumentTuple>::value == _N, \
  144. "This method does not take " GMOCK_PP_STRINGIZE( \
  145. _N) " arguments. Parenthesize all types with unprotected commas.")
  146. #define GMOCK_INTERNAL_ASSERT_VALID_SPEC(_Spec) \
  147. GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT, ~, _Spec)
  148. #define GMOCK_INTERNAL_MOCK_METHOD_IMPL(_N, _MethodName, _Constness, \
  149. _Override, _Final, _NoexceptSpec, \
  150. _CallType, _RefSpec, _Signature) \
  151. typename ::testing::internal::Function<GMOCK_PP_REMOVE_PARENS( \
  152. _Signature)>::Result \
  153. GMOCK_INTERNAL_EXPAND(_CallType) \
  154. _MethodName(GMOCK_PP_REPEAT(GMOCK_INTERNAL_PARAMETER, _Signature, _N)) \
  155. GMOCK_PP_IF(_Constness, const, ) \
  156. _RefSpec _NoexceptSpec GMOCK_PP_IF(_Override, override, ) \
  157. GMOCK_PP_IF(_Final, final, ) { \
  158. GMOCK_MOCKER_(_N, _Constness, _MethodName) \
  159. .SetOwnerAndName(this, #_MethodName); \
  160. return GMOCK_MOCKER_(_N, _Constness, _MethodName) \
  161. .Invoke(GMOCK_PP_REPEAT(GMOCK_INTERNAL_FORWARD_ARG, _Signature, _N)); \
  162. } \
  163. ::testing::MockSpec<GMOCK_PP_REMOVE_PARENS(_Signature)> gmock_##_MethodName( \
  164. GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_PARAMETER, _Signature, _N)) \
  165. GMOCK_PP_IF(_Constness, const, ) _RefSpec { \
  166. GMOCK_MOCKER_(_N, _Constness, _MethodName).RegisterOwner(this); \
  167. return GMOCK_MOCKER_(_N, _Constness, _MethodName) \
  168. .With(GMOCK_PP_REPEAT(GMOCK_INTERNAL_MATCHER_ARGUMENT, , _N)); \
  169. } \
  170. ::testing::MockSpec<GMOCK_PP_REMOVE_PARENS(_Signature)> gmock_##_MethodName( \
  171. const ::testing::internal::WithoutMatchers&, \
  172. GMOCK_PP_IF(_Constness, const, )::testing::internal::Function< \
  173. GMOCK_PP_REMOVE_PARENS(_Signature)>*) const _RefSpec _NoexceptSpec { \
  174. return ::testing::internal::ThisRefAdjuster<GMOCK_PP_IF( \
  175. _Constness, const, ) int _RefSpec>::Adjust(*this) \
  176. .gmock_##_MethodName(GMOCK_PP_REPEAT( \
  177. GMOCK_INTERNAL_A_MATCHER_ARGUMENT, _Signature, _N)); \
  178. } \
  179. mutable ::testing::FunctionMocker<GMOCK_PP_REMOVE_PARENS(_Signature)> \
  180. GMOCK_MOCKER_(_N, _Constness, _MethodName)
  181. #define GMOCK_INTERNAL_EXPAND(...) __VA_ARGS__
  182. // Valid modifiers.
  183. #define GMOCK_INTERNAL_HAS_CONST(_Tuple) \
  184. GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_CONST, ~, _Tuple))
  185. #define GMOCK_INTERNAL_HAS_OVERRIDE(_Tuple) \
  186. GMOCK_PP_HAS_COMMA( \
  187. GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_OVERRIDE, ~, _Tuple))
  188. #define GMOCK_INTERNAL_HAS_FINAL(_Tuple) \
  189. GMOCK_PP_HAS_COMMA(GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_DETECT_FINAL, ~, _Tuple))
  190. #define GMOCK_INTERNAL_GET_NOEXCEPT_SPEC(_Tuple) \
  191. GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_NOEXCEPT_SPEC_IF_NOEXCEPT, ~, _Tuple)
  192. #define GMOCK_INTERNAL_NOEXCEPT_SPEC_IF_NOEXCEPT(_i, _, _elem) \
  193. GMOCK_PP_IF( \
  194. GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)), \
  195. _elem, )
  196. #define GMOCK_INTERNAL_GET_CALLTYPE_SPEC(_Tuple) \
  197. GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_CALLTYPE_SPEC_IF_CALLTYPE, ~, _Tuple)
  198. #define GMOCK_INTERNAL_CALLTYPE_SPEC_IF_CALLTYPE(_i, _, _elem) \
  199. GMOCK_PP_IF( \
  200. GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CALLTYPE(_i, _, _elem)), \
  201. GMOCK_PP_CAT(GMOCK_INTERNAL_UNPACK_, _elem), )
  202. #define GMOCK_INTERNAL_GET_REF_SPEC(_Tuple) \
  203. GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_REF_SPEC_IF_REF, ~, _Tuple)
  204. #define GMOCK_INTERNAL_REF_SPEC_IF_REF(_i, _, _elem) \
  205. GMOCK_PP_IF(GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)), \
  206. GMOCK_PP_CAT(GMOCK_INTERNAL_UNPACK_, _elem), )
  207. #ifdef GMOCK_INTERNAL_STRICT_SPEC_ASSERT
  208. #define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \
  209. static_assert( \
  210. ::testing::internal::ValidateSpec(GMOCK_PP_STRINGIZE(_elem)), \
  211. "Token \'" GMOCK_PP_STRINGIZE( \
  212. _elem) "\' cannot be recognized as a valid specification " \
  213. "modifier. Is a ',' missing?");
  214. #else
  215. #define GMOCK_INTERNAL_ASSERT_VALID_SPEC_ELEMENT(_i, _, _elem) \
  216. static_assert( \
  217. (GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem)) + \
  218. GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem)) + \
  219. GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem)) + \
  220. GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem)) + \
  221. GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_REF(_i, _, _elem)) + \
  222. GMOCK_PP_HAS_COMMA(GMOCK_INTERNAL_DETECT_CALLTYPE(_i, _, _elem))) == 1, \
  223. GMOCK_PP_STRINGIZE( \
  224. _elem) " cannot be recognized as a valid specification modifier.");
  225. #endif // GMOCK_INTERNAL_STRICT_SPEC_ASSERT
  226. // Modifiers implementation.
  227. #define GMOCK_INTERNAL_DETECT_CONST(_i, _, _elem) \
  228. GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_CONST_I_, _elem)
  229. #define GMOCK_INTERNAL_DETECT_CONST_I_const ,
  230. #define GMOCK_INTERNAL_DETECT_OVERRIDE(_i, _, _elem) \
  231. GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_OVERRIDE_I_, _elem)
  232. #define GMOCK_INTERNAL_DETECT_OVERRIDE_I_override ,
  233. #define GMOCK_INTERNAL_DETECT_FINAL(_i, _, _elem) \
  234. GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_FINAL_I_, _elem)
  235. #define GMOCK_INTERNAL_DETECT_FINAL_I_final ,
  236. #define GMOCK_INTERNAL_DETECT_NOEXCEPT(_i, _, _elem) \
  237. GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_NOEXCEPT_I_, _elem)
  238. #define GMOCK_INTERNAL_DETECT_NOEXCEPT_I_noexcept ,
  239. #define GMOCK_INTERNAL_DETECT_REF(_i, _, _elem) \
  240. GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_REF_I_, _elem)
  241. #define GMOCK_INTERNAL_DETECT_REF_I_ref ,
  242. #define GMOCK_INTERNAL_UNPACK_ref(x) x
  243. #define GMOCK_INTERNAL_DETECT_CALLTYPE(_i, _, _elem) \
  244. GMOCK_PP_CAT(GMOCK_INTERNAL_DETECT_CALLTYPE_I_, _elem)
  245. #define GMOCK_INTERNAL_DETECT_CALLTYPE_I_Calltype ,
  246. #define GMOCK_INTERNAL_UNPACK_Calltype(...) __VA_ARGS__
  247. // Note: The use of `identity_t` here allows _Ret to represent return types that
  248. // would normally need to be specified in a different way. For example, a method
  249. // returning a function pointer must be written as
  250. //
  251. // fn_ptr_return_t (*method(method_args_t...))(fn_ptr_args_t...)
  252. //
  253. // But we only support placing the return type at the beginning. To handle this,
  254. // we wrap all calls in identity_t, so that a declaration will be expanded to
  255. //
  256. // identity_t<fn_ptr_return_t (*)(fn_ptr_args_t...)> method(method_args_t...)
  257. //
  258. // This allows us to work around the syntactic oddities of function/method
  259. // types.
  260. #define GMOCK_INTERNAL_SIGNATURE(_Ret, _Args) \
  261. ::testing::internal::identity_t<GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_Ret), \
  262. GMOCK_PP_REMOVE_PARENS, \
  263. GMOCK_PP_IDENTITY)(_Ret)>( \
  264. GMOCK_PP_FOR_EACH(GMOCK_INTERNAL_GET_TYPE, _, _Args))
  265. #define GMOCK_INTERNAL_GET_TYPE(_i, _, _elem) \
  266. GMOCK_PP_COMMA_IF(_i) \
  267. GMOCK_PP_IF(GMOCK_PP_IS_BEGIN_PARENS(_elem), GMOCK_PP_REMOVE_PARENS, \
  268. GMOCK_PP_IDENTITY) \
  269. (_elem)
  270. #define GMOCK_INTERNAL_PARAMETER(_i, _Signature, _) \
  271. GMOCK_PP_COMMA_IF(_i) \
  272. GMOCK_INTERNAL_ARG_O(_i, GMOCK_PP_REMOVE_PARENS(_Signature)) \
  273. gmock_a##_i
  274. #define GMOCK_INTERNAL_FORWARD_ARG(_i, _Signature, _) \
  275. GMOCK_PP_COMMA_IF(_i) \
  276. ::std::forward<GMOCK_INTERNAL_ARG_O( \
  277. _i, GMOCK_PP_REMOVE_PARENS(_Signature))>(gmock_a##_i)
  278. #define GMOCK_INTERNAL_MATCHER_PARAMETER(_i, _Signature, _) \
  279. GMOCK_PP_COMMA_IF(_i) \
  280. GMOCK_INTERNAL_MATCHER_O(_i, GMOCK_PP_REMOVE_PARENS(_Signature)) \
  281. gmock_a##_i
  282. #define GMOCK_INTERNAL_MATCHER_ARGUMENT(_i, _1, _2) \
  283. GMOCK_PP_COMMA_IF(_i) \
  284. gmock_a##_i
  285. #define GMOCK_INTERNAL_A_MATCHER_ARGUMENT(_i, _Signature, _) \
  286. GMOCK_PP_COMMA_IF(_i) \
  287. ::testing::A<GMOCK_INTERNAL_ARG_O(_i, GMOCK_PP_REMOVE_PARENS(_Signature))>()
  288. #define GMOCK_INTERNAL_ARG_O(_i, ...) \
  289. typename ::testing::internal::Function<__VA_ARGS__>::template Arg<_i>::type
  290. #define GMOCK_INTERNAL_MATCHER_O(_i, ...) \
  291. const ::testing::Matcher<typename ::testing::internal::Function< \
  292. __VA_ARGS__>::template Arg<_i>::type>&
  293. #define MOCK_METHOD0(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 0, __VA_ARGS__)
  294. #define MOCK_METHOD1(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 1, __VA_ARGS__)
  295. #define MOCK_METHOD2(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 2, __VA_ARGS__)
  296. #define MOCK_METHOD3(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 3, __VA_ARGS__)
  297. #define MOCK_METHOD4(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 4, __VA_ARGS__)
  298. #define MOCK_METHOD5(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 5, __VA_ARGS__)
  299. #define MOCK_METHOD6(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 6, __VA_ARGS__)
  300. #define MOCK_METHOD7(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 7, __VA_ARGS__)
  301. #define MOCK_METHOD8(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 8, __VA_ARGS__)
  302. #define MOCK_METHOD9(m, ...) GMOCK_INTERNAL_MOCK_METHODN(, , m, 9, __VA_ARGS__)
  303. #define MOCK_METHOD10(m, ...) \
  304. GMOCK_INTERNAL_MOCK_METHODN(, , m, 10, __VA_ARGS__)
  305. #define MOCK_CONST_METHOD0(m, ...) \
  306. GMOCK_INTERNAL_MOCK_METHODN(const, , m, 0, __VA_ARGS__)
  307. #define MOCK_CONST_METHOD1(m, ...) \
  308. GMOCK_INTERNAL_MOCK_METHODN(const, , m, 1, __VA_ARGS__)
  309. #define MOCK_CONST_METHOD2(m, ...) \
  310. GMOCK_INTERNAL_MOCK_METHODN(const, , m, 2, __VA_ARGS__)
  311. #define MOCK_CONST_METHOD3(m, ...) \
  312. GMOCK_INTERNAL_MOCK_METHODN(const, , m, 3, __VA_ARGS__)
  313. #define MOCK_CONST_METHOD4(m, ...) \
  314. GMOCK_INTERNAL_MOCK_METHODN(const, , m, 4, __VA_ARGS__)
  315. #define MOCK_CONST_METHOD5(m, ...) \
  316. GMOCK_INTERNAL_MOCK_METHODN(const, , m, 5, __VA_ARGS__)
  317. #define MOCK_CONST_METHOD6(m, ...) \
  318. GMOCK_INTERNAL_MOCK_METHODN(const, , m, 6, __VA_ARGS__)
  319. #define MOCK_CONST_METHOD7(m, ...) \
  320. GMOCK_INTERNAL_MOCK_METHODN(const, , m, 7, __VA_ARGS__)
  321. #define MOCK_CONST_METHOD8(m, ...) \
  322. GMOCK_INTERNAL_MOCK_METHODN(const, , m, 8, __VA_ARGS__)
  323. #define MOCK_CONST_METHOD9(m, ...) \
  324. GMOCK_INTERNAL_MOCK_METHODN(const, , m, 9, __VA_ARGS__)
  325. #define MOCK_CONST_METHOD10(m, ...) \
  326. GMOCK_INTERNAL_MOCK_METHODN(const, , m, 10, __VA_ARGS__)
  327. #define MOCK_METHOD0_T(m, ...) MOCK_METHOD0(m, __VA_ARGS__)
  328. #define MOCK_METHOD1_T(m, ...) MOCK_METHOD1(m, __VA_ARGS__)
  329. #define MOCK_METHOD2_T(m, ...) MOCK_METHOD2(m, __VA_ARGS__)
  330. #define MOCK_METHOD3_T(m, ...) MOCK_METHOD3(m, __VA_ARGS__)
  331. #define MOCK_METHOD4_T(m, ...) MOCK_METHOD4(m, __VA_ARGS__)
  332. #define MOCK_METHOD5_T(m, ...) MOCK_METHOD5(m, __VA_ARGS__)
  333. #define MOCK_METHOD6_T(m, ...) MOCK_METHOD6(m, __VA_ARGS__)
  334. #define MOCK_METHOD7_T(m, ...) MOCK_METHOD7(m, __VA_ARGS__)
  335. #define MOCK_METHOD8_T(m, ...) MOCK_METHOD8(m, __VA_ARGS__)
  336. #define MOCK_METHOD9_T(m, ...) MOCK_METHOD9(m, __VA_ARGS__)
  337. #define MOCK_METHOD10_T(m, ...) MOCK_METHOD10(m, __VA_ARGS__)
  338. #define MOCK_CONST_METHOD0_T(m, ...) MOCK_CONST_METHOD0(m, __VA_ARGS__)
  339. #define MOCK_CONST_METHOD1_T(m, ...) MOCK_CONST_METHOD1(m, __VA_ARGS__)
  340. #define MOCK_CONST_METHOD2_T(m, ...) MOCK_CONST_METHOD2(m, __VA_ARGS__)
  341. #define MOCK_CONST_METHOD3_T(m, ...) MOCK_CONST_METHOD3(m, __VA_ARGS__)
  342. #define MOCK_CONST_METHOD4_T(m, ...) MOCK_CONST_METHOD4(m, __VA_ARGS__)
  343. #define MOCK_CONST_METHOD5_T(m, ...) MOCK_CONST_METHOD5(m, __VA_ARGS__)
  344. #define MOCK_CONST_METHOD6_T(m, ...) MOCK_CONST_METHOD6(m, __VA_ARGS__)
  345. #define MOCK_CONST_METHOD7_T(m, ...) MOCK_CONST_METHOD7(m, __VA_ARGS__)
  346. #define MOCK_CONST_METHOD8_T(m, ...) MOCK_CONST_METHOD8(m, __VA_ARGS__)
  347. #define MOCK_CONST_METHOD9_T(m, ...) MOCK_CONST_METHOD9(m, __VA_ARGS__)
  348. #define MOCK_CONST_METHOD10_T(m, ...) MOCK_CONST_METHOD10(m, __VA_ARGS__)
  349. #define MOCK_METHOD0_WITH_CALLTYPE(ct, m, ...) \
  350. GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 0, __VA_ARGS__)
  351. #define MOCK_METHOD1_WITH_CALLTYPE(ct, m, ...) \
  352. GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 1, __VA_ARGS__)
  353. #define MOCK_METHOD2_WITH_CALLTYPE(ct, m, ...) \
  354. GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 2, __VA_ARGS__)
  355. #define MOCK_METHOD3_WITH_CALLTYPE(ct, m, ...) \
  356. GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 3, __VA_ARGS__)
  357. #define MOCK_METHOD4_WITH_CALLTYPE(ct, m, ...) \
  358. GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 4, __VA_ARGS__)
  359. #define MOCK_METHOD5_WITH_CALLTYPE(ct, m, ...) \
  360. GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 5, __VA_ARGS__)
  361. #define MOCK_METHOD6_WITH_CALLTYPE(ct, m, ...) \
  362. GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 6, __VA_ARGS__)
  363. #define MOCK_METHOD7_WITH_CALLTYPE(ct, m, ...) \
  364. GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 7, __VA_ARGS__)
  365. #define MOCK_METHOD8_WITH_CALLTYPE(ct, m, ...) \
  366. GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 8, __VA_ARGS__)
  367. #define MOCK_METHOD9_WITH_CALLTYPE(ct, m, ...) \
  368. GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 9, __VA_ARGS__)
  369. #define MOCK_METHOD10_WITH_CALLTYPE(ct, m, ...) \
  370. GMOCK_INTERNAL_MOCK_METHODN(, ct, m, 10, __VA_ARGS__)
  371. #define MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, ...) \
  372. GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 0, __VA_ARGS__)
  373. #define MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, ...) \
  374. GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 1, __VA_ARGS__)
  375. #define MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, ...) \
  376. GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 2, __VA_ARGS__)
  377. #define MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, ...) \
  378. GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 3, __VA_ARGS__)
  379. #define MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, ...) \
  380. GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 4, __VA_ARGS__)
  381. #define MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, ...) \
  382. GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 5, __VA_ARGS__)
  383. #define MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, ...) \
  384. GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 6, __VA_ARGS__)
  385. #define MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, ...) \
  386. GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 7, __VA_ARGS__)
  387. #define MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, ...) \
  388. GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 8, __VA_ARGS__)
  389. #define MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, ...) \
  390. GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 9, __VA_ARGS__)
  391. #define MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, ...) \
  392. GMOCK_INTERNAL_MOCK_METHODN(const, ct, m, 10, __VA_ARGS__)
  393. #define MOCK_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \
  394. MOCK_METHOD0_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  395. #define MOCK_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \
  396. MOCK_METHOD1_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  397. #define MOCK_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \
  398. MOCK_METHOD2_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  399. #define MOCK_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \
  400. MOCK_METHOD3_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  401. #define MOCK_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \
  402. MOCK_METHOD4_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  403. #define MOCK_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \
  404. MOCK_METHOD5_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  405. #define MOCK_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \
  406. MOCK_METHOD6_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  407. #define MOCK_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \
  408. MOCK_METHOD7_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  409. #define MOCK_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \
  410. MOCK_METHOD8_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  411. #define MOCK_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \
  412. MOCK_METHOD9_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  413. #define MOCK_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \
  414. MOCK_METHOD10_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  415. #define MOCK_CONST_METHOD0_T_WITH_CALLTYPE(ct, m, ...) \
  416. MOCK_CONST_METHOD0_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  417. #define MOCK_CONST_METHOD1_T_WITH_CALLTYPE(ct, m, ...) \
  418. MOCK_CONST_METHOD1_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  419. #define MOCK_CONST_METHOD2_T_WITH_CALLTYPE(ct, m, ...) \
  420. MOCK_CONST_METHOD2_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  421. #define MOCK_CONST_METHOD3_T_WITH_CALLTYPE(ct, m, ...) \
  422. MOCK_CONST_METHOD3_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  423. #define MOCK_CONST_METHOD4_T_WITH_CALLTYPE(ct, m, ...) \
  424. MOCK_CONST_METHOD4_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  425. #define MOCK_CONST_METHOD5_T_WITH_CALLTYPE(ct, m, ...) \
  426. MOCK_CONST_METHOD5_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  427. #define MOCK_CONST_METHOD6_T_WITH_CALLTYPE(ct, m, ...) \
  428. MOCK_CONST_METHOD6_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  429. #define MOCK_CONST_METHOD7_T_WITH_CALLTYPE(ct, m, ...) \
  430. MOCK_CONST_METHOD7_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  431. #define MOCK_CONST_METHOD8_T_WITH_CALLTYPE(ct, m, ...) \
  432. MOCK_CONST_METHOD8_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  433. #define MOCK_CONST_METHOD9_T_WITH_CALLTYPE(ct, m, ...) \
  434. MOCK_CONST_METHOD9_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  435. #define MOCK_CONST_METHOD10_T_WITH_CALLTYPE(ct, m, ...) \
  436. MOCK_CONST_METHOD10_WITH_CALLTYPE(ct, m, __VA_ARGS__)
  437. #define GMOCK_INTERNAL_MOCK_METHODN(constness, ct, Method, args_num, ...) \
  438. GMOCK_INTERNAL_ASSERT_VALID_SIGNATURE( \
  439. args_num, ::testing::internal::identity_t<__VA_ARGS__>); \
  440. GMOCK_INTERNAL_MOCK_METHOD_IMPL( \
  441. args_num, Method, GMOCK_PP_NARG0(constness), 0, 0, , ct, , \
  442. (::testing::internal::identity_t<__VA_ARGS__>))
  443. #define GMOCK_MOCKER_(arity, constness, Method) \
  444. GTEST_CONCAT_TOKEN_(gmock##constness##arity##_##Method##_, __LINE__)
  445. #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_FUNCTION_MOCKER_H_