gmock-generated-matchers.h 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190
  1. // This file was GENERATED by command:
  2. // pump.py gmock-generated-matchers.h.pump
  3. // DO NOT EDIT BY HAND!!!
  4. // Copyright 2008, 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 matchers.
  35. #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
  36. #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_
  37. #include <iterator>
  38. #include <sstream>
  39. #include <string>
  40. #include <vector>
  41. #include "gmock/gmock-matchers.h"
  42. namespace testing {
  43. namespace internal {
  44. // The type of the i-th (0-based) field of Tuple.
  45. #define GMOCK_FIELD_TYPE_(Tuple, i) \
  46. typename ::std::tr1::tuple_element<i, Tuple>::type
  47. // TupleFields<Tuple, k0, ..., kn> is for selecting fields from a
  48. // tuple of type Tuple. It has two members:
  49. //
  50. // type: a tuple type whose i-th field is the ki-th field of Tuple.
  51. // GetSelectedFields(t): returns fields k0, ..., and kn of t as a tuple.
  52. //
  53. // For example, in class TupleFields<tuple<bool, char, int>, 2, 0>, we have:
  54. //
  55. // type is tuple<int, bool>, and
  56. // GetSelectedFields(make_tuple(true, 'a', 42)) is (42, true).
  57. template <class Tuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1,
  58. int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
  59. int k9 = -1>
  60. class TupleFields;
  61. // This generic version is used when there are 10 selectors.
  62. template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
  63. int k7, int k8, int k9>
  64. class TupleFields {
  65. public:
  66. typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
  67. GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
  68. GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
  69. GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
  70. GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8),
  71. GMOCK_FIELD_TYPE_(Tuple, k9)> type;
  72. static type GetSelectedFields(const Tuple& t) {
  73. using ::std::tr1::get;
  74. return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
  75. get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t), get<k9>(t));
  76. }
  77. };
  78. // The following specialization is used for 0 ~ 9 selectors.
  79. template <class Tuple>
  80. class TupleFields<Tuple, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
  81. public:
  82. typedef ::std::tr1::tuple<> type;
  83. static type GetSelectedFields(const Tuple& /* t */) {
  84. using ::std::tr1::get;
  85. return type();
  86. }
  87. };
  88. template <class Tuple, int k0>
  89. class TupleFields<Tuple, k0, -1, -1, -1, -1, -1, -1, -1, -1, -1> {
  90. public:
  91. typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0)> type;
  92. static type GetSelectedFields(const Tuple& t) {
  93. using ::std::tr1::get;
  94. return type(get<k0>(t));
  95. }
  96. };
  97. template <class Tuple, int k0, int k1>
  98. class TupleFields<Tuple, k0, k1, -1, -1, -1, -1, -1, -1, -1, -1> {
  99. public:
  100. typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
  101. GMOCK_FIELD_TYPE_(Tuple, k1)> type;
  102. static type GetSelectedFields(const Tuple& t) {
  103. using ::std::tr1::get;
  104. return type(get<k0>(t), get<k1>(t));
  105. }
  106. };
  107. template <class Tuple, int k0, int k1, int k2>
  108. class TupleFields<Tuple, k0, k1, k2, -1, -1, -1, -1, -1, -1, -1> {
  109. public:
  110. typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
  111. GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2)> type;
  112. static type GetSelectedFields(const Tuple& t) {
  113. using ::std::tr1::get;
  114. return type(get<k0>(t), get<k1>(t), get<k2>(t));
  115. }
  116. };
  117. template <class Tuple, int k0, int k1, int k2, int k3>
  118. class TupleFields<Tuple, k0, k1, k2, k3, -1, -1, -1, -1, -1, -1> {
  119. public:
  120. typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
  121. GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
  122. GMOCK_FIELD_TYPE_(Tuple, k3)> type;
  123. static type GetSelectedFields(const Tuple& t) {
  124. using ::std::tr1::get;
  125. return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t));
  126. }
  127. };
  128. template <class Tuple, int k0, int k1, int k2, int k3, int k4>
  129. class TupleFields<Tuple, k0, k1, k2, k3, k4, -1, -1, -1, -1, -1> {
  130. public:
  131. typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
  132. GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
  133. GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4)> type;
  134. static type GetSelectedFields(const Tuple& t) {
  135. using ::std::tr1::get;
  136. return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t));
  137. }
  138. };
  139. template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5>
  140. class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, -1, -1, -1, -1> {
  141. public:
  142. typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
  143. GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
  144. GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
  145. GMOCK_FIELD_TYPE_(Tuple, k5)> type;
  146. static type GetSelectedFields(const Tuple& t) {
  147. using ::std::tr1::get;
  148. return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
  149. get<k5>(t));
  150. }
  151. };
  152. template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6>
  153. class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, -1, -1, -1> {
  154. public:
  155. typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
  156. GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
  157. GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
  158. GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6)> type;
  159. static type GetSelectedFields(const Tuple& t) {
  160. using ::std::tr1::get;
  161. return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
  162. get<k5>(t), get<k6>(t));
  163. }
  164. };
  165. template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
  166. int k7>
  167. class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, -1, -1> {
  168. public:
  169. typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
  170. GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
  171. GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
  172. GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
  173. GMOCK_FIELD_TYPE_(Tuple, k7)> type;
  174. static type GetSelectedFields(const Tuple& t) {
  175. using ::std::tr1::get;
  176. return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
  177. get<k5>(t), get<k6>(t), get<k7>(t));
  178. }
  179. };
  180. template <class Tuple, int k0, int k1, int k2, int k3, int k4, int k5, int k6,
  181. int k7, int k8>
  182. class TupleFields<Tuple, k0, k1, k2, k3, k4, k5, k6, k7, k8, -1> {
  183. public:
  184. typedef ::std::tr1::tuple<GMOCK_FIELD_TYPE_(Tuple, k0),
  185. GMOCK_FIELD_TYPE_(Tuple, k1), GMOCK_FIELD_TYPE_(Tuple, k2),
  186. GMOCK_FIELD_TYPE_(Tuple, k3), GMOCK_FIELD_TYPE_(Tuple, k4),
  187. GMOCK_FIELD_TYPE_(Tuple, k5), GMOCK_FIELD_TYPE_(Tuple, k6),
  188. GMOCK_FIELD_TYPE_(Tuple, k7), GMOCK_FIELD_TYPE_(Tuple, k8)> type;
  189. static type GetSelectedFields(const Tuple& t) {
  190. using ::std::tr1::get;
  191. return type(get<k0>(t), get<k1>(t), get<k2>(t), get<k3>(t), get<k4>(t),
  192. get<k5>(t), get<k6>(t), get<k7>(t), get<k8>(t));
  193. }
  194. };
  195. #undef GMOCK_FIELD_TYPE_
  196. // Implements the Args() matcher.
  197. template <class ArgsTuple, int k0 = -1, int k1 = -1, int k2 = -1, int k3 = -1,
  198. int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1, int k8 = -1,
  199. int k9 = -1>
  200. class ArgsMatcherImpl : public MatcherInterface<ArgsTuple> {
  201. public:
  202. // ArgsTuple may have top-level const or reference modifiers.
  203. typedef GTEST_REMOVE_REFERENCE_AND_CONST_(ArgsTuple) RawArgsTuple;
  204. typedef typename internal::TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5,
  205. k6, k7, k8, k9>::type SelectedArgs;
  206. typedef Matcher<const SelectedArgs&> MonomorphicInnerMatcher;
  207. template <typename InnerMatcher>
  208. explicit ArgsMatcherImpl(const InnerMatcher& inner_matcher)
  209. : inner_matcher_(SafeMatcherCast<const SelectedArgs&>(inner_matcher)) {}
  210. virtual bool MatchAndExplain(ArgsTuple args,
  211. MatchResultListener* listener) const {
  212. const SelectedArgs& selected_args = GetSelectedArgs(args);
  213. if (!listener->IsInterested())
  214. return inner_matcher_.Matches(selected_args);
  215. PrintIndices(listener->stream());
  216. *listener << "are " << PrintToString(selected_args);
  217. StringMatchResultListener inner_listener;
  218. const bool match = inner_matcher_.MatchAndExplain(selected_args,
  219. &inner_listener);
  220. PrintIfNotEmpty(inner_listener.str(), listener->stream());
  221. return match;
  222. }
  223. virtual void DescribeTo(::std::ostream* os) const {
  224. *os << "are a tuple ";
  225. PrintIndices(os);
  226. inner_matcher_.DescribeTo(os);
  227. }
  228. virtual void DescribeNegationTo(::std::ostream* os) const {
  229. *os << "are a tuple ";
  230. PrintIndices(os);
  231. inner_matcher_.DescribeNegationTo(os);
  232. }
  233. private:
  234. static SelectedArgs GetSelectedArgs(ArgsTuple args) {
  235. return TupleFields<RawArgsTuple, k0, k1, k2, k3, k4, k5, k6, k7, k8,
  236. k9>::GetSelectedFields(args);
  237. }
  238. // Prints the indices of the selected fields.
  239. static void PrintIndices(::std::ostream* os) {
  240. *os << "whose fields (";
  241. const int indices[10] = { k0, k1, k2, k3, k4, k5, k6, k7, k8, k9 };
  242. for (int i = 0; i < 10; i++) {
  243. if (indices[i] < 0)
  244. break;
  245. if (i >= 1)
  246. *os << ", ";
  247. *os << "#" << indices[i];
  248. }
  249. *os << ") ";
  250. }
  251. const MonomorphicInnerMatcher inner_matcher_;
  252. GTEST_DISALLOW_ASSIGN_(ArgsMatcherImpl);
  253. };
  254. template <class InnerMatcher, int k0 = -1, int k1 = -1, int k2 = -1,
  255. int k3 = -1, int k4 = -1, int k5 = -1, int k6 = -1, int k7 = -1,
  256. int k8 = -1, int k9 = -1>
  257. class ArgsMatcher {
  258. public:
  259. explicit ArgsMatcher(const InnerMatcher& inner_matcher)
  260. : inner_matcher_(inner_matcher) {}
  261. template <typename ArgsTuple>
  262. operator Matcher<ArgsTuple>() const {
  263. return MakeMatcher(new ArgsMatcherImpl<ArgsTuple, k0, k1, k2, k3, k4, k5,
  264. k6, k7, k8, k9>(inner_matcher_));
  265. }
  266. private:
  267. const InnerMatcher inner_matcher_;
  268. GTEST_DISALLOW_ASSIGN_(ArgsMatcher);
  269. };
  270. // A set of metafunctions for computing the result type of AllOf.
  271. // AllOf(m1, ..., mN) returns
  272. // AllOfResultN<decltype(m1), ..., decltype(mN)>::type.
  273. // Although AllOf isn't defined for one argument, AllOfResult1 is defined
  274. // to simplify the implementation.
  275. template <typename M1>
  276. struct AllOfResult1 {
  277. typedef M1 type;
  278. };
  279. template <typename M1, typename M2>
  280. struct AllOfResult2 {
  281. typedef BothOfMatcher<
  282. typename AllOfResult1<M1>::type,
  283. typename AllOfResult1<M2>::type
  284. > type;
  285. };
  286. template <typename M1, typename M2, typename M3>
  287. struct AllOfResult3 {
  288. typedef BothOfMatcher<
  289. typename AllOfResult1<M1>::type,
  290. typename AllOfResult2<M2, M3>::type
  291. > type;
  292. };
  293. template <typename M1, typename M2, typename M3, typename M4>
  294. struct AllOfResult4 {
  295. typedef BothOfMatcher<
  296. typename AllOfResult2<M1, M2>::type,
  297. typename AllOfResult2<M3, M4>::type
  298. > type;
  299. };
  300. template <typename M1, typename M2, typename M3, typename M4, typename M5>
  301. struct AllOfResult5 {
  302. typedef BothOfMatcher<
  303. typename AllOfResult2<M1, M2>::type,
  304. typename AllOfResult3<M3, M4, M5>::type
  305. > type;
  306. };
  307. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  308. typename M6>
  309. struct AllOfResult6 {
  310. typedef BothOfMatcher<
  311. typename AllOfResult3<M1, M2, M3>::type,
  312. typename AllOfResult3<M4, M5, M6>::type
  313. > type;
  314. };
  315. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  316. typename M6, typename M7>
  317. struct AllOfResult7 {
  318. typedef BothOfMatcher<
  319. typename AllOfResult3<M1, M2, M3>::type,
  320. typename AllOfResult4<M4, M5, M6, M7>::type
  321. > type;
  322. };
  323. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  324. typename M6, typename M7, typename M8>
  325. struct AllOfResult8 {
  326. typedef BothOfMatcher<
  327. typename AllOfResult4<M1, M2, M3, M4>::type,
  328. typename AllOfResult4<M5, M6, M7, M8>::type
  329. > type;
  330. };
  331. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  332. typename M6, typename M7, typename M8, typename M9>
  333. struct AllOfResult9 {
  334. typedef BothOfMatcher<
  335. typename AllOfResult4<M1, M2, M3, M4>::type,
  336. typename AllOfResult5<M5, M6, M7, M8, M9>::type
  337. > type;
  338. };
  339. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  340. typename M6, typename M7, typename M8, typename M9, typename M10>
  341. struct AllOfResult10 {
  342. typedef BothOfMatcher<
  343. typename AllOfResult5<M1, M2, M3, M4, M5>::type,
  344. typename AllOfResult5<M6, M7, M8, M9, M10>::type
  345. > type;
  346. };
  347. // A set of metafunctions for computing the result type of AnyOf.
  348. // AnyOf(m1, ..., mN) returns
  349. // AnyOfResultN<decltype(m1), ..., decltype(mN)>::type.
  350. // Although AnyOf isn't defined for one argument, AnyOfResult1 is defined
  351. // to simplify the implementation.
  352. template <typename M1>
  353. struct AnyOfResult1 {
  354. typedef M1 type;
  355. };
  356. template <typename M1, typename M2>
  357. struct AnyOfResult2 {
  358. typedef EitherOfMatcher<
  359. typename AnyOfResult1<M1>::type,
  360. typename AnyOfResult1<M2>::type
  361. > type;
  362. };
  363. template <typename M1, typename M2, typename M3>
  364. struct AnyOfResult3 {
  365. typedef EitherOfMatcher<
  366. typename AnyOfResult1<M1>::type,
  367. typename AnyOfResult2<M2, M3>::type
  368. > type;
  369. };
  370. template <typename M1, typename M2, typename M3, typename M4>
  371. struct AnyOfResult4 {
  372. typedef EitherOfMatcher<
  373. typename AnyOfResult2<M1, M2>::type,
  374. typename AnyOfResult2<M3, M4>::type
  375. > type;
  376. };
  377. template <typename M1, typename M2, typename M3, typename M4, typename M5>
  378. struct AnyOfResult5 {
  379. typedef EitherOfMatcher<
  380. typename AnyOfResult2<M1, M2>::type,
  381. typename AnyOfResult3<M3, M4, M5>::type
  382. > type;
  383. };
  384. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  385. typename M6>
  386. struct AnyOfResult6 {
  387. typedef EitherOfMatcher<
  388. typename AnyOfResult3<M1, M2, M3>::type,
  389. typename AnyOfResult3<M4, M5, M6>::type
  390. > type;
  391. };
  392. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  393. typename M6, typename M7>
  394. struct AnyOfResult7 {
  395. typedef EitherOfMatcher<
  396. typename AnyOfResult3<M1, M2, M3>::type,
  397. typename AnyOfResult4<M4, M5, M6, M7>::type
  398. > type;
  399. };
  400. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  401. typename M6, typename M7, typename M8>
  402. struct AnyOfResult8 {
  403. typedef EitherOfMatcher<
  404. typename AnyOfResult4<M1, M2, M3, M4>::type,
  405. typename AnyOfResult4<M5, M6, M7, M8>::type
  406. > type;
  407. };
  408. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  409. typename M6, typename M7, typename M8, typename M9>
  410. struct AnyOfResult9 {
  411. typedef EitherOfMatcher<
  412. typename AnyOfResult4<M1, M2, M3, M4>::type,
  413. typename AnyOfResult5<M5, M6, M7, M8, M9>::type
  414. > type;
  415. };
  416. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  417. typename M6, typename M7, typename M8, typename M9, typename M10>
  418. struct AnyOfResult10 {
  419. typedef EitherOfMatcher<
  420. typename AnyOfResult5<M1, M2, M3, M4, M5>::type,
  421. typename AnyOfResult5<M6, M7, M8, M9, M10>::type
  422. > type;
  423. };
  424. } // namespace internal
  425. // Args<N1, N2, ..., Nk>(a_matcher) matches a tuple if the selected
  426. // fields of it matches a_matcher. C++ doesn't support default
  427. // arguments for function templates, so we have to overload it.
  428. template <typename InnerMatcher>
  429. inline internal::ArgsMatcher<InnerMatcher>
  430. Args(const InnerMatcher& matcher) {
  431. return internal::ArgsMatcher<InnerMatcher>(matcher);
  432. }
  433. template <int k1, typename InnerMatcher>
  434. inline internal::ArgsMatcher<InnerMatcher, k1>
  435. Args(const InnerMatcher& matcher) {
  436. return internal::ArgsMatcher<InnerMatcher, k1>(matcher);
  437. }
  438. template <int k1, int k2, typename InnerMatcher>
  439. inline internal::ArgsMatcher<InnerMatcher, k1, k2>
  440. Args(const InnerMatcher& matcher) {
  441. return internal::ArgsMatcher<InnerMatcher, k1, k2>(matcher);
  442. }
  443. template <int k1, int k2, int k3, typename InnerMatcher>
  444. inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3>
  445. Args(const InnerMatcher& matcher) {
  446. return internal::ArgsMatcher<InnerMatcher, k1, k2, k3>(matcher);
  447. }
  448. template <int k1, int k2, int k3, int k4, typename InnerMatcher>
  449. inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4>
  450. Args(const InnerMatcher& matcher) {
  451. return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4>(matcher);
  452. }
  453. template <int k1, int k2, int k3, int k4, int k5, typename InnerMatcher>
  454. inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5>
  455. Args(const InnerMatcher& matcher) {
  456. return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5>(matcher);
  457. }
  458. template <int k1, int k2, int k3, int k4, int k5, int k6, typename InnerMatcher>
  459. inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6>
  460. Args(const InnerMatcher& matcher) {
  461. return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6>(matcher);
  462. }
  463. template <int k1, int k2, int k3, int k4, int k5, int k6, int k7,
  464. typename InnerMatcher>
  465. inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7>
  466. Args(const InnerMatcher& matcher) {
  467. return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6,
  468. k7>(matcher);
  469. }
  470. template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
  471. typename InnerMatcher>
  472. inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8>
  473. Args(const InnerMatcher& matcher) {
  474. return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7,
  475. k8>(matcher);
  476. }
  477. template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
  478. int k9, typename InnerMatcher>
  479. inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9>
  480. Args(const InnerMatcher& matcher) {
  481. return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8,
  482. k9>(matcher);
  483. }
  484. template <int k1, int k2, int k3, int k4, int k5, int k6, int k7, int k8,
  485. int k9, int k10, typename InnerMatcher>
  486. inline internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8, k9,
  487. k10>
  488. Args(const InnerMatcher& matcher) {
  489. return internal::ArgsMatcher<InnerMatcher, k1, k2, k3, k4, k5, k6, k7, k8,
  490. k9, k10>(matcher);
  491. }
  492. // ElementsAre(e_1, e_2, ... e_n) matches an STL-style container with
  493. // n elements, where the i-th element in the container must
  494. // match the i-th argument in the list. Each argument of
  495. // ElementsAre() can be either a value or a matcher. We support up to
  496. // 10 arguments.
  497. //
  498. // The use of DecayArray in the implementation allows ElementsAre()
  499. // to accept string literals, whose type is const char[N], but we
  500. // want to treat them as const char*.
  501. //
  502. // NOTE: Since ElementsAre() cares about the order of the elements, it
  503. // must not be used with containers whose elements's order is
  504. // undefined (e.g. hash_map).
  505. inline internal::ElementsAreMatcher<
  506. std::tr1::tuple<> >
  507. ElementsAre() {
  508. typedef std::tr1::tuple<> Args;
  509. return internal::ElementsAreMatcher<Args>(Args());
  510. }
  511. template <typename T1>
  512. inline internal::ElementsAreMatcher<
  513. std::tr1::tuple<
  514. typename internal::DecayArray<T1>::type> >
  515. ElementsAre(const T1& e1) {
  516. typedef std::tr1::tuple<
  517. typename internal::DecayArray<T1>::type> Args;
  518. return internal::ElementsAreMatcher<Args>(Args(e1));
  519. }
  520. template <typename T1, typename T2>
  521. inline internal::ElementsAreMatcher<
  522. std::tr1::tuple<
  523. typename internal::DecayArray<T1>::type,
  524. typename internal::DecayArray<T2>::type> >
  525. ElementsAre(const T1& e1, const T2& e2) {
  526. typedef std::tr1::tuple<
  527. typename internal::DecayArray<T1>::type,
  528. typename internal::DecayArray<T2>::type> Args;
  529. return internal::ElementsAreMatcher<Args>(Args(e1, e2));
  530. }
  531. template <typename T1, typename T2, typename T3>
  532. inline internal::ElementsAreMatcher<
  533. std::tr1::tuple<
  534. typename internal::DecayArray<T1>::type,
  535. typename internal::DecayArray<T2>::type,
  536. typename internal::DecayArray<T3>::type> >
  537. ElementsAre(const T1& e1, const T2& e2, const T3& e3) {
  538. typedef std::tr1::tuple<
  539. typename internal::DecayArray<T1>::type,
  540. typename internal::DecayArray<T2>::type,
  541. typename internal::DecayArray<T3>::type> Args;
  542. return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3));
  543. }
  544. template <typename T1, typename T2, typename T3, typename T4>
  545. inline internal::ElementsAreMatcher<
  546. std::tr1::tuple<
  547. typename internal::DecayArray<T1>::type,
  548. typename internal::DecayArray<T2>::type,
  549. typename internal::DecayArray<T3>::type,
  550. typename internal::DecayArray<T4>::type> >
  551. ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4) {
  552. typedef std::tr1::tuple<
  553. typename internal::DecayArray<T1>::type,
  554. typename internal::DecayArray<T2>::type,
  555. typename internal::DecayArray<T3>::type,
  556. typename internal::DecayArray<T4>::type> Args;
  557. return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4));
  558. }
  559. template <typename T1, typename T2, typename T3, typename T4, typename T5>
  560. inline internal::ElementsAreMatcher<
  561. std::tr1::tuple<
  562. typename internal::DecayArray<T1>::type,
  563. typename internal::DecayArray<T2>::type,
  564. typename internal::DecayArray<T3>::type,
  565. typename internal::DecayArray<T4>::type,
  566. typename internal::DecayArray<T5>::type> >
  567. ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
  568. const T5& e5) {
  569. typedef std::tr1::tuple<
  570. typename internal::DecayArray<T1>::type,
  571. typename internal::DecayArray<T2>::type,
  572. typename internal::DecayArray<T3>::type,
  573. typename internal::DecayArray<T4>::type,
  574. typename internal::DecayArray<T5>::type> Args;
  575. return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5));
  576. }
  577. template <typename T1, typename T2, typename T3, typename T4, typename T5,
  578. typename T6>
  579. inline internal::ElementsAreMatcher<
  580. std::tr1::tuple<
  581. typename internal::DecayArray<T1>::type,
  582. typename internal::DecayArray<T2>::type,
  583. typename internal::DecayArray<T3>::type,
  584. typename internal::DecayArray<T4>::type,
  585. typename internal::DecayArray<T5>::type,
  586. typename internal::DecayArray<T6>::type> >
  587. ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
  588. const T5& e5, const T6& e6) {
  589. typedef std::tr1::tuple<
  590. typename internal::DecayArray<T1>::type,
  591. typename internal::DecayArray<T2>::type,
  592. typename internal::DecayArray<T3>::type,
  593. typename internal::DecayArray<T4>::type,
  594. typename internal::DecayArray<T5>::type,
  595. typename internal::DecayArray<T6>::type> Args;
  596. return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6));
  597. }
  598. template <typename T1, typename T2, typename T3, typename T4, typename T5,
  599. typename T6, typename T7>
  600. inline internal::ElementsAreMatcher<
  601. std::tr1::tuple<
  602. typename internal::DecayArray<T1>::type,
  603. typename internal::DecayArray<T2>::type,
  604. typename internal::DecayArray<T3>::type,
  605. typename internal::DecayArray<T4>::type,
  606. typename internal::DecayArray<T5>::type,
  607. typename internal::DecayArray<T6>::type,
  608. typename internal::DecayArray<T7>::type> >
  609. ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
  610. const T5& e5, const T6& e6, const T7& e7) {
  611. typedef std::tr1::tuple<
  612. typename internal::DecayArray<T1>::type,
  613. typename internal::DecayArray<T2>::type,
  614. typename internal::DecayArray<T3>::type,
  615. typename internal::DecayArray<T4>::type,
  616. typename internal::DecayArray<T5>::type,
  617. typename internal::DecayArray<T6>::type,
  618. typename internal::DecayArray<T7>::type> Args;
  619. return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7));
  620. }
  621. template <typename T1, typename T2, typename T3, typename T4, typename T5,
  622. typename T6, typename T7, typename T8>
  623. inline internal::ElementsAreMatcher<
  624. std::tr1::tuple<
  625. typename internal::DecayArray<T1>::type,
  626. typename internal::DecayArray<T2>::type,
  627. typename internal::DecayArray<T3>::type,
  628. typename internal::DecayArray<T4>::type,
  629. typename internal::DecayArray<T5>::type,
  630. typename internal::DecayArray<T6>::type,
  631. typename internal::DecayArray<T7>::type,
  632. typename internal::DecayArray<T8>::type> >
  633. ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
  634. const T5& e5, const T6& e6, const T7& e7, const T8& e8) {
  635. typedef std::tr1::tuple<
  636. typename internal::DecayArray<T1>::type,
  637. typename internal::DecayArray<T2>::type,
  638. typename internal::DecayArray<T3>::type,
  639. typename internal::DecayArray<T4>::type,
  640. typename internal::DecayArray<T5>::type,
  641. typename internal::DecayArray<T6>::type,
  642. typename internal::DecayArray<T7>::type,
  643. typename internal::DecayArray<T8>::type> Args;
  644. return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
  645. e8));
  646. }
  647. template <typename T1, typename T2, typename T3, typename T4, typename T5,
  648. typename T6, typename T7, typename T8, typename T9>
  649. inline internal::ElementsAreMatcher<
  650. std::tr1::tuple<
  651. typename internal::DecayArray<T1>::type,
  652. typename internal::DecayArray<T2>::type,
  653. typename internal::DecayArray<T3>::type,
  654. typename internal::DecayArray<T4>::type,
  655. typename internal::DecayArray<T5>::type,
  656. typename internal::DecayArray<T6>::type,
  657. typename internal::DecayArray<T7>::type,
  658. typename internal::DecayArray<T8>::type,
  659. typename internal::DecayArray<T9>::type> >
  660. ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
  661. const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) {
  662. typedef std::tr1::tuple<
  663. typename internal::DecayArray<T1>::type,
  664. typename internal::DecayArray<T2>::type,
  665. typename internal::DecayArray<T3>::type,
  666. typename internal::DecayArray<T4>::type,
  667. typename internal::DecayArray<T5>::type,
  668. typename internal::DecayArray<T6>::type,
  669. typename internal::DecayArray<T7>::type,
  670. typename internal::DecayArray<T8>::type,
  671. typename internal::DecayArray<T9>::type> Args;
  672. return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
  673. e8, e9));
  674. }
  675. template <typename T1, typename T2, typename T3, typename T4, typename T5,
  676. typename T6, typename T7, typename T8, typename T9, typename T10>
  677. inline internal::ElementsAreMatcher<
  678. std::tr1::tuple<
  679. typename internal::DecayArray<T1>::type,
  680. typename internal::DecayArray<T2>::type,
  681. typename internal::DecayArray<T3>::type,
  682. typename internal::DecayArray<T4>::type,
  683. typename internal::DecayArray<T5>::type,
  684. typename internal::DecayArray<T6>::type,
  685. typename internal::DecayArray<T7>::type,
  686. typename internal::DecayArray<T8>::type,
  687. typename internal::DecayArray<T9>::type,
  688. typename internal::DecayArray<T10>::type> >
  689. ElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
  690. const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9,
  691. const T10& e10) {
  692. typedef std::tr1::tuple<
  693. typename internal::DecayArray<T1>::type,
  694. typename internal::DecayArray<T2>::type,
  695. typename internal::DecayArray<T3>::type,
  696. typename internal::DecayArray<T4>::type,
  697. typename internal::DecayArray<T5>::type,
  698. typename internal::DecayArray<T6>::type,
  699. typename internal::DecayArray<T7>::type,
  700. typename internal::DecayArray<T8>::type,
  701. typename internal::DecayArray<T9>::type,
  702. typename internal::DecayArray<T10>::type> Args;
  703. return internal::ElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5, e6, e7,
  704. e8, e9, e10));
  705. }
  706. // UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension
  707. // that matches n elements in any order. We support up to n=10 arguments.
  708. inline internal::UnorderedElementsAreMatcher<
  709. std::tr1::tuple<> >
  710. UnorderedElementsAre() {
  711. typedef std::tr1::tuple<> Args;
  712. return internal::UnorderedElementsAreMatcher<Args>(Args());
  713. }
  714. template <typename T1>
  715. inline internal::UnorderedElementsAreMatcher<
  716. std::tr1::tuple<
  717. typename internal::DecayArray<T1>::type> >
  718. UnorderedElementsAre(const T1& e1) {
  719. typedef std::tr1::tuple<
  720. typename internal::DecayArray<T1>::type> Args;
  721. return internal::UnorderedElementsAreMatcher<Args>(Args(e1));
  722. }
  723. template <typename T1, typename T2>
  724. inline internal::UnorderedElementsAreMatcher<
  725. std::tr1::tuple<
  726. typename internal::DecayArray<T1>::type,
  727. typename internal::DecayArray<T2>::type> >
  728. UnorderedElementsAre(const T1& e1, const T2& e2) {
  729. typedef std::tr1::tuple<
  730. typename internal::DecayArray<T1>::type,
  731. typename internal::DecayArray<T2>::type> Args;
  732. return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2));
  733. }
  734. template <typename T1, typename T2, typename T3>
  735. inline internal::UnorderedElementsAreMatcher<
  736. std::tr1::tuple<
  737. typename internal::DecayArray<T1>::type,
  738. typename internal::DecayArray<T2>::type,
  739. typename internal::DecayArray<T3>::type> >
  740. UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3) {
  741. typedef std::tr1::tuple<
  742. typename internal::DecayArray<T1>::type,
  743. typename internal::DecayArray<T2>::type,
  744. typename internal::DecayArray<T3>::type> Args;
  745. return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3));
  746. }
  747. template <typename T1, typename T2, typename T3, typename T4>
  748. inline internal::UnorderedElementsAreMatcher<
  749. std::tr1::tuple<
  750. typename internal::DecayArray<T1>::type,
  751. typename internal::DecayArray<T2>::type,
  752. typename internal::DecayArray<T3>::type,
  753. typename internal::DecayArray<T4>::type> >
  754. UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4) {
  755. typedef std::tr1::tuple<
  756. typename internal::DecayArray<T1>::type,
  757. typename internal::DecayArray<T2>::type,
  758. typename internal::DecayArray<T3>::type,
  759. typename internal::DecayArray<T4>::type> Args;
  760. return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4));
  761. }
  762. template <typename T1, typename T2, typename T3, typename T4, typename T5>
  763. inline internal::UnorderedElementsAreMatcher<
  764. std::tr1::tuple<
  765. typename internal::DecayArray<T1>::type,
  766. typename internal::DecayArray<T2>::type,
  767. typename internal::DecayArray<T3>::type,
  768. typename internal::DecayArray<T4>::type,
  769. typename internal::DecayArray<T5>::type> >
  770. UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
  771. const T5& e5) {
  772. typedef std::tr1::tuple<
  773. typename internal::DecayArray<T1>::type,
  774. typename internal::DecayArray<T2>::type,
  775. typename internal::DecayArray<T3>::type,
  776. typename internal::DecayArray<T4>::type,
  777. typename internal::DecayArray<T5>::type> Args;
  778. return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5));
  779. }
  780. template <typename T1, typename T2, typename T3, typename T4, typename T5,
  781. typename T6>
  782. inline internal::UnorderedElementsAreMatcher<
  783. std::tr1::tuple<
  784. typename internal::DecayArray<T1>::type,
  785. typename internal::DecayArray<T2>::type,
  786. typename internal::DecayArray<T3>::type,
  787. typename internal::DecayArray<T4>::type,
  788. typename internal::DecayArray<T5>::type,
  789. typename internal::DecayArray<T6>::type> >
  790. UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
  791. const T5& e5, const T6& e6) {
  792. typedef std::tr1::tuple<
  793. typename internal::DecayArray<T1>::type,
  794. typename internal::DecayArray<T2>::type,
  795. typename internal::DecayArray<T3>::type,
  796. typename internal::DecayArray<T4>::type,
  797. typename internal::DecayArray<T5>::type,
  798. typename internal::DecayArray<T6>::type> Args;
  799. return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
  800. e6));
  801. }
  802. template <typename T1, typename T2, typename T3, typename T4, typename T5,
  803. typename T6, typename T7>
  804. inline internal::UnorderedElementsAreMatcher<
  805. std::tr1::tuple<
  806. typename internal::DecayArray<T1>::type,
  807. typename internal::DecayArray<T2>::type,
  808. typename internal::DecayArray<T3>::type,
  809. typename internal::DecayArray<T4>::type,
  810. typename internal::DecayArray<T5>::type,
  811. typename internal::DecayArray<T6>::type,
  812. typename internal::DecayArray<T7>::type> >
  813. UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
  814. const T5& e5, const T6& e6, const T7& e7) {
  815. typedef std::tr1::tuple<
  816. typename internal::DecayArray<T1>::type,
  817. typename internal::DecayArray<T2>::type,
  818. typename internal::DecayArray<T3>::type,
  819. typename internal::DecayArray<T4>::type,
  820. typename internal::DecayArray<T5>::type,
  821. typename internal::DecayArray<T6>::type,
  822. typename internal::DecayArray<T7>::type> Args;
  823. return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
  824. e6, e7));
  825. }
  826. template <typename T1, typename T2, typename T3, typename T4, typename T5,
  827. typename T6, typename T7, typename T8>
  828. inline internal::UnorderedElementsAreMatcher<
  829. std::tr1::tuple<
  830. typename internal::DecayArray<T1>::type,
  831. typename internal::DecayArray<T2>::type,
  832. typename internal::DecayArray<T3>::type,
  833. typename internal::DecayArray<T4>::type,
  834. typename internal::DecayArray<T5>::type,
  835. typename internal::DecayArray<T6>::type,
  836. typename internal::DecayArray<T7>::type,
  837. typename internal::DecayArray<T8>::type> >
  838. UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
  839. const T5& e5, const T6& e6, const T7& e7, const T8& e8) {
  840. typedef std::tr1::tuple<
  841. typename internal::DecayArray<T1>::type,
  842. typename internal::DecayArray<T2>::type,
  843. typename internal::DecayArray<T3>::type,
  844. typename internal::DecayArray<T4>::type,
  845. typename internal::DecayArray<T5>::type,
  846. typename internal::DecayArray<T6>::type,
  847. typename internal::DecayArray<T7>::type,
  848. typename internal::DecayArray<T8>::type> Args;
  849. return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
  850. e6, e7, e8));
  851. }
  852. template <typename T1, typename T2, typename T3, typename T4, typename T5,
  853. typename T6, typename T7, typename T8, typename T9>
  854. inline internal::UnorderedElementsAreMatcher<
  855. std::tr1::tuple<
  856. typename internal::DecayArray<T1>::type,
  857. typename internal::DecayArray<T2>::type,
  858. typename internal::DecayArray<T3>::type,
  859. typename internal::DecayArray<T4>::type,
  860. typename internal::DecayArray<T5>::type,
  861. typename internal::DecayArray<T6>::type,
  862. typename internal::DecayArray<T7>::type,
  863. typename internal::DecayArray<T8>::type,
  864. typename internal::DecayArray<T9>::type> >
  865. UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
  866. const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9) {
  867. typedef std::tr1::tuple<
  868. typename internal::DecayArray<T1>::type,
  869. typename internal::DecayArray<T2>::type,
  870. typename internal::DecayArray<T3>::type,
  871. typename internal::DecayArray<T4>::type,
  872. typename internal::DecayArray<T5>::type,
  873. typename internal::DecayArray<T6>::type,
  874. typename internal::DecayArray<T7>::type,
  875. typename internal::DecayArray<T8>::type,
  876. typename internal::DecayArray<T9>::type> Args;
  877. return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
  878. e6, e7, e8, e9));
  879. }
  880. template <typename T1, typename T2, typename T3, typename T4, typename T5,
  881. typename T6, typename T7, typename T8, typename T9, typename T10>
  882. inline internal::UnorderedElementsAreMatcher<
  883. std::tr1::tuple<
  884. typename internal::DecayArray<T1>::type,
  885. typename internal::DecayArray<T2>::type,
  886. typename internal::DecayArray<T3>::type,
  887. typename internal::DecayArray<T4>::type,
  888. typename internal::DecayArray<T5>::type,
  889. typename internal::DecayArray<T6>::type,
  890. typename internal::DecayArray<T7>::type,
  891. typename internal::DecayArray<T8>::type,
  892. typename internal::DecayArray<T9>::type,
  893. typename internal::DecayArray<T10>::type> >
  894. UnorderedElementsAre(const T1& e1, const T2& e2, const T3& e3, const T4& e4,
  895. const T5& e5, const T6& e6, const T7& e7, const T8& e8, const T9& e9,
  896. const T10& e10) {
  897. typedef std::tr1::tuple<
  898. typename internal::DecayArray<T1>::type,
  899. typename internal::DecayArray<T2>::type,
  900. typename internal::DecayArray<T3>::type,
  901. typename internal::DecayArray<T4>::type,
  902. typename internal::DecayArray<T5>::type,
  903. typename internal::DecayArray<T6>::type,
  904. typename internal::DecayArray<T7>::type,
  905. typename internal::DecayArray<T8>::type,
  906. typename internal::DecayArray<T9>::type,
  907. typename internal::DecayArray<T10>::type> Args;
  908. return internal::UnorderedElementsAreMatcher<Args>(Args(e1, e2, e3, e4, e5,
  909. e6, e7, e8, e9, e10));
  910. }
  911. // AllOf(m1, m2, ..., mk) matches any value that matches all of the given
  912. // sub-matchers. AllOf is called fully qualified to prevent ADL from firing.
  913. template <typename M1, typename M2>
  914. inline typename internal::AllOfResult2<M1, M2>::type
  915. AllOf(M1 m1, M2 m2) {
  916. return typename internal::AllOfResult2<M1, M2>::type(
  917. m1,
  918. m2);
  919. }
  920. template <typename M1, typename M2, typename M3>
  921. inline typename internal::AllOfResult3<M1, M2, M3>::type
  922. AllOf(M1 m1, M2 m2, M3 m3) {
  923. return typename internal::AllOfResult3<M1, M2, M3>::type(
  924. m1,
  925. ::testing::AllOf(m2, m3));
  926. }
  927. template <typename M1, typename M2, typename M3, typename M4>
  928. inline typename internal::AllOfResult4<M1, M2, M3, M4>::type
  929. AllOf(M1 m1, M2 m2, M3 m3, M4 m4) {
  930. return typename internal::AllOfResult4<M1, M2, M3, M4>::type(
  931. ::testing::AllOf(m1, m2),
  932. ::testing::AllOf(m3, m4));
  933. }
  934. template <typename M1, typename M2, typename M3, typename M4, typename M5>
  935. inline typename internal::AllOfResult5<M1, M2, M3, M4, M5>::type
  936. AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) {
  937. return typename internal::AllOfResult5<M1, M2, M3, M4, M5>::type(
  938. ::testing::AllOf(m1, m2),
  939. ::testing::AllOf(m3, m4, m5));
  940. }
  941. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  942. typename M6>
  943. inline typename internal::AllOfResult6<M1, M2, M3, M4, M5, M6>::type
  944. AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) {
  945. return typename internal::AllOfResult6<M1, M2, M3, M4, M5, M6>::type(
  946. ::testing::AllOf(m1, m2, m3),
  947. ::testing::AllOf(m4, m5, m6));
  948. }
  949. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  950. typename M6, typename M7>
  951. inline typename internal::AllOfResult7<M1, M2, M3, M4, M5, M6, M7>::type
  952. AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) {
  953. return typename internal::AllOfResult7<M1, M2, M3, M4, M5, M6, M7>::type(
  954. ::testing::AllOf(m1, m2, m3),
  955. ::testing::AllOf(m4, m5, m6, m7));
  956. }
  957. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  958. typename M6, typename M7, typename M8>
  959. inline typename internal::AllOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type
  960. AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) {
  961. return typename internal::AllOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type(
  962. ::testing::AllOf(m1, m2, m3, m4),
  963. ::testing::AllOf(m5, m6, m7, m8));
  964. }
  965. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  966. typename M6, typename M7, typename M8, typename M9>
  967. inline typename internal::AllOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type
  968. AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) {
  969. return typename internal::AllOfResult9<M1, M2, M3, M4, M5, M6, M7, M8,
  970. M9>::type(
  971. ::testing::AllOf(m1, m2, m3, m4),
  972. ::testing::AllOf(m5, m6, m7, m8, m9));
  973. }
  974. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  975. typename M6, typename M7, typename M8, typename M9, typename M10>
  976. inline typename internal::AllOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
  977. M10>::type
  978. AllOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
  979. return typename internal::AllOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
  980. M10>::type(
  981. ::testing::AllOf(m1, m2, m3, m4, m5),
  982. ::testing::AllOf(m6, m7, m8, m9, m10));
  983. }
  984. // AnyOf(m1, m2, ..., mk) matches any value that matches any of the given
  985. // sub-matchers. AnyOf is called fully qualified to prevent ADL from firing.
  986. template <typename M1, typename M2>
  987. inline typename internal::AnyOfResult2<M1, M2>::type
  988. AnyOf(M1 m1, M2 m2) {
  989. return typename internal::AnyOfResult2<M1, M2>::type(
  990. m1,
  991. m2);
  992. }
  993. template <typename M1, typename M2, typename M3>
  994. inline typename internal::AnyOfResult3<M1, M2, M3>::type
  995. AnyOf(M1 m1, M2 m2, M3 m3) {
  996. return typename internal::AnyOfResult3<M1, M2, M3>::type(
  997. m1,
  998. ::testing::AnyOf(m2, m3));
  999. }
  1000. template <typename M1, typename M2, typename M3, typename M4>
  1001. inline typename internal::AnyOfResult4<M1, M2, M3, M4>::type
  1002. AnyOf(M1 m1, M2 m2, M3 m3, M4 m4) {
  1003. return typename internal::AnyOfResult4<M1, M2, M3, M4>::type(
  1004. ::testing::AnyOf(m1, m2),
  1005. ::testing::AnyOf(m3, m4));
  1006. }
  1007. template <typename M1, typename M2, typename M3, typename M4, typename M5>
  1008. inline typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type
  1009. AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5) {
  1010. return typename internal::AnyOfResult5<M1, M2, M3, M4, M5>::type(
  1011. ::testing::AnyOf(m1, m2),
  1012. ::testing::AnyOf(m3, m4, m5));
  1013. }
  1014. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  1015. typename M6>
  1016. inline typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type
  1017. AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6) {
  1018. return typename internal::AnyOfResult6<M1, M2, M3, M4, M5, M6>::type(
  1019. ::testing::AnyOf(m1, m2, m3),
  1020. ::testing::AnyOf(m4, m5, m6));
  1021. }
  1022. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  1023. typename M6, typename M7>
  1024. inline typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type
  1025. AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7) {
  1026. return typename internal::AnyOfResult7<M1, M2, M3, M4, M5, M6, M7>::type(
  1027. ::testing::AnyOf(m1, m2, m3),
  1028. ::testing::AnyOf(m4, m5, m6, m7));
  1029. }
  1030. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  1031. typename M6, typename M7, typename M8>
  1032. inline typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type
  1033. AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8) {
  1034. return typename internal::AnyOfResult8<M1, M2, M3, M4, M5, M6, M7, M8>::type(
  1035. ::testing::AnyOf(m1, m2, m3, m4),
  1036. ::testing::AnyOf(m5, m6, m7, m8));
  1037. }
  1038. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  1039. typename M6, typename M7, typename M8, typename M9>
  1040. inline typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8, M9>::type
  1041. AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9) {
  1042. return typename internal::AnyOfResult9<M1, M2, M3, M4, M5, M6, M7, M8,
  1043. M9>::type(
  1044. ::testing::AnyOf(m1, m2, m3, m4),
  1045. ::testing::AnyOf(m5, m6, m7, m8, m9));
  1046. }
  1047. template <typename M1, typename M2, typename M3, typename M4, typename M5,
  1048. typename M6, typename M7, typename M8, typename M9, typename M10>
  1049. inline typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
  1050. M10>::type
  1051. AnyOf(M1 m1, M2 m2, M3 m3, M4 m4, M5 m5, M6 m6, M7 m7, M8 m8, M9 m9, M10 m10) {
  1052. return typename internal::AnyOfResult10<M1, M2, M3, M4, M5, M6, M7, M8, M9,
  1053. M10>::type(
  1054. ::testing::AnyOf(m1, m2, m3, m4, m5),
  1055. ::testing::AnyOf(m6, m7, m8, m9, m10));
  1056. }
  1057. } // namespace testing
  1058. // The MATCHER* family of macros can be used in a namespace scope to
  1059. // define custom matchers easily.
  1060. //
  1061. // Basic Usage
  1062. // ===========
  1063. //
  1064. // The syntax
  1065. //
  1066. // MATCHER(name, description_string) { statements; }
  1067. //
  1068. // defines a matcher with the given name that executes the statements,
  1069. // which must return a bool to indicate if the match succeeds. Inside
  1070. // the statements, you can refer to the value being matched by 'arg',
  1071. // and refer to its type by 'arg_type'.
  1072. //
  1073. // The description string documents what the matcher does, and is used
  1074. // to generate the failure message when the match fails. Since a
  1075. // MATCHER() is usually defined in a header file shared by multiple
  1076. // C++ source files, we require the description to be a C-string
  1077. // literal to avoid possible side effects. It can be empty, in which
  1078. // case we'll use the sequence of words in the matcher name as the
  1079. // description.
  1080. //
  1081. // For example:
  1082. //
  1083. // MATCHER(IsEven, "") { return (arg % 2) == 0; }
  1084. //
  1085. // allows you to write
  1086. //
  1087. // // Expects mock_foo.Bar(n) to be called where n is even.
  1088. // EXPECT_CALL(mock_foo, Bar(IsEven()));
  1089. //
  1090. // or,
  1091. //
  1092. // // Verifies that the value of some_expression is even.
  1093. // EXPECT_THAT(some_expression, IsEven());
  1094. //
  1095. // If the above assertion fails, it will print something like:
  1096. //
  1097. // Value of: some_expression
  1098. // Expected: is even
  1099. // Actual: 7
  1100. //
  1101. // where the description "is even" is automatically calculated from the
  1102. // matcher name IsEven.
  1103. //
  1104. // Argument Type
  1105. // =============
  1106. //
  1107. // Note that the type of the value being matched (arg_type) is
  1108. // determined by the context in which you use the matcher and is
  1109. // supplied to you by the compiler, so you don't need to worry about
  1110. // declaring it (nor can you). This allows the matcher to be
  1111. // polymorphic. For example, IsEven() can be used to match any type
  1112. // where the value of "(arg % 2) == 0" can be implicitly converted to
  1113. // a bool. In the "Bar(IsEven())" example above, if method Bar()
  1114. // takes an int, 'arg_type' will be int; if it takes an unsigned long,
  1115. // 'arg_type' will be unsigned long; and so on.
  1116. //
  1117. // Parameterizing Matchers
  1118. // =======================
  1119. //
  1120. // Sometimes you'll want to parameterize the matcher. For that you
  1121. // can use another macro:
  1122. //
  1123. // MATCHER_P(name, param_name, description_string) { statements; }
  1124. //
  1125. // For example:
  1126. //
  1127. // MATCHER_P(HasAbsoluteValue, value, "") { return abs(arg) == value; }
  1128. //
  1129. // will allow you to write:
  1130. //
  1131. // EXPECT_THAT(Blah("a"), HasAbsoluteValue(n));
  1132. //
  1133. // which may lead to this message (assuming n is 10):
  1134. //
  1135. // Value of: Blah("a")
  1136. // Expected: has absolute value 10
  1137. // Actual: -9
  1138. //
  1139. // Note that both the matcher description and its parameter are
  1140. // printed, making the message human-friendly.
  1141. //
  1142. // In the matcher definition body, you can write 'foo_type' to
  1143. // reference the type of a parameter named 'foo'. For example, in the
  1144. // body of MATCHER_P(HasAbsoluteValue, value) above, you can write
  1145. // 'value_type' to refer to the type of 'value'.
  1146. //
  1147. // We also provide MATCHER_P2, MATCHER_P3, ..., up to MATCHER_P10 to
  1148. // support multi-parameter matchers.
  1149. //
  1150. // Describing Parameterized Matchers
  1151. // =================================
  1152. //
  1153. // The last argument to MATCHER*() is a string-typed expression. The
  1154. // expression can reference all of the matcher's parameters and a
  1155. // special bool-typed variable named 'negation'. When 'negation' is
  1156. // false, the expression should evaluate to the matcher's description;
  1157. // otherwise it should evaluate to the description of the negation of
  1158. // the matcher. For example,
  1159. //
  1160. // using testing::PrintToString;
  1161. //
  1162. // MATCHER_P2(InClosedRange, low, hi,
  1163. // string(negation ? "is not" : "is") + " in range [" +
  1164. // PrintToString(low) + ", " + PrintToString(hi) + "]") {
  1165. // return low <= arg && arg <= hi;
  1166. // }
  1167. // ...
  1168. // EXPECT_THAT(3, InClosedRange(4, 6));
  1169. // EXPECT_THAT(3, Not(InClosedRange(2, 4)));
  1170. //
  1171. // would generate two failures that contain the text:
  1172. //
  1173. // Expected: is in range [4, 6]
  1174. // ...
  1175. // Expected: is not in range [2, 4]
  1176. //
  1177. // If you specify "" as the description, the failure message will
  1178. // contain the sequence of words in the matcher name followed by the
  1179. // parameter values printed as a tuple. For example,
  1180. //
  1181. // MATCHER_P2(InClosedRange, low, hi, "") { ... }
  1182. // ...
  1183. // EXPECT_THAT(3, InClosedRange(4, 6));
  1184. // EXPECT_THAT(3, Not(InClosedRange(2, 4)));
  1185. //
  1186. // would generate two failures that contain the text:
  1187. //
  1188. // Expected: in closed range (4, 6)
  1189. // ...
  1190. // Expected: not (in closed range (2, 4))
  1191. //
  1192. // Types of Matcher Parameters
  1193. // ===========================
  1194. //
  1195. // For the purpose of typing, you can view
  1196. //
  1197. // MATCHER_Pk(Foo, p1, ..., pk, description_string) { ... }
  1198. //
  1199. // as shorthand for
  1200. //
  1201. // template <typename p1_type, ..., typename pk_type>
  1202. // FooMatcherPk<p1_type, ..., pk_type>
  1203. // Foo(p1_type p1, ..., pk_type pk) { ... }
  1204. //
  1205. // When you write Foo(v1, ..., vk), the compiler infers the types of
  1206. // the parameters v1, ..., and vk for you. If you are not happy with
  1207. // the result of the type inference, you can specify the types by
  1208. // explicitly instantiating the template, as in Foo<long, bool>(5,
  1209. // false). As said earlier, you don't get to (or need to) specify
  1210. // 'arg_type' as that's determined by the context in which the matcher
  1211. // is used. You can assign the result of expression Foo(p1, ..., pk)
  1212. // to a variable of type FooMatcherPk<p1_type, ..., pk_type>. This
  1213. // can be useful when composing matchers.
  1214. //
  1215. // While you can instantiate a matcher template with reference types,
  1216. // passing the parameters by pointer usually makes your code more
  1217. // readable. If, however, you still want to pass a parameter by
  1218. // reference, be aware that in the failure message generated by the
  1219. // matcher you will see the value of the referenced object but not its
  1220. // address.
  1221. //
  1222. // Explaining Match Results
  1223. // ========================
  1224. //
  1225. // Sometimes the matcher description alone isn't enough to explain why
  1226. // the match has failed or succeeded. For example, when expecting a
  1227. // long string, it can be very helpful to also print the diff between
  1228. // the expected string and the actual one. To achieve that, you can
  1229. // optionally stream additional information to a special variable
  1230. // named result_listener, whose type is a pointer to class
  1231. // MatchResultListener:
  1232. //
  1233. // MATCHER_P(EqualsLongString, str, "") {
  1234. // if (arg == str) return true;
  1235. //
  1236. // *result_listener << "the difference: "
  1237. /// << DiffStrings(str, arg);
  1238. // return false;
  1239. // }
  1240. //
  1241. // Overloading Matchers
  1242. // ====================
  1243. //
  1244. // You can overload matchers with different numbers of parameters:
  1245. //
  1246. // MATCHER_P(Blah, a, description_string1) { ... }
  1247. // MATCHER_P2(Blah, a, b, description_string2) { ... }
  1248. //
  1249. // Caveats
  1250. // =======
  1251. //
  1252. // When defining a new matcher, you should also consider implementing
  1253. // MatcherInterface or using MakePolymorphicMatcher(). These
  1254. // approaches require more work than the MATCHER* macros, but also
  1255. // give you more control on the types of the value being matched and
  1256. // the matcher parameters, which may leads to better compiler error
  1257. // messages when the matcher is used wrong. They also allow
  1258. // overloading matchers based on parameter types (as opposed to just
  1259. // based on the number of parameters).
  1260. //
  1261. // MATCHER*() can only be used in a namespace scope. The reason is
  1262. // that C++ doesn't yet allow function-local types to be used to
  1263. // instantiate templates. The up-coming C++0x standard will fix this.
  1264. // Once that's done, we'll consider supporting using MATCHER*() inside
  1265. // a function.
  1266. //
  1267. // More Information
  1268. // ================
  1269. //
  1270. // To learn more about using these macros, please search for 'MATCHER'
  1271. // on http://code.google.com/p/googlemock/wiki/CookBook.
  1272. #define MATCHER(name, description)\
  1273. class name##Matcher {\
  1274. public:\
  1275. template <typename arg_type>\
  1276. class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
  1277. public:\
  1278. gmock_Impl()\
  1279. {}\
  1280. virtual bool MatchAndExplain(\
  1281. arg_type arg, ::testing::MatchResultListener* result_listener) const;\
  1282. virtual void DescribeTo(::std::ostream* gmock_os) const {\
  1283. *gmock_os << FormatDescription(false);\
  1284. }\
  1285. virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
  1286. *gmock_os << FormatDescription(true);\
  1287. }\
  1288. private:\
  1289. ::testing::internal::string FormatDescription(bool negation) const {\
  1290. const ::testing::internal::string gmock_description = (description);\
  1291. if (!gmock_description.empty())\
  1292. return gmock_description;\
  1293. return ::testing::internal::FormatMatcherDescription(\
  1294. negation, #name, \
  1295. ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
  1296. ::std::tr1::tuple<>()));\
  1297. }\
  1298. GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
  1299. };\
  1300. template <typename arg_type>\
  1301. operator ::testing::Matcher<arg_type>() const {\
  1302. return ::testing::Matcher<arg_type>(\
  1303. new gmock_Impl<arg_type>());\
  1304. }\
  1305. name##Matcher() {\
  1306. }\
  1307. private:\
  1308. GTEST_DISALLOW_ASSIGN_(name##Matcher);\
  1309. };\
  1310. inline name##Matcher name() {\
  1311. return name##Matcher();\
  1312. }\
  1313. template <typename arg_type>\
  1314. bool name##Matcher::gmock_Impl<arg_type>::MatchAndExplain(\
  1315. arg_type arg, \
  1316. ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
  1317. const
  1318. #define MATCHER_P(name, p0, description)\
  1319. template <typename p0##_type>\
  1320. class name##MatcherP {\
  1321. public:\
  1322. template <typename arg_type>\
  1323. class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
  1324. public:\
  1325. explicit gmock_Impl(p0##_type gmock_p0)\
  1326. : p0(gmock_p0) {}\
  1327. virtual bool MatchAndExplain(\
  1328. arg_type arg, ::testing::MatchResultListener* result_listener) const;\
  1329. virtual void DescribeTo(::std::ostream* gmock_os) const {\
  1330. *gmock_os << FormatDescription(false);\
  1331. }\
  1332. virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
  1333. *gmock_os << FormatDescription(true);\
  1334. }\
  1335. p0##_type p0;\
  1336. private:\
  1337. ::testing::internal::string FormatDescription(bool negation) const {\
  1338. const ::testing::internal::string gmock_description = (description);\
  1339. if (!gmock_description.empty())\
  1340. return gmock_description;\
  1341. return ::testing::internal::FormatMatcherDescription(\
  1342. negation, #name, \
  1343. ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
  1344. ::std::tr1::tuple<p0##_type>(p0)));\
  1345. }\
  1346. GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
  1347. };\
  1348. template <typename arg_type>\
  1349. operator ::testing::Matcher<arg_type>() const {\
  1350. return ::testing::Matcher<arg_type>(\
  1351. new gmock_Impl<arg_type>(p0));\
  1352. }\
  1353. name##MatcherP(p0##_type gmock_p0) : p0(gmock_p0) {\
  1354. }\
  1355. p0##_type p0;\
  1356. private:\
  1357. GTEST_DISALLOW_ASSIGN_(name##MatcherP);\
  1358. };\
  1359. template <typename p0##_type>\
  1360. inline name##MatcherP<p0##_type> name(p0##_type p0) {\
  1361. return name##MatcherP<p0##_type>(p0);\
  1362. }\
  1363. template <typename p0##_type>\
  1364. template <typename arg_type>\
  1365. bool name##MatcherP<p0##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
  1366. arg_type arg, \
  1367. ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
  1368. const
  1369. #define MATCHER_P2(name, p0, p1, description)\
  1370. template <typename p0##_type, typename p1##_type>\
  1371. class name##MatcherP2 {\
  1372. public:\
  1373. template <typename arg_type>\
  1374. class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
  1375. public:\
  1376. gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1)\
  1377. : p0(gmock_p0), p1(gmock_p1) {}\
  1378. virtual bool MatchAndExplain(\
  1379. arg_type arg, ::testing::MatchResultListener* result_listener) const;\
  1380. virtual void DescribeTo(::std::ostream* gmock_os) const {\
  1381. *gmock_os << FormatDescription(false);\
  1382. }\
  1383. virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
  1384. *gmock_os << FormatDescription(true);\
  1385. }\
  1386. p0##_type p0;\
  1387. p1##_type p1;\
  1388. private:\
  1389. ::testing::internal::string FormatDescription(bool negation) const {\
  1390. const ::testing::internal::string gmock_description = (description);\
  1391. if (!gmock_description.empty())\
  1392. return gmock_description;\
  1393. return ::testing::internal::FormatMatcherDescription(\
  1394. negation, #name, \
  1395. ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
  1396. ::std::tr1::tuple<p0##_type, p1##_type>(p0, p1)));\
  1397. }\
  1398. GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
  1399. };\
  1400. template <typename arg_type>\
  1401. operator ::testing::Matcher<arg_type>() const {\
  1402. return ::testing::Matcher<arg_type>(\
  1403. new gmock_Impl<arg_type>(p0, p1));\
  1404. }\
  1405. name##MatcherP2(p0##_type gmock_p0, p1##_type gmock_p1) : p0(gmock_p0), \
  1406. p1(gmock_p1) {\
  1407. }\
  1408. p0##_type p0;\
  1409. p1##_type p1;\
  1410. private:\
  1411. GTEST_DISALLOW_ASSIGN_(name##MatcherP2);\
  1412. };\
  1413. template <typename p0##_type, typename p1##_type>\
  1414. inline name##MatcherP2<p0##_type, p1##_type> name(p0##_type p0, \
  1415. p1##_type p1) {\
  1416. return name##MatcherP2<p0##_type, p1##_type>(p0, p1);\
  1417. }\
  1418. template <typename p0##_type, typename p1##_type>\
  1419. template <typename arg_type>\
  1420. bool name##MatcherP2<p0##_type, \
  1421. p1##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
  1422. arg_type arg, \
  1423. ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
  1424. const
  1425. #define MATCHER_P3(name, p0, p1, p2, description)\
  1426. template <typename p0##_type, typename p1##_type, typename p2##_type>\
  1427. class name##MatcherP3 {\
  1428. public:\
  1429. template <typename arg_type>\
  1430. class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
  1431. public:\
  1432. gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2)\
  1433. : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {}\
  1434. virtual bool MatchAndExplain(\
  1435. arg_type arg, ::testing::MatchResultListener* result_listener) const;\
  1436. virtual void DescribeTo(::std::ostream* gmock_os) const {\
  1437. *gmock_os << FormatDescription(false);\
  1438. }\
  1439. virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
  1440. *gmock_os << FormatDescription(true);\
  1441. }\
  1442. p0##_type p0;\
  1443. p1##_type p1;\
  1444. p2##_type p2;\
  1445. private:\
  1446. ::testing::internal::string FormatDescription(bool negation) const {\
  1447. const ::testing::internal::string gmock_description = (description);\
  1448. if (!gmock_description.empty())\
  1449. return gmock_description;\
  1450. return ::testing::internal::FormatMatcherDescription(\
  1451. negation, #name, \
  1452. ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
  1453. ::std::tr1::tuple<p0##_type, p1##_type, p2##_type>(p0, p1, \
  1454. p2)));\
  1455. }\
  1456. GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
  1457. };\
  1458. template <typename arg_type>\
  1459. operator ::testing::Matcher<arg_type>() const {\
  1460. return ::testing::Matcher<arg_type>(\
  1461. new gmock_Impl<arg_type>(p0, p1, p2));\
  1462. }\
  1463. name##MatcherP3(p0##_type gmock_p0, p1##_type gmock_p1, \
  1464. p2##_type gmock_p2) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2) {\
  1465. }\
  1466. p0##_type p0;\
  1467. p1##_type p1;\
  1468. p2##_type p2;\
  1469. private:\
  1470. GTEST_DISALLOW_ASSIGN_(name##MatcherP3);\
  1471. };\
  1472. template <typename p0##_type, typename p1##_type, typename p2##_type>\
  1473. inline name##MatcherP3<p0##_type, p1##_type, p2##_type> name(p0##_type p0, \
  1474. p1##_type p1, p2##_type p2) {\
  1475. return name##MatcherP3<p0##_type, p1##_type, p2##_type>(p0, p1, p2);\
  1476. }\
  1477. template <typename p0##_type, typename p1##_type, typename p2##_type>\
  1478. template <typename arg_type>\
  1479. bool name##MatcherP3<p0##_type, p1##_type, \
  1480. p2##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
  1481. arg_type arg, \
  1482. ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
  1483. const
  1484. #define MATCHER_P4(name, p0, p1, p2, p3, description)\
  1485. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1486. typename p3##_type>\
  1487. class name##MatcherP4 {\
  1488. public:\
  1489. template <typename arg_type>\
  1490. class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
  1491. public:\
  1492. gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
  1493. p3##_type gmock_p3)\
  1494. : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3) {}\
  1495. virtual bool MatchAndExplain(\
  1496. arg_type arg, ::testing::MatchResultListener* result_listener) const;\
  1497. virtual void DescribeTo(::std::ostream* gmock_os) const {\
  1498. *gmock_os << FormatDescription(false);\
  1499. }\
  1500. virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
  1501. *gmock_os << FormatDescription(true);\
  1502. }\
  1503. p0##_type p0;\
  1504. p1##_type p1;\
  1505. p2##_type p2;\
  1506. p3##_type p3;\
  1507. private:\
  1508. ::testing::internal::string FormatDescription(bool negation) const {\
  1509. const ::testing::internal::string gmock_description = (description);\
  1510. if (!gmock_description.empty())\
  1511. return gmock_description;\
  1512. return ::testing::internal::FormatMatcherDescription(\
  1513. negation, #name, \
  1514. ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
  1515. ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, \
  1516. p3##_type>(p0, p1, p2, p3)));\
  1517. }\
  1518. GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
  1519. };\
  1520. template <typename arg_type>\
  1521. operator ::testing::Matcher<arg_type>() const {\
  1522. return ::testing::Matcher<arg_type>(\
  1523. new gmock_Impl<arg_type>(p0, p1, p2, p3));\
  1524. }\
  1525. name##MatcherP4(p0##_type gmock_p0, p1##_type gmock_p1, \
  1526. p2##_type gmock_p2, p3##_type gmock_p3) : p0(gmock_p0), p1(gmock_p1), \
  1527. p2(gmock_p2), p3(gmock_p3) {\
  1528. }\
  1529. p0##_type p0;\
  1530. p1##_type p1;\
  1531. p2##_type p2;\
  1532. p3##_type p3;\
  1533. private:\
  1534. GTEST_DISALLOW_ASSIGN_(name##MatcherP4);\
  1535. };\
  1536. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1537. typename p3##_type>\
  1538. inline name##MatcherP4<p0##_type, p1##_type, p2##_type, \
  1539. p3##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
  1540. p3##_type p3) {\
  1541. return name##MatcherP4<p0##_type, p1##_type, p2##_type, p3##_type>(p0, \
  1542. p1, p2, p3);\
  1543. }\
  1544. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1545. typename p3##_type>\
  1546. template <typename arg_type>\
  1547. bool name##MatcherP4<p0##_type, p1##_type, p2##_type, \
  1548. p3##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
  1549. arg_type arg, \
  1550. ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
  1551. const
  1552. #define MATCHER_P5(name, p0, p1, p2, p3, p4, description)\
  1553. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1554. typename p3##_type, typename p4##_type>\
  1555. class name##MatcherP5 {\
  1556. public:\
  1557. template <typename arg_type>\
  1558. class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
  1559. public:\
  1560. gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
  1561. p3##_type gmock_p3, p4##_type gmock_p4)\
  1562. : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
  1563. p4(gmock_p4) {}\
  1564. virtual bool MatchAndExplain(\
  1565. arg_type arg, ::testing::MatchResultListener* result_listener) const;\
  1566. virtual void DescribeTo(::std::ostream* gmock_os) const {\
  1567. *gmock_os << FormatDescription(false);\
  1568. }\
  1569. virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
  1570. *gmock_os << FormatDescription(true);\
  1571. }\
  1572. p0##_type p0;\
  1573. p1##_type p1;\
  1574. p2##_type p2;\
  1575. p3##_type p3;\
  1576. p4##_type p4;\
  1577. private:\
  1578. ::testing::internal::string FormatDescription(bool negation) const {\
  1579. const ::testing::internal::string gmock_description = (description);\
  1580. if (!gmock_description.empty())\
  1581. return gmock_description;\
  1582. return ::testing::internal::FormatMatcherDescription(\
  1583. negation, #name, \
  1584. ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
  1585. ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
  1586. p4##_type>(p0, p1, p2, p3, p4)));\
  1587. }\
  1588. GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
  1589. };\
  1590. template <typename arg_type>\
  1591. operator ::testing::Matcher<arg_type>() const {\
  1592. return ::testing::Matcher<arg_type>(\
  1593. new gmock_Impl<arg_type>(p0, p1, p2, p3, p4));\
  1594. }\
  1595. name##MatcherP5(p0##_type gmock_p0, p1##_type gmock_p1, \
  1596. p2##_type gmock_p2, p3##_type gmock_p3, \
  1597. p4##_type gmock_p4) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
  1598. p3(gmock_p3), p4(gmock_p4) {\
  1599. }\
  1600. p0##_type p0;\
  1601. p1##_type p1;\
  1602. p2##_type p2;\
  1603. p3##_type p3;\
  1604. p4##_type p4;\
  1605. private:\
  1606. GTEST_DISALLOW_ASSIGN_(name##MatcherP5);\
  1607. };\
  1608. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1609. typename p3##_type, typename p4##_type>\
  1610. inline name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
  1611. p4##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
  1612. p4##_type p4) {\
  1613. return name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
  1614. p4##_type>(p0, p1, p2, p3, p4);\
  1615. }\
  1616. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1617. typename p3##_type, typename p4##_type>\
  1618. template <typename arg_type>\
  1619. bool name##MatcherP5<p0##_type, p1##_type, p2##_type, p3##_type, \
  1620. p4##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
  1621. arg_type arg, \
  1622. ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
  1623. const
  1624. #define MATCHER_P6(name, p0, p1, p2, p3, p4, p5, description)\
  1625. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1626. typename p3##_type, typename p4##_type, typename p5##_type>\
  1627. class name##MatcherP6 {\
  1628. public:\
  1629. template <typename arg_type>\
  1630. class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
  1631. public:\
  1632. gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
  1633. p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5)\
  1634. : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
  1635. p4(gmock_p4), p5(gmock_p5) {}\
  1636. virtual bool MatchAndExplain(\
  1637. arg_type arg, ::testing::MatchResultListener* result_listener) const;\
  1638. virtual void DescribeTo(::std::ostream* gmock_os) const {\
  1639. *gmock_os << FormatDescription(false);\
  1640. }\
  1641. virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
  1642. *gmock_os << FormatDescription(true);\
  1643. }\
  1644. p0##_type p0;\
  1645. p1##_type p1;\
  1646. p2##_type p2;\
  1647. p3##_type p3;\
  1648. p4##_type p4;\
  1649. p5##_type p5;\
  1650. private:\
  1651. ::testing::internal::string FormatDescription(bool negation) const {\
  1652. const ::testing::internal::string gmock_description = (description);\
  1653. if (!gmock_description.empty())\
  1654. return gmock_description;\
  1655. return ::testing::internal::FormatMatcherDescription(\
  1656. negation, #name, \
  1657. ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
  1658. ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
  1659. p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5)));\
  1660. }\
  1661. GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
  1662. };\
  1663. template <typename arg_type>\
  1664. operator ::testing::Matcher<arg_type>() const {\
  1665. return ::testing::Matcher<arg_type>(\
  1666. new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5));\
  1667. }\
  1668. name##MatcherP6(p0##_type gmock_p0, p1##_type gmock_p1, \
  1669. p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
  1670. p5##_type gmock_p5) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
  1671. p3(gmock_p3), p4(gmock_p4), p5(gmock_p5) {\
  1672. }\
  1673. p0##_type p0;\
  1674. p1##_type p1;\
  1675. p2##_type p2;\
  1676. p3##_type p3;\
  1677. p4##_type p4;\
  1678. p5##_type p5;\
  1679. private:\
  1680. GTEST_DISALLOW_ASSIGN_(name##MatcherP6);\
  1681. };\
  1682. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1683. typename p3##_type, typename p4##_type, typename p5##_type>\
  1684. inline name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
  1685. p4##_type, p5##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, \
  1686. p3##_type p3, p4##_type p4, p5##_type p5) {\
  1687. return name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, \
  1688. p4##_type, p5##_type>(p0, p1, p2, p3, p4, p5);\
  1689. }\
  1690. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1691. typename p3##_type, typename p4##_type, typename p5##_type>\
  1692. template <typename arg_type>\
  1693. bool name##MatcherP6<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
  1694. p5##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
  1695. arg_type arg, \
  1696. ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
  1697. const
  1698. #define MATCHER_P7(name, p0, p1, p2, p3, p4, p5, p6, description)\
  1699. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1700. typename p3##_type, typename p4##_type, typename p5##_type, \
  1701. typename p6##_type>\
  1702. class name##MatcherP7 {\
  1703. public:\
  1704. template <typename arg_type>\
  1705. class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
  1706. public:\
  1707. gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
  1708. p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
  1709. p6##_type gmock_p6)\
  1710. : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
  1711. p4(gmock_p4), p5(gmock_p5), p6(gmock_p6) {}\
  1712. virtual bool MatchAndExplain(\
  1713. arg_type arg, ::testing::MatchResultListener* result_listener) const;\
  1714. virtual void DescribeTo(::std::ostream* gmock_os) const {\
  1715. *gmock_os << FormatDescription(false);\
  1716. }\
  1717. virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
  1718. *gmock_os << FormatDescription(true);\
  1719. }\
  1720. p0##_type p0;\
  1721. p1##_type p1;\
  1722. p2##_type p2;\
  1723. p3##_type p3;\
  1724. p4##_type p4;\
  1725. p5##_type p5;\
  1726. p6##_type p6;\
  1727. private:\
  1728. ::testing::internal::string FormatDescription(bool negation) const {\
  1729. const ::testing::internal::string gmock_description = (description);\
  1730. if (!gmock_description.empty())\
  1731. return gmock_description;\
  1732. return ::testing::internal::FormatMatcherDescription(\
  1733. negation, #name, \
  1734. ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
  1735. ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
  1736. p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, \
  1737. p6)));\
  1738. }\
  1739. GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
  1740. };\
  1741. template <typename arg_type>\
  1742. operator ::testing::Matcher<arg_type>() const {\
  1743. return ::testing::Matcher<arg_type>(\
  1744. new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6));\
  1745. }\
  1746. name##MatcherP7(p0##_type gmock_p0, p1##_type gmock_p1, \
  1747. p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
  1748. p5##_type gmock_p5, p6##_type gmock_p6) : p0(gmock_p0), p1(gmock_p1), \
  1749. p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), \
  1750. p6(gmock_p6) {\
  1751. }\
  1752. p0##_type p0;\
  1753. p1##_type p1;\
  1754. p2##_type p2;\
  1755. p3##_type p3;\
  1756. p4##_type p4;\
  1757. p5##_type p5;\
  1758. p6##_type p6;\
  1759. private:\
  1760. GTEST_DISALLOW_ASSIGN_(name##MatcherP7);\
  1761. };\
  1762. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1763. typename p3##_type, typename p4##_type, typename p5##_type, \
  1764. typename p6##_type>\
  1765. inline name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
  1766. p4##_type, p5##_type, p6##_type> name(p0##_type p0, p1##_type p1, \
  1767. p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
  1768. p6##_type p6) {\
  1769. return name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, \
  1770. p4##_type, p5##_type, p6##_type>(p0, p1, p2, p3, p4, p5, p6);\
  1771. }\
  1772. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1773. typename p3##_type, typename p4##_type, typename p5##_type, \
  1774. typename p6##_type>\
  1775. template <typename arg_type>\
  1776. bool name##MatcherP7<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
  1777. p5##_type, p6##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
  1778. arg_type arg, \
  1779. ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
  1780. const
  1781. #define MATCHER_P8(name, p0, p1, p2, p3, p4, p5, p6, p7, description)\
  1782. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1783. typename p3##_type, typename p4##_type, typename p5##_type, \
  1784. typename p6##_type, typename p7##_type>\
  1785. class name##MatcherP8 {\
  1786. public:\
  1787. template <typename arg_type>\
  1788. class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
  1789. public:\
  1790. gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
  1791. p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
  1792. p6##_type gmock_p6, p7##_type gmock_p7)\
  1793. : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
  1794. p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7) {}\
  1795. virtual bool MatchAndExplain(\
  1796. arg_type arg, ::testing::MatchResultListener* result_listener) const;\
  1797. virtual void DescribeTo(::std::ostream* gmock_os) const {\
  1798. *gmock_os << FormatDescription(false);\
  1799. }\
  1800. virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
  1801. *gmock_os << FormatDescription(true);\
  1802. }\
  1803. p0##_type p0;\
  1804. p1##_type p1;\
  1805. p2##_type p2;\
  1806. p3##_type p3;\
  1807. p4##_type p4;\
  1808. p5##_type p5;\
  1809. p6##_type p6;\
  1810. p7##_type p7;\
  1811. private:\
  1812. ::testing::internal::string FormatDescription(bool negation) const {\
  1813. const ::testing::internal::string gmock_description = (description);\
  1814. if (!gmock_description.empty())\
  1815. return gmock_description;\
  1816. return ::testing::internal::FormatMatcherDescription(\
  1817. negation, #name, \
  1818. ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
  1819. ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
  1820. p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, \
  1821. p3, p4, p5, p6, p7)));\
  1822. }\
  1823. GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
  1824. };\
  1825. template <typename arg_type>\
  1826. operator ::testing::Matcher<arg_type>() const {\
  1827. return ::testing::Matcher<arg_type>(\
  1828. new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7));\
  1829. }\
  1830. name##MatcherP8(p0##_type gmock_p0, p1##_type gmock_p1, \
  1831. p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
  1832. p5##_type gmock_p5, p6##_type gmock_p6, \
  1833. p7##_type gmock_p7) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
  1834. p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
  1835. p7(gmock_p7) {\
  1836. }\
  1837. p0##_type p0;\
  1838. p1##_type p1;\
  1839. p2##_type p2;\
  1840. p3##_type p3;\
  1841. p4##_type p4;\
  1842. p5##_type p5;\
  1843. p6##_type p6;\
  1844. p7##_type p7;\
  1845. private:\
  1846. GTEST_DISALLOW_ASSIGN_(name##MatcherP8);\
  1847. };\
  1848. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1849. typename p3##_type, typename p4##_type, typename p5##_type, \
  1850. typename p6##_type, typename p7##_type>\
  1851. inline name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
  1852. p4##_type, p5##_type, p6##_type, p7##_type> name(p0##_type p0, \
  1853. p1##_type p1, p2##_type p2, p3##_type p3, p4##_type p4, p5##_type p5, \
  1854. p6##_type p6, p7##_type p7) {\
  1855. return name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, \
  1856. p4##_type, p5##_type, p6##_type, p7##_type>(p0, p1, p2, p3, p4, p5, \
  1857. p6, p7);\
  1858. }\
  1859. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1860. typename p3##_type, typename p4##_type, typename p5##_type, \
  1861. typename p6##_type, typename p7##_type>\
  1862. template <typename arg_type>\
  1863. bool name##MatcherP8<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
  1864. p5##_type, p6##_type, \
  1865. p7##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
  1866. arg_type arg, \
  1867. ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
  1868. const
  1869. #define MATCHER_P9(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, description)\
  1870. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1871. typename p3##_type, typename p4##_type, typename p5##_type, \
  1872. typename p6##_type, typename p7##_type, typename p8##_type>\
  1873. class name##MatcherP9 {\
  1874. public:\
  1875. template <typename arg_type>\
  1876. class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
  1877. public:\
  1878. gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
  1879. p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
  1880. p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8)\
  1881. : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
  1882. p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
  1883. p8(gmock_p8) {}\
  1884. virtual bool MatchAndExplain(\
  1885. arg_type arg, ::testing::MatchResultListener* result_listener) const;\
  1886. virtual void DescribeTo(::std::ostream* gmock_os) const {\
  1887. *gmock_os << FormatDescription(false);\
  1888. }\
  1889. virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
  1890. *gmock_os << FormatDescription(true);\
  1891. }\
  1892. p0##_type p0;\
  1893. p1##_type p1;\
  1894. p2##_type p2;\
  1895. p3##_type p3;\
  1896. p4##_type p4;\
  1897. p5##_type p5;\
  1898. p6##_type p6;\
  1899. p7##_type p7;\
  1900. p8##_type p8;\
  1901. private:\
  1902. ::testing::internal::string FormatDescription(bool negation) const {\
  1903. const ::testing::internal::string gmock_description = (description);\
  1904. if (!gmock_description.empty())\
  1905. return gmock_description;\
  1906. return ::testing::internal::FormatMatcherDescription(\
  1907. negation, #name, \
  1908. ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
  1909. ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
  1910. p4##_type, p5##_type, p6##_type, p7##_type, \
  1911. p8##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8)));\
  1912. }\
  1913. GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
  1914. };\
  1915. template <typename arg_type>\
  1916. operator ::testing::Matcher<arg_type>() const {\
  1917. return ::testing::Matcher<arg_type>(\
  1918. new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8));\
  1919. }\
  1920. name##MatcherP9(p0##_type gmock_p0, p1##_type gmock_p1, \
  1921. p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
  1922. p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
  1923. p8##_type gmock_p8) : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), \
  1924. p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
  1925. p8(gmock_p8) {\
  1926. }\
  1927. p0##_type p0;\
  1928. p1##_type p1;\
  1929. p2##_type p2;\
  1930. p3##_type p3;\
  1931. p4##_type p4;\
  1932. p5##_type p5;\
  1933. p6##_type p6;\
  1934. p7##_type p7;\
  1935. p8##_type p8;\
  1936. private:\
  1937. GTEST_DISALLOW_ASSIGN_(name##MatcherP9);\
  1938. };\
  1939. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1940. typename p3##_type, typename p4##_type, typename p5##_type, \
  1941. typename p6##_type, typename p7##_type, typename p8##_type>\
  1942. inline name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
  1943. p4##_type, p5##_type, p6##_type, p7##_type, \
  1944. p8##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
  1945. p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, \
  1946. p8##_type p8) {\
  1947. return name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, \
  1948. p4##_type, p5##_type, p6##_type, p7##_type, p8##_type>(p0, p1, p2, \
  1949. p3, p4, p5, p6, p7, p8);\
  1950. }\
  1951. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1952. typename p3##_type, typename p4##_type, typename p5##_type, \
  1953. typename p6##_type, typename p7##_type, typename p8##_type>\
  1954. template <typename arg_type>\
  1955. bool name##MatcherP9<p0##_type, p1##_type, p2##_type, p3##_type, p4##_type, \
  1956. p5##_type, p6##_type, p7##_type, \
  1957. p8##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
  1958. arg_type arg, \
  1959. ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
  1960. const
  1961. #define MATCHER_P10(name, p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, description)\
  1962. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  1963. typename p3##_type, typename p4##_type, typename p5##_type, \
  1964. typename p6##_type, typename p7##_type, typename p8##_type, \
  1965. typename p9##_type>\
  1966. class name##MatcherP10 {\
  1967. public:\
  1968. template <typename arg_type>\
  1969. class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
  1970. public:\
  1971. gmock_Impl(p0##_type gmock_p0, p1##_type gmock_p1, p2##_type gmock_p2, \
  1972. p3##_type gmock_p3, p4##_type gmock_p4, p5##_type gmock_p5, \
  1973. p6##_type gmock_p6, p7##_type gmock_p7, p8##_type gmock_p8, \
  1974. p9##_type gmock_p9)\
  1975. : p0(gmock_p0), p1(gmock_p1), p2(gmock_p2), p3(gmock_p3), \
  1976. p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), p7(gmock_p7), \
  1977. p8(gmock_p8), p9(gmock_p9) {}\
  1978. virtual bool MatchAndExplain(\
  1979. arg_type arg, ::testing::MatchResultListener* result_listener) const;\
  1980. virtual void DescribeTo(::std::ostream* gmock_os) const {\
  1981. *gmock_os << FormatDescription(false);\
  1982. }\
  1983. virtual void DescribeNegationTo(::std::ostream* gmock_os) const {\
  1984. *gmock_os << FormatDescription(true);\
  1985. }\
  1986. p0##_type p0;\
  1987. p1##_type p1;\
  1988. p2##_type p2;\
  1989. p3##_type p3;\
  1990. p4##_type p4;\
  1991. p5##_type p5;\
  1992. p6##_type p6;\
  1993. p7##_type p7;\
  1994. p8##_type p8;\
  1995. p9##_type p9;\
  1996. private:\
  1997. ::testing::internal::string FormatDescription(bool negation) const {\
  1998. const ::testing::internal::string gmock_description = (description);\
  1999. if (!gmock_description.empty())\
  2000. return gmock_description;\
  2001. return ::testing::internal::FormatMatcherDescription(\
  2002. negation, #name, \
  2003. ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
  2004. ::std::tr1::tuple<p0##_type, p1##_type, p2##_type, p3##_type, \
  2005. p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
  2006. p9##_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9)));\
  2007. }\
  2008. GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
  2009. };\
  2010. template <typename arg_type>\
  2011. operator ::testing::Matcher<arg_type>() const {\
  2012. return ::testing::Matcher<arg_type>(\
  2013. new gmock_Impl<arg_type>(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9));\
  2014. }\
  2015. name##MatcherP10(p0##_type gmock_p0, p1##_type gmock_p1, \
  2016. p2##_type gmock_p2, p3##_type gmock_p3, p4##_type gmock_p4, \
  2017. p5##_type gmock_p5, p6##_type gmock_p6, p7##_type gmock_p7, \
  2018. p8##_type gmock_p8, p9##_type gmock_p9) : p0(gmock_p0), p1(gmock_p1), \
  2019. p2(gmock_p2), p3(gmock_p3), p4(gmock_p4), p5(gmock_p5), p6(gmock_p6), \
  2020. p7(gmock_p7), p8(gmock_p8), p9(gmock_p9) {\
  2021. }\
  2022. p0##_type p0;\
  2023. p1##_type p1;\
  2024. p2##_type p2;\
  2025. p3##_type p3;\
  2026. p4##_type p4;\
  2027. p5##_type p5;\
  2028. p6##_type p6;\
  2029. p7##_type p7;\
  2030. p8##_type p8;\
  2031. p9##_type p9;\
  2032. private:\
  2033. GTEST_DISALLOW_ASSIGN_(name##MatcherP10);\
  2034. };\
  2035. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  2036. typename p3##_type, typename p4##_type, typename p5##_type, \
  2037. typename p6##_type, typename p7##_type, typename p8##_type, \
  2038. typename p9##_type>\
  2039. inline name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
  2040. p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
  2041. p9##_type> name(p0##_type p0, p1##_type p1, p2##_type p2, p3##_type p3, \
  2042. p4##_type p4, p5##_type p5, p6##_type p6, p7##_type p7, p8##_type p8, \
  2043. p9##_type p9) {\
  2044. return name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
  2045. p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, p9##_type>(p0, \
  2046. p1, p2, p3, p4, p5, p6, p7, p8, p9);\
  2047. }\
  2048. template <typename p0##_type, typename p1##_type, typename p2##_type, \
  2049. typename p3##_type, typename p4##_type, typename p5##_type, \
  2050. typename p6##_type, typename p7##_type, typename p8##_type, \
  2051. typename p9##_type>\
  2052. template <typename arg_type>\
  2053. bool name##MatcherP10<p0##_type, p1##_type, p2##_type, p3##_type, \
  2054. p4##_type, p5##_type, p6##_type, p7##_type, p8##_type, \
  2055. p9##_type>::gmock_Impl<arg_type>::MatchAndExplain(\
  2056. arg_type arg, \
  2057. ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
  2058. const
  2059. #endif // GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_MATCHERS_H_