gmock-generated-matchers.h.pump 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. $$ -*- mode: c++; -*-
  2. $$ This is a Pump source file. Please use Pump to convert
  3. $$ it to gmock-generated-matchers.h.
  4. $$
  5. $var n = 10 $$ The maximum arity we support.
  6. $$ }} This line fixes auto-indentation of the following code in Emacs.
  7. // Copyright 2008, Google Inc.
  8. // All rights reserved.
  9. //
  10. // Redistribution and use in source and binary forms, with or without
  11. // modification, are permitted provided that the following conditions are
  12. // met:
  13. //
  14. // * Redistributions of source code must retain the above copyright
  15. // notice, this list of conditions and the following disclaimer.
  16. // * Redistributions in binary form must reproduce the above
  17. // copyright notice, this list of conditions and the following disclaimer
  18. // in the documentation and/or other materials provided with the
  19. // distribution.
  20. // * Neither the name of Google Inc. nor the names of its
  21. // contributors may be used to endorse or promote products derived from
  22. // this software without specific prior written permission.
  23. //
  24. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. // Google Mock - a framework for writing C++ mock classes.
  36. //
  37. // This file implements some commonly used variadic matchers.
  38. // GOOGLETEST_CM0002 DO NOT DELETE
  39. #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
  40. #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
  41. #include <iterator>
  42. #include <sstream>
  43. #include <string>
  44. #include <vector>
  45. #include "gmock/gmock-matchers.h"
  46. namespace testing {
  47. namespace internal {
  48. $range i 0..n-1
  49. // The type of the i-th (0-based) field of Tuple.
  50. #define GMOCK_FIELD_TYPE_(Tuple, i) \
  51. typename ::testing::tuple_element<i, Tuple>::type
  52. // TupleFields<Tuple, k0, ..., kn> is for selecting fields from a
  53. // tuple of type Tuple. It has two members:
  54. //
  55. // type: a tuple type whose i-th field is the ki-th field of Tuple.
  56. // GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple.
  57. //
  58. // For example, in class TupleFields<tuple<bool, char, int>, 2, 0>, we have:
  59. //
  60. // type is tuple<int, bool>, and
  61. // GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true).
  62. template <class Tuple$for i [[, int k$i = -1]]>
  63. class TupleFields;
  64. // This generic version is used when there are $n selectors.
  65. template <class Tuple$for i [[, int k$i]]>
  66. class TupleFields {
  67. public:
  68. typedef ::testing::tuple<$for i, [[GMOCK_FIELD_TYPE_(Tuple, k$i)]]> type;
  69. static type GetSelectedFields(const Tuple& t) {
  70. return type($for i, [[get<k$i>(t)]]);
  71. }
  72. };
  73. // The following specialization is used for 0 ~ $(n-1) selectors.
  74. $for i [[
  75. $$ }}}
  76. $range j 0..i-1
  77. $range k 0..n-1
  78. template <class Tuple$for j [[, int k$j]]>
  79. class TupleFields<Tuple, $for k, [[$if k < i [[k$k]] $else [[-1]]]]> {
  80. public:
  81. typedef ::testing::tuple<$for j, [[GMOCK_FIELD_TYPE_(Tuple, k$j)]]> type;
  82. static type GetSelectedFields(const Tuple& $if i==0 [[/* t */]] $else [[t]]) {
  83. return type($for j, [[get<k$j>(t)]]);
  84. }
  85. };
  86. ]]
  87. #undef GMOCK_FIELD_TYPE_
  88. // Implements the Args() matcher.
  89. $var ks = [[$for i, [[k$i]]]]
  90. template <class ArgsTuple$for i [[, int k$i = -1]]>
  91. class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
  92. public:
  93. // ArgsTuple may have top-level const or reference modifiers.
  94. typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple;
  95. typedef typename internal::TupleFields<RawArgsTuple, $ks>::type SelectedArgs;
  96. typedef Matcher<const SelectedArgs&> MonomorphicInnerMatcher;
  97. template <typename InnerMatcher>
  98. explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher)
  99. : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
  100. virtual bool MatchAndExplain(ArgsTuple args,
  101. MatchResultListener* listener) const {
  102. const SelectedArgs& selected_args = GetSelectedArgs(args);
  103. if (!listener->IsInterested())
  104. return inner_matcher_.Matches(selected_args);
  105. PrintIndices(listener->stream());
  106. *listener << "are " << PrintToString(selected_args);
  107. StringMatchResultListener inner_listener;
  108. const bool match = inner_matcher_.MatchAndExplain(selected_args,
  109. &inner_listener);
  110. PrintIfNotEmpty(inner_listener.str(), listener->stream());
  111. return match;
  112. }
  113. virtual void DescribeTo(::std::ostream* os) const {
  114. *os << "are a tuple ";
  115. PrintIndices(os);
  116. inner_matcher_.DescribeTo(os);
  117. }
  118. virtual void DescribeNegationTo(::std::ostream* os) const {
  119. *os << "are a tuple ";
  120. PrintIndices(os);
  121. inner_matcher_.DescribeNegationTo(os);
  122. }
  123. private:
  124. static SelectedArgs GetSelectedArgs(ArgsTuple args) {
  125. return TupleFields<RawArgsTuple, $ks>::GetSelectedFields(args);
  126. }
  127. // Prints the indices of the selected fields.
  128. static void PrintIndices(::std::ostream* os) {
  129. *os << "whose fields (";
  130. const int indices[$n] = { $ks };
  131. for (int i = 0; i < $n; i++) {
  132. if (indices[i] < 0)
  133. break;
  134. if (i >= 1)
  135. *os << ", ";
  136. *os << "#" << indices[i];
  137. }
  138. *os << ") ";
  139. }
  140. const MonomorphicInnerMatcher inner_matcher_;
  141. GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl);
  142. };
  143. template <class InnerMatcher$for i [[, int k$i = -1]]>
  144. class ArgsMatcher {
  145. public:
  146. explicit ArgsMatcher(const InnerMatcher& inner_matcher)
  147. : inner_matcher_(inner_matcher) {}
  148. template <typename ArgsTuple>
  149. operator Matcher<ArgsTuple>() const {
  150. return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, $ks>(inner_matcher_));
  151. }
  152. private:
  153. const InnerMatcher inner_matcher_;
  154. GTEST_DISALLOW_ASSIGN_(ArgsMatcher);
  155. };
  156. // A set of metafunctions for computing the result type of AllOf.
  157. // AllOf(m1, ..., mN) returns
  158. // AllOfResultN<decltype(m1), ..., decltype(mN)>::type.
  159. // Although AllOf isn't defined for one argument, AllOfResult1 is defined
  160. // to simplify the implementation.
  161. template <typename M1>
  162. struct AllOfResult1 {
  163. typedef M1 type;
  164. };
  165. $range i 1..n
  166. $range i 2..n
  167. $for i [[
  168. $range j 2..i
  169. $var m = i/2
  170. $range k 1..m
  171. $range t m+1..i
  172. template <typename M1$for j [[, typename M$j]]>
  173. struct AllOfResult$i {
  174. typedef BothOfMatcher<
  175. typename AllOfResult$m<$for k, [[M$k]]>::type,
  176. typename AllOfResult$(i-m)<$for t, [[M$t]]>::type
  177. > type;
  178. };
  179. ]]
  180. // A set of metafunctions for computing the result type of AnyOf.
  181. // AnyOf(m1, ..., mN) returns
  182. // AnyOfResultN<decltype(m1), ..., decltype(mN)>::type.
  183. // Although AnyOf isn't defined for one argument, AnyOfResult1 is defined
  184. // to simplify the implementation.
  185. template <typename M1>
  186. struct AnyOfResult1 {
  187. typedef M1 type;
  188. };
  189. $range i 1..n
  190. $range i 2..n
  191. $for i [[
  192. $range j 2..i
  193. $var m = i/2
  194. $range k 1..m
  195. $range t m+1..i
  196. template <typename M1$for j [[, typename M$j]]>
  197. struct AnyOfResult$i {
  198. typedef EitherOfMatcher<
  199. typename AnyOfResult$m<$for k, [[M$k]]>::type,
  200. typename AnyOfResult$(i-m)<$for t, [[M$t]]>::type
  201. > type;
  202. };
  203. ]]
  204. } // namespace internal
  205. // Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected
  206. // fields of it matches a_matcher. C++ doesn't support default
  207. // arguments for function templates, so we have to overload it.
  208. $range i 0..n
  209. $for i [[
  210. $range j 1..i
  211. template <$for j [[int k$j, ]]typename InnerMatcher>
  212. inline internal::ArgsMatcher<InnerMatcher$for j [[, k$j]]>
  213. Args(const InnerMatcher& matcher) {
  214. return internal::ArgsMatcher<InnerMatcher$for j [[, k$j]]>(matcher);
  215. }
  216. ]]
  217. // ElementsAre(e_1, e_2, ... e_n) matches an STL-style container with
  218. // n elements, where the i-th element in the container must
  219. // match the i-th argument in the list. Each argument of
  220. // ElementsAre() can be either a value or a matcher. We support up to
  221. // $n arguments.
  222. //
  223. // The use of DecayArray in the implementation allows ElementsAre()
  224. // to accept string literals, whose type is const char[N], but we
  225. // want to treat them as const char*.
  226. //
  227. // NOTE: Since ElementsAre() cares about the order of the elements, it
  228. // must not be used with containers whose elements's order is
  229. // undefined (e.g. hash_map).
  230. $range i 0..n
  231. $for i [[
  232. $range j 1..i
  233. $if i>0 [[
  234. template <$for j, [[typename T$j]]>
  235. ]]
  236. inline internal::ElementsAreMatcher<
  237. ::testing::tuple<
  238. $for j, [[
  239. typename internal::DecayArray<T$j[[]]>::type]]> >
  240. ElementsAre($for j, [[const T$j& e$j]]) {
  241. typedef ::testing::tuple<
  242. $for j, [[
  243. typename internal::DecayArray<T$j[[]]>::type]]> Args;
  244. return internal::ElementsAreMatcher<Args>(Args($for j, [[e$j]]));
  245. }
  246. ]]
  247. // UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension
  248. // that matches n elements in any order. We support up to n=$n arguments.
  249. //
  250. // If you have >$n elements, consider UnorderedElementsAreArray() or
  251. // UnorderedPointwise() instead.
  252. $range i 0..n
  253. $for i [[
  254. $range j 1..i
  255. $if i>0 [[
  256. template <$for j, [[typename T$j]]>
  257. ]]
  258. inline internal::UnorderedElementsAreMatcher<
  259. ::testing::tuple<
  260. $for j, [[
  261. typename internal::DecayArray<T$j[[]]>::type]]> >
  262. UnorderedElementsAre($for j, [[const T$j& e$j]]) {
  263. typedef ::testing::tuple<
  264. $for j, [[
  265. typename internal::DecayArray<T$j[[]]>::type]]> Args;
  266. return internal::UnorderedElementsAreMatcher<Args>(Args($for j, [[e$j]]));
  267. }
  268. ]]
  269. // AllOf(m1, m2, ..., mk) matches any value that matches all of the given
  270. // sub-matchers. AllOf is called fully qualified to prevent ADL from firing.
  271. $range i 2..n
  272. $for i [[
  273. $range j 1..i
  274. $var m = i/2
  275. $range k 1..m
  276. $range t m+1..i
  277. template <$for j, [[typename M$j]]>
  278. inline typename internal::AllOfResult$i<$for j, [[M$j]]>::type
  279. AllOf($for j, [[M$j m$j]]) {
  280. return typename internal::AllOfResult$i<$for j, [[M$j]]>::type(
  281. $if m == 1 [[m1]] $else [[::testing::AllOf($for k, [[m$k]])]],
  282. $if m+1 == i [[m$i]] $else [[::testing::AllOf($for t, [[m$t]])]]);
  283. }
  284. ]]
  285. // AnyOf(m1, m2, ..., mk) matches any value that matches any of the given
  286. // sub-matchers. AnyOf is called fully qualified to prevent ADL from firing.
  287. $range i 2..n
  288. $for i [[
  289. $range j 1..i
  290. $var m = i/2
  291. $range k 1..m
  292. $range t m+1..i
  293. template <$for j, [[typename M$j]]>
  294. inline typename internal::AnyOfResult$i<$for j, [[M$j]]>::type
  295. AnyOf($for j, [[M$j m$j]]) {
  296. return typename internal::AnyOfResult$i<$for j, [[M$j]]>::type(
  297. $if m == 1 [[m1]] $else [[::testing::AnyOf($for k, [[m$k]])]],
  298. $if m+1 == i [[m$i]] $else [[::testing::AnyOf($for t, [[m$t]])]]);
  299. }
  300. ]]
  301. } // namespace testing
  302. $$ } // This Pump meta comment fixes auto-indentation in Emacs. It will not
  303. $$ // show up in the generated code.
  304. // The MATCHER* family of macros can be used in a namespace scope to
  305. // define custom matchers easily.
  306. //
  307. // Basic Usage
  308. // ===========
  309. //
  310. // The syntax
  311. //
  312. // MATCHER(name, description_string) { statements; }
  313. //
  314. // defines a matcher with the given name that executes the statements,
  315. // which must return a bool to indicate if the match succeeds. Inside
  316. // the statements, you can refer to the value being matched by 'arg',
  317. // and refer to its type by 'arg_type'.
  318. //
  319. // The description string documents what the matcher does, and is used
  320. // to generate the failure message when the match fails. Since a
  321. // MATCHER() is usually defined in a header file shared by multiple
  322. // C++ source files, we require the description to be a C-string
  323. // literal to avoid possible side effects. It can be empty, in which
  324. // case we'll use the sequence of words in the matcher name as the
  325. // description.
  326. //
  327. // For example:
  328. //
  329. // MATCHER(IsEven, "") { return (arg % 2) == 0; }
  330. //
  331. // allows you to write
  332. //
  333. // // Expects mock_foo.Bar(n) to be called where n is even.
  334. // EXPECT_CALL(mock_foo, Bar(IsEven()));
  335. //
  336. // or,
  337. //
  338. // // Verifies that the value of some_expression is even.
  339. // EXPECT_THAT(some_expression, IsEven());
  340. //
  341. // If the above assertion fails, it will print something like:
  342. //
  343. // Value of: some_expression
  344. // Expected: is even
  345. // Actual: 7
  346. //
  347. // where the description "is even" is automatically calculated from the
  348. // matcher name IsEven.
  349. //
  350. // Argument Type
  351. // =============
  352. //
  353. // Note that the type of the value being matched (arg_type) is
  354. // determined by the context in which you use the matcher and is
  355. // supplied to you by the compiler, so you don't need to worry about
  356. // declaring it (nor can you). This allows the matcher to be
  357. // polymorphic. For example, IsEven() can be used to match any type
  358. // where the value of "(arg % 2) == 0" can be implicitly converted to
  359. // a bool. In the "Bar(IsEven())" example above, if method Bar()
  360. // takes an int, 'arg_type' will be int; if it takes an unsigned long,
  361. // 'arg_type' will be unsigned long; and so on.
  362. //
  363. // Parameterizing Matchers
  364. // =======================
  365. //
  366. // Sometimes you'll want to parameterize the matcher. For that you
  367. // can use another macro:
  368. //
  369. // MATCHER_P(name, param_name, description_string) { statements; }
  370. //
  371. // For example:
  372. //
  373. // MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; }
  374. //
  375. // will allow you to write:
  376. //
  377. // EXPECT_THAT(Blah("a"), HasAbsoluteValue(n));
  378. //
  379. // which may lead to this message (assuming n is 10):
  380. //
  381. // Value of: Blah("a")
  382. // Expected: has absolute value 10
  383. // Actual: -9
  384. //
  385. // Note that both the matcher description and its parameter are
  386. // printed, making the message human-friendly.
  387. //
  388. // In the matcher definition body, you can write 'foo_type' to
  389. // reference the type of a parameter named 'foo'. For example, in the
  390. // body of MATCHER_P(HasAbsoluteValue, value) above, you can write
  391. // 'value_type' to refer to the type of 'value'.
  392. //
  393. // We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P$n to
  394. // support multi-parameter matchers.
  395. //
  396. // Describing Parameterized Matchers
  397. // =================================
  398. //
  399. // The last argument to MATCHER*() is a string-typed expression. The
  400. // expression can reference all of the matcher's parameters and a
  401. // special bool-typed variable named 'negation'. When 'negation' is
  402. // false, the expression should evaluate to the matcher's description;
  403. // otherwise it should evaluate to the description of the negation of
  404. // the matcher. For example,
  405. //
  406. // using testing::PrintToString;
  407. //
  408. // MATCHER_P2(InClosedRange, low, hi,
  409. // std::string(negation ? "is not" : "is") + " in range [" +
  410. // PrintToString(low) + ", " + PrintToString(hi) + "]") {
  411. // return low <= arg && arg <= hi;
  412. // }
  413. // ...
  414. // EXPECT_THAT(3, InClosedRange(4, 6));
  415. // EXPECT_THAT(3, Not(InClosedRange(2, 4)));
  416. //
  417. // would generate two failures that contain the text:
  418. //
  419. // Expected: is in range [4, 6]
  420. // ...
  421. // Expected: is not in range [2, 4]
  422. //
  423. // If you specify "" as the description, the failure message will
  424. // contain the sequence of words in the matcher name followed by the
  425. // parameter values printed as a tuple. For example,
  426. //
  427. // MATCHER_P2(InClosedRange, low, hi, "") { ... }
  428. // ...
  429. // EXPECT_THAT(3, InClosedRange(4, 6));
  430. // EXPECT_THAT(3, Not(InClosedRange(2, 4)));
  431. //
  432. // would generate two failures that contain the text:
  433. //
  434. // Expected: in closed range (4, 6)
  435. // ...
  436. // Expected: not (in closed range (2, 4))
  437. //
  438. // Types of Matcher Parameters
  439. // ===========================
  440. //
  441. // For the purpose of typing, you can view
  442. //
  443. // MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... }
  444. //
  445. // as shorthand for
  446. //
  447. // template <typename p1_type, ..., typename pk_type>
  448. // FooMatcherPk<p1_type, ..., pk_type>
  449. // Foo(p1_type p1, ..., pk_type pk) { ... }
  450. //
  451. // When you write Foo(v1, ..., vk), the compiler infers the types of
  452. // the parameters v1, ..., and vk for you. If you are not happy with
  453. // the result of the type inference, you can specify the types by
  454. // explicitly instantiating the template, as in Foo<long, bool>(5,
  455. // false). As said earlier, you don't get to (or need to) specify
  456. // 'arg_type' as that's determined by the context in which the matcher
  457. // is used. You can assign the result of expression Foo(p1, ..., pk)
  458. // to a variable of type FooMatcherPk<p1_type, ..., pk_type>. This
  459. // can be useful when composing matchers.
  460. //
  461. // While you can instantiate a matcher template with reference types,
  462. // passing the parameters by pointer usually makes your code more
  463. // readable. If, however, you still want to pass a parameter by
  464. // reference, be aware that in the failure message generated by the
  465. // matcher you will see the value of the referenced object but not its
  466. // address.
  467. //
  468. // Explaining Match Results
  469. // ========================
  470. //
  471. // Sometimes the matcher description alone isn't enough to explain why
  472. // the match has failed or succeeded. For example, when expecting a
  473. // long string, it can be very helpful to also print the diff between
  474. // the expected string and the actual one. To achieve that, you can
  475. // optionally stream additional information to a special variable
  476. // named result_listener, whose type is a pointer to class
  477. // MatchResultListener:
  478. //
  479. // MATCHER_P(EqualsLongString, str, "") {
  480. // if (arg == str) return true;
  481. //
  482. // *result_listener << "the difference: "
  483. /// << DiffStrings(str, arg);
  484. // return false;
  485. // }
  486. //
  487. // Overloading Matchers
  488. // ====================
  489. //
  490. // You can overload matchers with different numbers of parameters:
  491. //
  492. // MATCHER_P(Blah, a, description_string1) { ... }
  493. // MATCHER_P2(Blah, a, b, description_string2) { ... }
  494. //
  495. // Caveats
  496. // =======
  497. //
  498. // When defining a new matcher, you should also consider implementing
  499. // MatcherInterface or using MakePolymorphicMatcher(). These
  500. // approaches require more work than the MATCHER* macros, but also
  501. // give you more control on the types of the value being matched and
  502. // the matcher parameters, which may leads to better compiler error
  503. // messages when the matcher is used wrong. They also allow
  504. // overloading matchers based on parameter types (as opposed to just
  505. // based on the number of parameters).
  506. //
  507. // MATCHER*() can only be used in a namespace scope. The reason is
  508. // that C++ doesn't yet allow function-local types to be used to
  509. // instantiate templates. The up-coming C++0x standard will fix this.
  510. // Once that's done, we'll consider supporting using MATCHER*() inside
  511. // a function.
  512. //
  513. // More Information
  514. // ================
  515. //
  516. // To learn more about using these macros, please search for 'MATCHER'
  517. // on
  518. // https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md
  519. $range i 0..n
  520. $for i
  521. [[
  522. $var macro_name = [[$if i==0 [[MATCHER]] $elif i==1 [[MATCHER_P]]
  523. $else [[MATCHER_P$i]]]]
  524. $var class_name = [[name##Matcher[[$if i==0 [[]] $elif i==1 [[P]]
  525. $else [[P$i]]]]]]
  526. $range j 0..i-1
  527. $var template = [[$if i==0 [[]] $else [[
  528. template <$for j, [[typename p$j##_type]]>\
  529. ]]]]
  530. $var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
  531. $var impl_ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
  532. $var impl_inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::testing::internal::move(gmock_p$j))]]]]]]
  533. $var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::testing::internal::move(gmock_p$j))]]]]]]
  534. $var params = [[$for j, [[p$j]]]]
  535. $var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]]
  536. $var param_types_and_names = [[$for j, [[p$j##_type p$j]]]]
  537. $var param_field_decls = [[$for j
  538. [[
  539. p$j##_type const p$j;\
  540. ]]]]
  541. $var param_field_decls2 = [[$for j
  542. [[
  543. p$j##_type const p$j;\
  544. ]]]]
  545. #define $macro_name(name$for j [[, p$j]], description)\$template
  546. class $class_name {\
  547. public:\
  548. template <typename arg_type>\
  549. class gmock_Impl : public ::testing::MatcherInterface<\
  550. GTEST_REFERENCE_TO_CONST_(arg_type)> {\
  551. public:\
  552. [[$if i==1 [[explicit ]]]]gmock_Impl($impl_ctor_param_list)\
  553. $impl_inits {}\
  554. virtual bool MatchAndExplain(\
  555. GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
  556. ::testing::MatchResultListener* result_listener) const;\
  557. virtual void DescribeTo(::std::ostream* gmock_os) const {\
  558. *gmock_os << FormatDescription(false);\
  559. }\
  560. virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
  561. *gmock_os << FormatDescription(true);\
  562. }\$param_field_decls
  563. private:\
  564. ::std::string FormatDescription(bool negation) const {\
  565. ::std::string gmock_description = (description);\
  566. if (!gmock_description.empty())\
  567. return gmock_description;\
  568. return ::testing::internal::FormatMatcherDescription(\
  569. negation, #name, \
  570. ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
  571. ::testing::tuple<$for j, [[p$j##_type]]>($for j, [[p$j]])));\
  572. }\
  573. };\
  574. template <typename arg_type>\
  575. operator ::testing::Matcher<arg_type>() const {\
  576. return ::testing::Matcher<arg_type>(\
  577. new gmock_Impl<arg_type>($params));\
  578. }\
  579. [[$if i==1 [[explicit ]]]]$class_name($ctor_param_list)$inits {\
  580. }\$param_field_decls2
  581. private:\
  582. };\$template
  583. inline $class_name$param_types name($param_types_and_names) {\
  584. return $class_name$param_types($params);\
  585. }\$template
  586. template <typename arg_type>\
  587. bool $class_name$param_types::gmock_Impl<arg_type>::MatchAndExplain(\
  588. GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
  589. ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
  590. const
  591. ]]
  592. #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_