gtest_pred_impl_unittest.cc 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422
  1. // Copyright 2006, Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. // This file is AUTOMATICALLY GENERATED on 11/05/2019 by command
  30. // 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
  31. // Regression test for gtest_pred_impl.h
  32. //
  33. // This file is generated by a script and quite long. If you intend to
  34. // learn how Google Test works by reading its unit tests, read
  35. // gtest_unittest.cc instead.
  36. //
  37. // This is intended as a regression test for the Google Test predicate
  38. // assertions. We compile it as part of the gtest_unittest target
  39. // only to keep the implementation tidy and compact, as it is quite
  40. // involved to set up the stage for testing Google Test using Google
  41. // Test itself.
  42. //
  43. // Currently, gtest_unittest takes ~11 seconds to run in the testing
  44. // daemon. In the future, if it grows too large and needs much more
  45. // time to finish, we should consider separating this file into a
  46. // stand-alone regression test.
  47. #include <iostream>
  48. #include "gtest/gtest.h"
  49. #include "gtest/gtest-spi.h"
  50. // A user-defined data type.
  51. struct Bool {
  52. explicit Bool(int val) : value(val != 0) {}
  53. bool operator>(int n) const { return value > Bool(n).value; }
  54. Bool operator+(const Bool& rhs) const { return Bool(value + rhs.value); }
  55. bool operator==(const Bool& rhs) const { return value == rhs.value; }
  56. bool value;
  57. };
  58. // Enables Bool to be used in assertions.
  59. std::ostream& operator<<(std::ostream& os, const Bool& x) {
  60. return os << (x.value ? "true" : "false");
  61. }
  62. // Sample functions/functors for testing unary predicate assertions.
  63. // A unary predicate function.
  64. template <typename T1>
  65. bool PredFunction1(T1 v1) {
  66. return v1 > 0;
  67. }
  68. // The following two functions are needed because a compiler doesn't have
  69. // a context yet to know which template function must be instantiated.
  70. bool PredFunction1Int(int v1) {
  71. return v1 > 0;
  72. }
  73. bool PredFunction1Bool(Bool v1) {
  74. return v1 > 0;
  75. }
  76. // A unary predicate functor.
  77. struct PredFunctor1 {
  78. template <typename T1>
  79. bool operator()(const T1& v1) {
  80. return v1 > 0;
  81. }
  82. };
  83. // A unary predicate-formatter function.
  84. template <typename T1>
  85. testing::AssertionResult PredFormatFunction1(const char* e1,
  86. const T1& v1) {
  87. if (PredFunction1(v1))
  88. return testing::AssertionSuccess();
  89. return testing::AssertionFailure()
  90. << e1
  91. << " is expected to be positive, but evaluates to "
  92. << v1 << ".";
  93. }
  94. // A unary predicate-formatter functor.
  95. struct PredFormatFunctor1 {
  96. template <typename T1>
  97. testing::AssertionResult operator()(const char* e1,
  98. const T1& v1) const {
  99. return PredFormatFunction1(e1, v1);
  100. }
  101. };
  102. // Tests for {EXPECT|ASSERT}_PRED_FORMAT1.
  103. class Predicate1Test : public testing::Test {
  104. protected:
  105. void SetUp() override {
  106. expected_to_finish_ = true;
  107. finished_ = false;
  108. n1_ = 0;
  109. }
  110. void TearDown() override {
  111. // Verifies that each of the predicate's arguments was evaluated
  112. // exactly once.
  113. EXPECT_EQ(1, n1_) <<
  114. "The predicate assertion didn't evaluate argument 2 "
  115. "exactly once.";
  116. // Verifies that the control flow in the test function is expected.
  117. if (expected_to_finish_ && !finished_) {
  118. FAIL() << "The predicate assertion unexpactedly aborted the test.";
  119. } else if (!expected_to_finish_ && finished_) {
  120. FAIL() << "The failed predicate assertion didn't abort the test "
  121. "as expected.";
  122. }
  123. }
  124. // true if and only if the test function is expected to run to finish.
  125. static bool expected_to_finish_;
  126. // true if and only if the test function did run to finish.
  127. static bool finished_;
  128. static int n1_;
  129. };
  130. bool Predicate1Test::expected_to_finish_;
  131. bool Predicate1Test::finished_;
  132. int Predicate1Test::n1_;
  133. typedef Predicate1Test EXPECT_PRED_FORMAT1Test;
  134. typedef Predicate1Test ASSERT_PRED_FORMAT1Test;
  135. typedef Predicate1Test EXPECT_PRED1Test;
  136. typedef Predicate1Test ASSERT_PRED1Test;
  137. // Tests a successful EXPECT_PRED1 where the
  138. // predicate-formatter is a function on a built-in type (int).
  139. TEST_F(EXPECT_PRED1Test, FunctionOnBuiltInTypeSuccess) {
  140. EXPECT_PRED1(PredFunction1Int,
  141. ++n1_);
  142. finished_ = true;
  143. }
  144. // Tests a successful EXPECT_PRED1 where the
  145. // predicate-formatter is a function on a user-defined type (Bool).
  146. TEST_F(EXPECT_PRED1Test, FunctionOnUserTypeSuccess) {
  147. EXPECT_PRED1(PredFunction1Bool,
  148. Bool(++n1_));
  149. finished_ = true;
  150. }
  151. // Tests a successful EXPECT_PRED1 where the
  152. // predicate-formatter is a functor on a built-in type (int).
  153. TEST_F(EXPECT_PRED1Test, FunctorOnBuiltInTypeSuccess) {
  154. EXPECT_PRED1(PredFunctor1(),
  155. ++n1_);
  156. finished_ = true;
  157. }
  158. // Tests a successful EXPECT_PRED1 where the
  159. // predicate-formatter is a functor on a user-defined type (Bool).
  160. TEST_F(EXPECT_PRED1Test, FunctorOnUserTypeSuccess) {
  161. EXPECT_PRED1(PredFunctor1(),
  162. Bool(++n1_));
  163. finished_ = true;
  164. }
  165. // Tests a failed EXPECT_PRED1 where the
  166. // predicate-formatter is a function on a built-in type (int).
  167. TEST_F(EXPECT_PRED1Test, FunctionOnBuiltInTypeFailure) {
  168. EXPECT_NONFATAL_FAILURE({ // NOLINT
  169. EXPECT_PRED1(PredFunction1Int,
  170. n1_++);
  171. finished_ = true;
  172. }, "");
  173. }
  174. // Tests a failed EXPECT_PRED1 where the
  175. // predicate-formatter is a function on a user-defined type (Bool).
  176. TEST_F(EXPECT_PRED1Test, FunctionOnUserTypeFailure) {
  177. EXPECT_NONFATAL_FAILURE({ // NOLINT
  178. EXPECT_PRED1(PredFunction1Bool,
  179. Bool(n1_++));
  180. finished_ = true;
  181. }, "");
  182. }
  183. // Tests a failed EXPECT_PRED1 where the
  184. // predicate-formatter is a functor on a built-in type (int).
  185. TEST_F(EXPECT_PRED1Test, FunctorOnBuiltInTypeFailure) {
  186. EXPECT_NONFATAL_FAILURE({ // NOLINT
  187. EXPECT_PRED1(PredFunctor1(),
  188. n1_++);
  189. finished_ = true;
  190. }, "");
  191. }
  192. // Tests a failed EXPECT_PRED1 where the
  193. // predicate-formatter is a functor on a user-defined type (Bool).
  194. TEST_F(EXPECT_PRED1Test, FunctorOnUserTypeFailure) {
  195. EXPECT_NONFATAL_FAILURE({ // NOLINT
  196. EXPECT_PRED1(PredFunctor1(),
  197. Bool(n1_++));
  198. finished_ = true;
  199. }, "");
  200. }
  201. // Tests a successful ASSERT_PRED1 where the
  202. // predicate-formatter is a function on a built-in type (int).
  203. TEST_F(ASSERT_PRED1Test, FunctionOnBuiltInTypeSuccess) {
  204. ASSERT_PRED1(PredFunction1Int,
  205. ++n1_);
  206. finished_ = true;
  207. }
  208. // Tests a successful ASSERT_PRED1 where the
  209. // predicate-formatter is a function on a user-defined type (Bool).
  210. TEST_F(ASSERT_PRED1Test, FunctionOnUserTypeSuccess) {
  211. ASSERT_PRED1(PredFunction1Bool,
  212. Bool(++n1_));
  213. finished_ = true;
  214. }
  215. // Tests a successful ASSERT_PRED1 where the
  216. // predicate-formatter is a functor on a built-in type (int).
  217. TEST_F(ASSERT_PRED1Test, FunctorOnBuiltInTypeSuccess) {
  218. ASSERT_PRED1(PredFunctor1(),
  219. ++n1_);
  220. finished_ = true;
  221. }
  222. // Tests a successful ASSERT_PRED1 where the
  223. // predicate-formatter is a functor on a user-defined type (Bool).
  224. TEST_F(ASSERT_PRED1Test, FunctorOnUserTypeSuccess) {
  225. ASSERT_PRED1(PredFunctor1(),
  226. Bool(++n1_));
  227. finished_ = true;
  228. }
  229. // Tests a failed ASSERT_PRED1 where the
  230. // predicate-formatter is a function on a built-in type (int).
  231. TEST_F(ASSERT_PRED1Test, FunctionOnBuiltInTypeFailure) {
  232. expected_to_finish_ = false;
  233. EXPECT_FATAL_FAILURE({ // NOLINT
  234. ASSERT_PRED1(PredFunction1Int,
  235. n1_++);
  236. finished_ = true;
  237. }, "");
  238. }
  239. // Tests a failed ASSERT_PRED1 where the
  240. // predicate-formatter is a function on a user-defined type (Bool).
  241. TEST_F(ASSERT_PRED1Test, FunctionOnUserTypeFailure) {
  242. expected_to_finish_ = false;
  243. EXPECT_FATAL_FAILURE({ // NOLINT
  244. ASSERT_PRED1(PredFunction1Bool,
  245. Bool(n1_++));
  246. finished_ = true;
  247. }, "");
  248. }
  249. // Tests a failed ASSERT_PRED1 where the
  250. // predicate-formatter is a functor on a built-in type (int).
  251. TEST_F(ASSERT_PRED1Test, FunctorOnBuiltInTypeFailure) {
  252. expected_to_finish_ = false;
  253. EXPECT_FATAL_FAILURE({ // NOLINT
  254. ASSERT_PRED1(PredFunctor1(),
  255. n1_++);
  256. finished_ = true;
  257. }, "");
  258. }
  259. // Tests a failed ASSERT_PRED1 where the
  260. // predicate-formatter is a functor on a user-defined type (Bool).
  261. TEST_F(ASSERT_PRED1Test, FunctorOnUserTypeFailure) {
  262. expected_to_finish_ = false;
  263. EXPECT_FATAL_FAILURE({ // NOLINT
  264. ASSERT_PRED1(PredFunctor1(),
  265. Bool(n1_++));
  266. finished_ = true;
  267. }, "");
  268. }
  269. // Tests a successful EXPECT_PRED_FORMAT1 where the
  270. // predicate-formatter is a function on a built-in type (int).
  271. TEST_F(EXPECT_PRED_FORMAT1Test, FunctionOnBuiltInTypeSuccess) {
  272. EXPECT_PRED_FORMAT1(PredFormatFunction1,
  273. ++n1_);
  274. finished_ = true;
  275. }
  276. // Tests a successful EXPECT_PRED_FORMAT1 where the
  277. // predicate-formatter is a function on a user-defined type (Bool).
  278. TEST_F(EXPECT_PRED_FORMAT1Test, FunctionOnUserTypeSuccess) {
  279. EXPECT_PRED_FORMAT1(PredFormatFunction1,
  280. Bool(++n1_));
  281. finished_ = true;
  282. }
  283. // Tests a successful EXPECT_PRED_FORMAT1 where the
  284. // predicate-formatter is a functor on a built-in type (int).
  285. TEST_F(EXPECT_PRED_FORMAT1Test, FunctorOnBuiltInTypeSuccess) {
  286. EXPECT_PRED_FORMAT1(PredFormatFunctor1(),
  287. ++n1_);
  288. finished_ = true;
  289. }
  290. // Tests a successful EXPECT_PRED_FORMAT1 where the
  291. // predicate-formatter is a functor on a user-defined type (Bool).
  292. TEST_F(EXPECT_PRED_FORMAT1Test, FunctorOnUserTypeSuccess) {
  293. EXPECT_PRED_FORMAT1(PredFormatFunctor1(),
  294. Bool(++n1_));
  295. finished_ = true;
  296. }
  297. // Tests a failed EXPECT_PRED_FORMAT1 where the
  298. // predicate-formatter is a function on a built-in type (int).
  299. TEST_F(EXPECT_PRED_FORMAT1Test, FunctionOnBuiltInTypeFailure) {
  300. EXPECT_NONFATAL_FAILURE({ // NOLINT
  301. EXPECT_PRED_FORMAT1(PredFormatFunction1,
  302. n1_++);
  303. finished_ = true;
  304. }, "");
  305. }
  306. // Tests a failed EXPECT_PRED_FORMAT1 where the
  307. // predicate-formatter is a function on a user-defined type (Bool).
  308. TEST_F(EXPECT_PRED_FORMAT1Test, FunctionOnUserTypeFailure) {
  309. EXPECT_NONFATAL_FAILURE({ // NOLINT
  310. EXPECT_PRED_FORMAT1(PredFormatFunction1,
  311. Bool(n1_++));
  312. finished_ = true;
  313. }, "");
  314. }
  315. // Tests a failed EXPECT_PRED_FORMAT1 where the
  316. // predicate-formatter is a functor on a built-in type (int).
  317. TEST_F(EXPECT_PRED_FORMAT1Test, FunctorOnBuiltInTypeFailure) {
  318. EXPECT_NONFATAL_FAILURE({ // NOLINT
  319. EXPECT_PRED_FORMAT1(PredFormatFunctor1(),
  320. n1_++);
  321. finished_ = true;
  322. }, "");
  323. }
  324. // Tests a failed EXPECT_PRED_FORMAT1 where the
  325. // predicate-formatter is a functor on a user-defined type (Bool).
  326. TEST_F(EXPECT_PRED_FORMAT1Test, FunctorOnUserTypeFailure) {
  327. EXPECT_NONFATAL_FAILURE({ // NOLINT
  328. EXPECT_PRED_FORMAT1(PredFormatFunctor1(),
  329. Bool(n1_++));
  330. finished_ = true;
  331. }, "");
  332. }
  333. // Tests a successful ASSERT_PRED_FORMAT1 where the
  334. // predicate-formatter is a function on a built-in type (int).
  335. TEST_F(ASSERT_PRED_FORMAT1Test, FunctionOnBuiltInTypeSuccess) {
  336. ASSERT_PRED_FORMAT1(PredFormatFunction1,
  337. ++n1_);
  338. finished_ = true;
  339. }
  340. // Tests a successful ASSERT_PRED_FORMAT1 where the
  341. // predicate-formatter is a function on a user-defined type (Bool).
  342. TEST_F(ASSERT_PRED_FORMAT1Test, FunctionOnUserTypeSuccess) {
  343. ASSERT_PRED_FORMAT1(PredFormatFunction1,
  344. Bool(++n1_));
  345. finished_ = true;
  346. }
  347. // Tests a successful ASSERT_PRED_FORMAT1 where the
  348. // predicate-formatter is a functor on a built-in type (int).
  349. TEST_F(ASSERT_PRED_FORMAT1Test, FunctorOnBuiltInTypeSuccess) {
  350. ASSERT_PRED_FORMAT1(PredFormatFunctor1(),
  351. ++n1_);
  352. finished_ = true;
  353. }
  354. // Tests a successful ASSERT_PRED_FORMAT1 where the
  355. // predicate-formatter is a functor on a user-defined type (Bool).
  356. TEST_F(ASSERT_PRED_FORMAT1Test, FunctorOnUserTypeSuccess) {
  357. ASSERT_PRED_FORMAT1(PredFormatFunctor1(),
  358. Bool(++n1_));
  359. finished_ = true;
  360. }
  361. // Tests a failed ASSERT_PRED_FORMAT1 where the
  362. // predicate-formatter is a function on a built-in type (int).
  363. TEST_F(ASSERT_PRED_FORMAT1Test, FunctionOnBuiltInTypeFailure) {
  364. expected_to_finish_ = false;
  365. EXPECT_FATAL_FAILURE({ // NOLINT
  366. ASSERT_PRED_FORMAT1(PredFormatFunction1,
  367. n1_++);
  368. finished_ = true;
  369. }, "");
  370. }
  371. // Tests a failed ASSERT_PRED_FORMAT1 where the
  372. // predicate-formatter is a function on a user-defined type (Bool).
  373. TEST_F(ASSERT_PRED_FORMAT1Test, FunctionOnUserTypeFailure) {
  374. expected_to_finish_ = false;
  375. EXPECT_FATAL_FAILURE({ // NOLINT
  376. ASSERT_PRED_FORMAT1(PredFormatFunction1,
  377. Bool(n1_++));
  378. finished_ = true;
  379. }, "");
  380. }
  381. // Tests a failed ASSERT_PRED_FORMAT1 where the
  382. // predicate-formatter is a functor on a built-in type (int).
  383. TEST_F(ASSERT_PRED_FORMAT1Test, FunctorOnBuiltInTypeFailure) {
  384. expected_to_finish_ = false;
  385. EXPECT_FATAL_FAILURE({ // NOLINT
  386. ASSERT_PRED_FORMAT1(PredFormatFunctor1(),
  387. n1_++);
  388. finished_ = true;
  389. }, "");
  390. }
  391. // Tests a failed ASSERT_PRED_FORMAT1 where the
  392. // predicate-formatter is a functor on a user-defined type (Bool).
  393. TEST_F(ASSERT_PRED_FORMAT1Test, FunctorOnUserTypeFailure) {
  394. expected_to_finish_ = false;
  395. EXPECT_FATAL_FAILURE({ // NOLINT
  396. ASSERT_PRED_FORMAT1(PredFormatFunctor1(),
  397. Bool(n1_++));
  398. finished_ = true;
  399. }, "");
  400. }
  401. // Sample functions/functors for testing binary predicate assertions.
  402. // A binary predicate function.
  403. template <typename T1, typename T2>
  404. bool PredFunction2(T1 v1, T2 v2) {
  405. return v1 + v2 > 0;
  406. }
  407. // The following two functions are needed because a compiler doesn't have
  408. // a context yet to know which template function must be instantiated.
  409. bool PredFunction2Int(int v1, int v2) {
  410. return v1 + v2 > 0;
  411. }
  412. bool PredFunction2Bool(Bool v1, Bool v2) {
  413. return v1 + v2 > 0;
  414. }
  415. // A binary predicate functor.
  416. struct PredFunctor2 {
  417. template <typename T1, typename T2>
  418. bool operator()(const T1& v1,
  419. const T2& v2) {
  420. return v1 + v2 > 0;
  421. }
  422. };
  423. // A binary predicate-formatter function.
  424. template <typename T1, typename T2>
  425. testing::AssertionResult PredFormatFunction2(const char* e1,
  426. const char* e2,
  427. const T1& v1,
  428. const T2& v2) {
  429. if (PredFunction2(v1, v2))
  430. return testing::AssertionSuccess();
  431. return testing::AssertionFailure()
  432. << e1 << " + " << e2
  433. << " is expected to be positive, but evaluates to "
  434. << v1 + v2 << ".";
  435. }
  436. // A binary predicate-formatter functor.
  437. struct PredFormatFunctor2 {
  438. template <typename T1, typename T2>
  439. testing::AssertionResult operator()(const char* e1,
  440. const char* e2,
  441. const T1& v1,
  442. const T2& v2) const {
  443. return PredFormatFunction2(e1, e2, v1, v2);
  444. }
  445. };
  446. // Tests for {EXPECT|ASSERT}_PRED_FORMAT2.
  447. class Predicate2Test : public testing::Test {
  448. protected:
  449. void SetUp() override {
  450. expected_to_finish_ = true;
  451. finished_ = false;
  452. n1_ = n2_ = 0;
  453. }
  454. void TearDown() override {
  455. // Verifies that each of the predicate's arguments was evaluated
  456. // exactly once.
  457. EXPECT_EQ(1, n1_) <<
  458. "The predicate assertion didn't evaluate argument 2 "
  459. "exactly once.";
  460. EXPECT_EQ(1, n2_) <<
  461. "The predicate assertion didn't evaluate argument 3 "
  462. "exactly once.";
  463. // Verifies that the control flow in the test function is expected.
  464. if (expected_to_finish_ && !finished_) {
  465. FAIL() << "The predicate assertion unexpactedly aborted the test.";
  466. } else if (!expected_to_finish_ && finished_) {
  467. FAIL() << "The failed predicate assertion didn't abort the test "
  468. "as expected.";
  469. }
  470. }
  471. // true if and only if the test function is expected to run to finish.
  472. static bool expected_to_finish_;
  473. // true if and only if the test function did run to finish.
  474. static bool finished_;
  475. static int n1_;
  476. static int n2_;
  477. };
  478. bool Predicate2Test::expected_to_finish_;
  479. bool Predicate2Test::finished_;
  480. int Predicate2Test::n1_;
  481. int Predicate2Test::n2_;
  482. typedef Predicate2Test EXPECT_PRED_FORMAT2Test;
  483. typedef Predicate2Test ASSERT_PRED_FORMAT2Test;
  484. typedef Predicate2Test EXPECT_PRED2Test;
  485. typedef Predicate2Test ASSERT_PRED2Test;
  486. // Tests a successful EXPECT_PRED2 where the
  487. // predicate-formatter is a function on a built-in type (int).
  488. TEST_F(EXPECT_PRED2Test, FunctionOnBuiltInTypeSuccess) {
  489. EXPECT_PRED2(PredFunction2Int,
  490. ++n1_,
  491. ++n2_);
  492. finished_ = true;
  493. }
  494. // Tests a successful EXPECT_PRED2 where the
  495. // predicate-formatter is a function on a user-defined type (Bool).
  496. TEST_F(EXPECT_PRED2Test, FunctionOnUserTypeSuccess) {
  497. EXPECT_PRED2(PredFunction2Bool,
  498. Bool(++n1_),
  499. Bool(++n2_));
  500. finished_ = true;
  501. }
  502. // Tests a successful EXPECT_PRED2 where the
  503. // predicate-formatter is a functor on a built-in type (int).
  504. TEST_F(EXPECT_PRED2Test, FunctorOnBuiltInTypeSuccess) {
  505. EXPECT_PRED2(PredFunctor2(),
  506. ++n1_,
  507. ++n2_);
  508. finished_ = true;
  509. }
  510. // Tests a successful EXPECT_PRED2 where the
  511. // predicate-formatter is a functor on a user-defined type (Bool).
  512. TEST_F(EXPECT_PRED2Test, FunctorOnUserTypeSuccess) {
  513. EXPECT_PRED2(PredFunctor2(),
  514. Bool(++n1_),
  515. Bool(++n2_));
  516. finished_ = true;
  517. }
  518. // Tests a failed EXPECT_PRED2 where the
  519. // predicate-formatter is a function on a built-in type (int).
  520. TEST_F(EXPECT_PRED2Test, FunctionOnBuiltInTypeFailure) {
  521. EXPECT_NONFATAL_FAILURE({ // NOLINT
  522. EXPECT_PRED2(PredFunction2Int,
  523. n1_++,
  524. n2_++);
  525. finished_ = true;
  526. }, "");
  527. }
  528. // Tests a failed EXPECT_PRED2 where the
  529. // predicate-formatter is a function on a user-defined type (Bool).
  530. TEST_F(EXPECT_PRED2Test, FunctionOnUserTypeFailure) {
  531. EXPECT_NONFATAL_FAILURE({ // NOLINT
  532. EXPECT_PRED2(PredFunction2Bool,
  533. Bool(n1_++),
  534. Bool(n2_++));
  535. finished_ = true;
  536. }, "");
  537. }
  538. // Tests a failed EXPECT_PRED2 where the
  539. // predicate-formatter is a functor on a built-in type (int).
  540. TEST_F(EXPECT_PRED2Test, FunctorOnBuiltInTypeFailure) {
  541. EXPECT_NONFATAL_FAILURE({ // NOLINT
  542. EXPECT_PRED2(PredFunctor2(),
  543. n1_++,
  544. n2_++);
  545. finished_ = true;
  546. }, "");
  547. }
  548. // Tests a failed EXPECT_PRED2 where the
  549. // predicate-formatter is a functor on a user-defined type (Bool).
  550. TEST_F(EXPECT_PRED2Test, FunctorOnUserTypeFailure) {
  551. EXPECT_NONFATAL_FAILURE({ // NOLINT
  552. EXPECT_PRED2(PredFunctor2(),
  553. Bool(n1_++),
  554. Bool(n2_++));
  555. finished_ = true;
  556. }, "");
  557. }
  558. // Tests a successful ASSERT_PRED2 where the
  559. // predicate-formatter is a function on a built-in type (int).
  560. TEST_F(ASSERT_PRED2Test, FunctionOnBuiltInTypeSuccess) {
  561. ASSERT_PRED2(PredFunction2Int,
  562. ++n1_,
  563. ++n2_);
  564. finished_ = true;
  565. }
  566. // Tests a successful ASSERT_PRED2 where the
  567. // predicate-formatter is a function on a user-defined type (Bool).
  568. TEST_F(ASSERT_PRED2Test, FunctionOnUserTypeSuccess) {
  569. ASSERT_PRED2(PredFunction2Bool,
  570. Bool(++n1_),
  571. Bool(++n2_));
  572. finished_ = true;
  573. }
  574. // Tests a successful ASSERT_PRED2 where the
  575. // predicate-formatter is a functor on a built-in type (int).
  576. TEST_F(ASSERT_PRED2Test, FunctorOnBuiltInTypeSuccess) {
  577. ASSERT_PRED2(PredFunctor2(),
  578. ++n1_,
  579. ++n2_);
  580. finished_ = true;
  581. }
  582. // Tests a successful ASSERT_PRED2 where the
  583. // predicate-formatter is a functor on a user-defined type (Bool).
  584. TEST_F(ASSERT_PRED2Test, FunctorOnUserTypeSuccess) {
  585. ASSERT_PRED2(PredFunctor2(),
  586. Bool(++n1_),
  587. Bool(++n2_));
  588. finished_ = true;
  589. }
  590. // Tests a failed ASSERT_PRED2 where the
  591. // predicate-formatter is a function on a built-in type (int).
  592. TEST_F(ASSERT_PRED2Test, FunctionOnBuiltInTypeFailure) {
  593. expected_to_finish_ = false;
  594. EXPECT_FATAL_FAILURE({ // NOLINT
  595. ASSERT_PRED2(PredFunction2Int,
  596. n1_++,
  597. n2_++);
  598. finished_ = true;
  599. }, "");
  600. }
  601. // Tests a failed ASSERT_PRED2 where the
  602. // predicate-formatter is a function on a user-defined type (Bool).
  603. TEST_F(ASSERT_PRED2Test, FunctionOnUserTypeFailure) {
  604. expected_to_finish_ = false;
  605. EXPECT_FATAL_FAILURE({ // NOLINT
  606. ASSERT_PRED2(PredFunction2Bool,
  607. Bool(n1_++),
  608. Bool(n2_++));
  609. finished_ = true;
  610. }, "");
  611. }
  612. // Tests a failed ASSERT_PRED2 where the
  613. // predicate-formatter is a functor on a built-in type (int).
  614. TEST_F(ASSERT_PRED2Test, FunctorOnBuiltInTypeFailure) {
  615. expected_to_finish_ = false;
  616. EXPECT_FATAL_FAILURE({ // NOLINT
  617. ASSERT_PRED2(PredFunctor2(),
  618. n1_++,
  619. n2_++);
  620. finished_ = true;
  621. }, "");
  622. }
  623. // Tests a failed ASSERT_PRED2 where the
  624. // predicate-formatter is a functor on a user-defined type (Bool).
  625. TEST_F(ASSERT_PRED2Test, FunctorOnUserTypeFailure) {
  626. expected_to_finish_ = false;
  627. EXPECT_FATAL_FAILURE({ // NOLINT
  628. ASSERT_PRED2(PredFunctor2(),
  629. Bool(n1_++),
  630. Bool(n2_++));
  631. finished_ = true;
  632. }, "");
  633. }
  634. // Tests a successful EXPECT_PRED_FORMAT2 where the
  635. // predicate-formatter is a function on a built-in type (int).
  636. TEST_F(EXPECT_PRED_FORMAT2Test, FunctionOnBuiltInTypeSuccess) {
  637. EXPECT_PRED_FORMAT2(PredFormatFunction2,
  638. ++n1_,
  639. ++n2_);
  640. finished_ = true;
  641. }
  642. // Tests a successful EXPECT_PRED_FORMAT2 where the
  643. // predicate-formatter is a function on a user-defined type (Bool).
  644. TEST_F(EXPECT_PRED_FORMAT2Test, FunctionOnUserTypeSuccess) {
  645. EXPECT_PRED_FORMAT2(PredFormatFunction2,
  646. Bool(++n1_),
  647. Bool(++n2_));
  648. finished_ = true;
  649. }
  650. // Tests a successful EXPECT_PRED_FORMAT2 where the
  651. // predicate-formatter is a functor on a built-in type (int).
  652. TEST_F(EXPECT_PRED_FORMAT2Test, FunctorOnBuiltInTypeSuccess) {
  653. EXPECT_PRED_FORMAT2(PredFormatFunctor2(),
  654. ++n1_,
  655. ++n2_);
  656. finished_ = true;
  657. }
  658. // Tests a successful EXPECT_PRED_FORMAT2 where the
  659. // predicate-formatter is a functor on a user-defined type (Bool).
  660. TEST_F(EXPECT_PRED_FORMAT2Test, FunctorOnUserTypeSuccess) {
  661. EXPECT_PRED_FORMAT2(PredFormatFunctor2(),
  662. Bool(++n1_),
  663. Bool(++n2_));
  664. finished_ = true;
  665. }
  666. // Tests a failed EXPECT_PRED_FORMAT2 where the
  667. // predicate-formatter is a function on a built-in type (int).
  668. TEST_F(EXPECT_PRED_FORMAT2Test, FunctionOnBuiltInTypeFailure) {
  669. EXPECT_NONFATAL_FAILURE({ // NOLINT
  670. EXPECT_PRED_FORMAT2(PredFormatFunction2,
  671. n1_++,
  672. n2_++);
  673. finished_ = true;
  674. }, "");
  675. }
  676. // Tests a failed EXPECT_PRED_FORMAT2 where the
  677. // predicate-formatter is a function on a user-defined type (Bool).
  678. TEST_F(EXPECT_PRED_FORMAT2Test, FunctionOnUserTypeFailure) {
  679. EXPECT_NONFATAL_FAILURE({ // NOLINT
  680. EXPECT_PRED_FORMAT2(PredFormatFunction2,
  681. Bool(n1_++),
  682. Bool(n2_++));
  683. finished_ = true;
  684. }, "");
  685. }
  686. // Tests a failed EXPECT_PRED_FORMAT2 where the
  687. // predicate-formatter is a functor on a built-in type (int).
  688. TEST_F(EXPECT_PRED_FORMAT2Test, FunctorOnBuiltInTypeFailure) {
  689. EXPECT_NONFATAL_FAILURE({ // NOLINT
  690. EXPECT_PRED_FORMAT2(PredFormatFunctor2(),
  691. n1_++,
  692. n2_++);
  693. finished_ = true;
  694. }, "");
  695. }
  696. // Tests a failed EXPECT_PRED_FORMAT2 where the
  697. // predicate-formatter is a functor on a user-defined type (Bool).
  698. TEST_F(EXPECT_PRED_FORMAT2Test, FunctorOnUserTypeFailure) {
  699. EXPECT_NONFATAL_FAILURE({ // NOLINT
  700. EXPECT_PRED_FORMAT2(PredFormatFunctor2(),
  701. Bool(n1_++),
  702. Bool(n2_++));
  703. finished_ = true;
  704. }, "");
  705. }
  706. // Tests a successful ASSERT_PRED_FORMAT2 where the
  707. // predicate-formatter is a function on a built-in type (int).
  708. TEST_F(ASSERT_PRED_FORMAT2Test, FunctionOnBuiltInTypeSuccess) {
  709. ASSERT_PRED_FORMAT2(PredFormatFunction2,
  710. ++n1_,
  711. ++n2_);
  712. finished_ = true;
  713. }
  714. // Tests a successful ASSERT_PRED_FORMAT2 where the
  715. // predicate-formatter is a function on a user-defined type (Bool).
  716. TEST_F(ASSERT_PRED_FORMAT2Test, FunctionOnUserTypeSuccess) {
  717. ASSERT_PRED_FORMAT2(PredFormatFunction2,
  718. Bool(++n1_),
  719. Bool(++n2_));
  720. finished_ = true;
  721. }
  722. // Tests a successful ASSERT_PRED_FORMAT2 where the
  723. // predicate-formatter is a functor on a built-in type (int).
  724. TEST_F(ASSERT_PRED_FORMAT2Test, FunctorOnBuiltInTypeSuccess) {
  725. ASSERT_PRED_FORMAT2(PredFormatFunctor2(),
  726. ++n1_,
  727. ++n2_);
  728. finished_ = true;
  729. }
  730. // Tests a successful ASSERT_PRED_FORMAT2 where the
  731. // predicate-formatter is a functor on a user-defined type (Bool).
  732. TEST_F(ASSERT_PRED_FORMAT2Test, FunctorOnUserTypeSuccess) {
  733. ASSERT_PRED_FORMAT2(PredFormatFunctor2(),
  734. Bool(++n1_),
  735. Bool(++n2_));
  736. finished_ = true;
  737. }
  738. // Tests a failed ASSERT_PRED_FORMAT2 where the
  739. // predicate-formatter is a function on a built-in type (int).
  740. TEST_F(ASSERT_PRED_FORMAT2Test, FunctionOnBuiltInTypeFailure) {
  741. expected_to_finish_ = false;
  742. EXPECT_FATAL_FAILURE({ // NOLINT
  743. ASSERT_PRED_FORMAT2(PredFormatFunction2,
  744. n1_++,
  745. n2_++);
  746. finished_ = true;
  747. }, "");
  748. }
  749. // Tests a failed ASSERT_PRED_FORMAT2 where the
  750. // predicate-formatter is a function on a user-defined type (Bool).
  751. TEST_F(ASSERT_PRED_FORMAT2Test, FunctionOnUserTypeFailure) {
  752. expected_to_finish_ = false;
  753. EXPECT_FATAL_FAILURE({ // NOLINT
  754. ASSERT_PRED_FORMAT2(PredFormatFunction2,
  755. Bool(n1_++),
  756. Bool(n2_++));
  757. finished_ = true;
  758. }, "");
  759. }
  760. // Tests a failed ASSERT_PRED_FORMAT2 where the
  761. // predicate-formatter is a functor on a built-in type (int).
  762. TEST_F(ASSERT_PRED_FORMAT2Test, FunctorOnBuiltInTypeFailure) {
  763. expected_to_finish_ = false;
  764. EXPECT_FATAL_FAILURE({ // NOLINT
  765. ASSERT_PRED_FORMAT2(PredFormatFunctor2(),
  766. n1_++,
  767. n2_++);
  768. finished_ = true;
  769. }, "");
  770. }
  771. // Tests a failed ASSERT_PRED_FORMAT2 where the
  772. // predicate-formatter is a functor on a user-defined type (Bool).
  773. TEST_F(ASSERT_PRED_FORMAT2Test, FunctorOnUserTypeFailure) {
  774. expected_to_finish_ = false;
  775. EXPECT_FATAL_FAILURE({ // NOLINT
  776. ASSERT_PRED_FORMAT2(PredFormatFunctor2(),
  777. Bool(n1_++),
  778. Bool(n2_++));
  779. finished_ = true;
  780. }, "");
  781. }
  782. // Sample functions/functors for testing ternary predicate assertions.
  783. // A ternary predicate function.
  784. template <typename T1, typename T2, typename T3>
  785. bool PredFunction3(T1 v1, T2 v2, T3 v3) {
  786. return v1 + v2 + v3 > 0;
  787. }
  788. // The following two functions are needed because a compiler doesn't have
  789. // a context yet to know which template function must be instantiated.
  790. bool PredFunction3Int(int v1, int v2, int v3) {
  791. return v1 + v2 + v3 > 0;
  792. }
  793. bool PredFunction3Bool(Bool v1, Bool v2, Bool v3) {
  794. return v1 + v2 + v3 > 0;
  795. }
  796. // A ternary predicate functor.
  797. struct PredFunctor3 {
  798. template <typename T1, typename T2, typename T3>
  799. bool operator()(const T1& v1,
  800. const T2& v2,
  801. const T3& v3) {
  802. return v1 + v2 + v3 > 0;
  803. }
  804. };
  805. // A ternary predicate-formatter function.
  806. template <typename T1, typename T2, typename T3>
  807. testing::AssertionResult PredFormatFunction3(const char* e1,
  808. const char* e2,
  809. const char* e3,
  810. const T1& v1,
  811. const T2& v2,
  812. const T3& v3) {
  813. if (PredFunction3(v1, v2, v3))
  814. return testing::AssertionSuccess();
  815. return testing::AssertionFailure()
  816. << e1 << " + " << e2 << " + " << e3
  817. << " is expected to be positive, but evaluates to "
  818. << v1 + v2 + v3 << ".";
  819. }
  820. // A ternary predicate-formatter functor.
  821. struct PredFormatFunctor3 {
  822. template <typename T1, typename T2, typename T3>
  823. testing::AssertionResult operator()(const char* e1,
  824. const char* e2,
  825. const char* e3,
  826. const T1& v1,
  827. const T2& v2,
  828. const T3& v3) const {
  829. return PredFormatFunction3(e1, e2, e3, v1, v2, v3);
  830. }
  831. };
  832. // Tests for {EXPECT|ASSERT}_PRED_FORMAT3.
  833. class Predicate3Test : public testing::Test {
  834. protected:
  835. void SetUp() override {
  836. expected_to_finish_ = true;
  837. finished_ = false;
  838. n1_ = n2_ = n3_ = 0;
  839. }
  840. void TearDown() override {
  841. // Verifies that each of the predicate's arguments was evaluated
  842. // exactly once.
  843. EXPECT_EQ(1, n1_) <<
  844. "The predicate assertion didn't evaluate argument 2 "
  845. "exactly once.";
  846. EXPECT_EQ(1, n2_) <<
  847. "The predicate assertion didn't evaluate argument 3 "
  848. "exactly once.";
  849. EXPECT_EQ(1, n3_) <<
  850. "The predicate assertion didn't evaluate argument 4 "
  851. "exactly once.";
  852. // Verifies that the control flow in the test function is expected.
  853. if (expected_to_finish_ && !finished_) {
  854. FAIL() << "The predicate assertion unexpactedly aborted the test.";
  855. } else if (!expected_to_finish_ && finished_) {
  856. FAIL() << "The failed predicate assertion didn't abort the test "
  857. "as expected.";
  858. }
  859. }
  860. // true if and only if the test function is expected to run to finish.
  861. static bool expected_to_finish_;
  862. // true if and only if the test function did run to finish.
  863. static bool finished_;
  864. static int n1_;
  865. static int n2_;
  866. static int n3_;
  867. };
  868. bool Predicate3Test::expected_to_finish_;
  869. bool Predicate3Test::finished_;
  870. int Predicate3Test::n1_;
  871. int Predicate3Test::n2_;
  872. int Predicate3Test::n3_;
  873. typedef Predicate3Test EXPECT_PRED_FORMAT3Test;
  874. typedef Predicate3Test ASSERT_PRED_FORMAT3Test;
  875. typedef Predicate3Test EXPECT_PRED3Test;
  876. typedef Predicate3Test ASSERT_PRED3Test;
  877. // Tests a successful EXPECT_PRED3 where the
  878. // predicate-formatter is a function on a built-in type (int).
  879. TEST_F(EXPECT_PRED3Test, FunctionOnBuiltInTypeSuccess) {
  880. EXPECT_PRED3(PredFunction3Int,
  881. ++n1_,
  882. ++n2_,
  883. ++n3_);
  884. finished_ = true;
  885. }
  886. // Tests a successful EXPECT_PRED3 where the
  887. // predicate-formatter is a function on a user-defined type (Bool).
  888. TEST_F(EXPECT_PRED3Test, FunctionOnUserTypeSuccess) {
  889. EXPECT_PRED3(PredFunction3Bool,
  890. Bool(++n1_),
  891. Bool(++n2_),
  892. Bool(++n3_));
  893. finished_ = true;
  894. }
  895. // Tests a successful EXPECT_PRED3 where the
  896. // predicate-formatter is a functor on a built-in type (int).
  897. TEST_F(EXPECT_PRED3Test, FunctorOnBuiltInTypeSuccess) {
  898. EXPECT_PRED3(PredFunctor3(),
  899. ++n1_,
  900. ++n2_,
  901. ++n3_);
  902. finished_ = true;
  903. }
  904. // Tests a successful EXPECT_PRED3 where the
  905. // predicate-formatter is a functor on a user-defined type (Bool).
  906. TEST_F(EXPECT_PRED3Test, FunctorOnUserTypeSuccess) {
  907. EXPECT_PRED3(PredFunctor3(),
  908. Bool(++n1_),
  909. Bool(++n2_),
  910. Bool(++n3_));
  911. finished_ = true;
  912. }
  913. // Tests a failed EXPECT_PRED3 where the
  914. // predicate-formatter is a function on a built-in type (int).
  915. TEST_F(EXPECT_PRED3Test, FunctionOnBuiltInTypeFailure) {
  916. EXPECT_NONFATAL_FAILURE({ // NOLINT
  917. EXPECT_PRED3(PredFunction3Int,
  918. n1_++,
  919. n2_++,
  920. n3_++);
  921. finished_ = true;
  922. }, "");
  923. }
  924. // Tests a failed EXPECT_PRED3 where the
  925. // predicate-formatter is a function on a user-defined type (Bool).
  926. TEST_F(EXPECT_PRED3Test, FunctionOnUserTypeFailure) {
  927. EXPECT_NONFATAL_FAILURE({ // NOLINT
  928. EXPECT_PRED3(PredFunction3Bool,
  929. Bool(n1_++),
  930. Bool(n2_++),
  931. Bool(n3_++));
  932. finished_ = true;
  933. }, "");
  934. }
  935. // Tests a failed EXPECT_PRED3 where the
  936. // predicate-formatter is a functor on a built-in type (int).
  937. TEST_F(EXPECT_PRED3Test, FunctorOnBuiltInTypeFailure) {
  938. EXPECT_NONFATAL_FAILURE({ // NOLINT
  939. EXPECT_PRED3(PredFunctor3(),
  940. n1_++,
  941. n2_++,
  942. n3_++);
  943. finished_ = true;
  944. }, "");
  945. }
  946. // Tests a failed EXPECT_PRED3 where the
  947. // predicate-formatter is a functor on a user-defined type (Bool).
  948. TEST_F(EXPECT_PRED3Test, FunctorOnUserTypeFailure) {
  949. EXPECT_NONFATAL_FAILURE({ // NOLINT
  950. EXPECT_PRED3(PredFunctor3(),
  951. Bool(n1_++),
  952. Bool(n2_++),
  953. Bool(n3_++));
  954. finished_ = true;
  955. }, "");
  956. }
  957. // Tests a successful ASSERT_PRED3 where the
  958. // predicate-formatter is a function on a built-in type (int).
  959. TEST_F(ASSERT_PRED3Test, FunctionOnBuiltInTypeSuccess) {
  960. ASSERT_PRED3(PredFunction3Int,
  961. ++n1_,
  962. ++n2_,
  963. ++n3_);
  964. finished_ = true;
  965. }
  966. // Tests a successful ASSERT_PRED3 where the
  967. // predicate-formatter is a function on a user-defined type (Bool).
  968. TEST_F(ASSERT_PRED3Test, FunctionOnUserTypeSuccess) {
  969. ASSERT_PRED3(PredFunction3Bool,
  970. Bool(++n1_),
  971. Bool(++n2_),
  972. Bool(++n3_));
  973. finished_ = true;
  974. }
  975. // Tests a successful ASSERT_PRED3 where the
  976. // predicate-formatter is a functor on a built-in type (int).
  977. TEST_F(ASSERT_PRED3Test, FunctorOnBuiltInTypeSuccess) {
  978. ASSERT_PRED3(PredFunctor3(),
  979. ++n1_,
  980. ++n2_,
  981. ++n3_);
  982. finished_ = true;
  983. }
  984. // Tests a successful ASSERT_PRED3 where the
  985. // predicate-formatter is a functor on a user-defined type (Bool).
  986. TEST_F(ASSERT_PRED3Test, FunctorOnUserTypeSuccess) {
  987. ASSERT_PRED3(PredFunctor3(),
  988. Bool(++n1_),
  989. Bool(++n2_),
  990. Bool(++n3_));
  991. finished_ = true;
  992. }
  993. // Tests a failed ASSERT_PRED3 where the
  994. // predicate-formatter is a function on a built-in type (int).
  995. TEST_F(ASSERT_PRED3Test, FunctionOnBuiltInTypeFailure) {
  996. expected_to_finish_ = false;
  997. EXPECT_FATAL_FAILURE({ // NOLINT
  998. ASSERT_PRED3(PredFunction3Int,
  999. n1_++,
  1000. n2_++,
  1001. n3_++);
  1002. finished_ = true;
  1003. }, "");
  1004. }
  1005. // Tests a failed ASSERT_PRED3 where the
  1006. // predicate-formatter is a function on a user-defined type (Bool).
  1007. TEST_F(ASSERT_PRED3Test, FunctionOnUserTypeFailure) {
  1008. expected_to_finish_ = false;
  1009. EXPECT_FATAL_FAILURE({ // NOLINT
  1010. ASSERT_PRED3(PredFunction3Bool,
  1011. Bool(n1_++),
  1012. Bool(n2_++),
  1013. Bool(n3_++));
  1014. finished_ = true;
  1015. }, "");
  1016. }
  1017. // Tests a failed ASSERT_PRED3 where the
  1018. // predicate-formatter is a functor on a built-in type (int).
  1019. TEST_F(ASSERT_PRED3Test, FunctorOnBuiltInTypeFailure) {
  1020. expected_to_finish_ = false;
  1021. EXPECT_FATAL_FAILURE({ // NOLINT
  1022. ASSERT_PRED3(PredFunctor3(),
  1023. n1_++,
  1024. n2_++,
  1025. n3_++);
  1026. finished_ = true;
  1027. }, "");
  1028. }
  1029. // Tests a failed ASSERT_PRED3 where the
  1030. // predicate-formatter is a functor on a user-defined type (Bool).
  1031. TEST_F(ASSERT_PRED3Test, FunctorOnUserTypeFailure) {
  1032. expected_to_finish_ = false;
  1033. EXPECT_FATAL_FAILURE({ // NOLINT
  1034. ASSERT_PRED3(PredFunctor3(),
  1035. Bool(n1_++),
  1036. Bool(n2_++),
  1037. Bool(n3_++));
  1038. finished_ = true;
  1039. }, "");
  1040. }
  1041. // Tests a successful EXPECT_PRED_FORMAT3 where the
  1042. // predicate-formatter is a function on a built-in type (int).
  1043. TEST_F(EXPECT_PRED_FORMAT3Test, FunctionOnBuiltInTypeSuccess) {
  1044. EXPECT_PRED_FORMAT3(PredFormatFunction3,
  1045. ++n1_,
  1046. ++n2_,
  1047. ++n3_);
  1048. finished_ = true;
  1049. }
  1050. // Tests a successful EXPECT_PRED_FORMAT3 where the
  1051. // predicate-formatter is a function on a user-defined type (Bool).
  1052. TEST_F(EXPECT_PRED_FORMAT3Test, FunctionOnUserTypeSuccess) {
  1053. EXPECT_PRED_FORMAT3(PredFormatFunction3,
  1054. Bool(++n1_),
  1055. Bool(++n2_),
  1056. Bool(++n3_));
  1057. finished_ = true;
  1058. }
  1059. // Tests a successful EXPECT_PRED_FORMAT3 where the
  1060. // predicate-formatter is a functor on a built-in type (int).
  1061. TEST_F(EXPECT_PRED_FORMAT3Test, FunctorOnBuiltInTypeSuccess) {
  1062. EXPECT_PRED_FORMAT3(PredFormatFunctor3(),
  1063. ++n1_,
  1064. ++n2_,
  1065. ++n3_);
  1066. finished_ = true;
  1067. }
  1068. // Tests a successful EXPECT_PRED_FORMAT3 where the
  1069. // predicate-formatter is a functor on a user-defined type (Bool).
  1070. TEST_F(EXPECT_PRED_FORMAT3Test, FunctorOnUserTypeSuccess) {
  1071. EXPECT_PRED_FORMAT3(PredFormatFunctor3(),
  1072. Bool(++n1_),
  1073. Bool(++n2_),
  1074. Bool(++n3_));
  1075. finished_ = true;
  1076. }
  1077. // Tests a failed EXPECT_PRED_FORMAT3 where the
  1078. // predicate-formatter is a function on a built-in type (int).
  1079. TEST_F(EXPECT_PRED_FORMAT3Test, FunctionOnBuiltInTypeFailure) {
  1080. EXPECT_NONFATAL_FAILURE({ // NOLINT
  1081. EXPECT_PRED_FORMAT3(PredFormatFunction3,
  1082. n1_++,
  1083. n2_++,
  1084. n3_++);
  1085. finished_ = true;
  1086. }, "");
  1087. }
  1088. // Tests a failed EXPECT_PRED_FORMAT3 where the
  1089. // predicate-formatter is a function on a user-defined type (Bool).
  1090. TEST_F(EXPECT_PRED_FORMAT3Test, FunctionOnUserTypeFailure) {
  1091. EXPECT_NONFATAL_FAILURE({ // NOLINT
  1092. EXPECT_PRED_FORMAT3(PredFormatFunction3,
  1093. Bool(n1_++),
  1094. Bool(n2_++),
  1095. Bool(n3_++));
  1096. finished_ = true;
  1097. }, "");
  1098. }
  1099. // Tests a failed EXPECT_PRED_FORMAT3 where the
  1100. // predicate-formatter is a functor on a built-in type (int).
  1101. TEST_F(EXPECT_PRED_FORMAT3Test, FunctorOnBuiltInTypeFailure) {
  1102. EXPECT_NONFATAL_FAILURE({ // NOLINT
  1103. EXPECT_PRED_FORMAT3(PredFormatFunctor3(),
  1104. n1_++,
  1105. n2_++,
  1106. n3_++);
  1107. finished_ = true;
  1108. }, "");
  1109. }
  1110. // Tests a failed EXPECT_PRED_FORMAT3 where the
  1111. // predicate-formatter is a functor on a user-defined type (Bool).
  1112. TEST_F(EXPECT_PRED_FORMAT3Test, FunctorOnUserTypeFailure) {
  1113. EXPECT_NONFATAL_FAILURE({ // NOLINT
  1114. EXPECT_PRED_FORMAT3(PredFormatFunctor3(),
  1115. Bool(n1_++),
  1116. Bool(n2_++),
  1117. Bool(n3_++));
  1118. finished_ = true;
  1119. }, "");
  1120. }
  1121. // Tests a successful ASSERT_PRED_FORMAT3 where the
  1122. // predicate-formatter is a function on a built-in type (int).
  1123. TEST_F(ASSERT_PRED_FORMAT3Test, FunctionOnBuiltInTypeSuccess) {
  1124. ASSERT_PRED_FORMAT3(PredFormatFunction3,
  1125. ++n1_,
  1126. ++n2_,
  1127. ++n3_);
  1128. finished_ = true;
  1129. }
  1130. // Tests a successful ASSERT_PRED_FORMAT3 where the
  1131. // predicate-formatter is a function on a user-defined type (Bool).
  1132. TEST_F(ASSERT_PRED_FORMAT3Test, FunctionOnUserTypeSuccess) {
  1133. ASSERT_PRED_FORMAT3(PredFormatFunction3,
  1134. Bool(++n1_),
  1135. Bool(++n2_),
  1136. Bool(++n3_));
  1137. finished_ = true;
  1138. }
  1139. // Tests a successful ASSERT_PRED_FORMAT3 where the
  1140. // predicate-formatter is a functor on a built-in type (int).
  1141. TEST_F(ASSERT_PRED_FORMAT3Test, FunctorOnBuiltInTypeSuccess) {
  1142. ASSERT_PRED_FORMAT3(PredFormatFunctor3(),
  1143. ++n1_,
  1144. ++n2_,
  1145. ++n3_);
  1146. finished_ = true;
  1147. }
  1148. // Tests a successful ASSERT_PRED_FORMAT3 where the
  1149. // predicate-formatter is a functor on a user-defined type (Bool).
  1150. TEST_F(ASSERT_PRED_FORMAT3Test, FunctorOnUserTypeSuccess) {
  1151. ASSERT_PRED_FORMAT3(PredFormatFunctor3(),
  1152. Bool(++n1_),
  1153. Bool(++n2_),
  1154. Bool(++n3_));
  1155. finished_ = true;
  1156. }
  1157. // Tests a failed ASSERT_PRED_FORMAT3 where the
  1158. // predicate-formatter is a function on a built-in type (int).
  1159. TEST_F(ASSERT_PRED_FORMAT3Test, FunctionOnBuiltInTypeFailure) {
  1160. expected_to_finish_ = false;
  1161. EXPECT_FATAL_FAILURE({ // NOLINT
  1162. ASSERT_PRED_FORMAT3(PredFormatFunction3,
  1163. n1_++,
  1164. n2_++,
  1165. n3_++);
  1166. finished_ = true;
  1167. }, "");
  1168. }
  1169. // Tests a failed ASSERT_PRED_FORMAT3 where the
  1170. // predicate-formatter is a function on a user-defined type (Bool).
  1171. TEST_F(ASSERT_PRED_FORMAT3Test, FunctionOnUserTypeFailure) {
  1172. expected_to_finish_ = false;
  1173. EXPECT_FATAL_FAILURE({ // NOLINT
  1174. ASSERT_PRED_FORMAT3(PredFormatFunction3,
  1175. Bool(n1_++),
  1176. Bool(n2_++),
  1177. Bool(n3_++));
  1178. finished_ = true;
  1179. }, "");
  1180. }
  1181. // Tests a failed ASSERT_PRED_FORMAT3 where the
  1182. // predicate-formatter is a functor on a built-in type (int).
  1183. TEST_F(ASSERT_PRED_FORMAT3Test, FunctorOnBuiltInTypeFailure) {
  1184. expected_to_finish_ = false;
  1185. EXPECT_FATAL_FAILURE({ // NOLINT
  1186. ASSERT_PRED_FORMAT3(PredFormatFunctor3(),
  1187. n1_++,
  1188. n2_++,
  1189. n3_++);
  1190. finished_ = true;
  1191. }, "");
  1192. }
  1193. // Tests a failed ASSERT_PRED_FORMAT3 where the
  1194. // predicate-formatter is a functor on a user-defined type (Bool).
  1195. TEST_F(ASSERT_PRED_FORMAT3Test, FunctorOnUserTypeFailure) {
  1196. expected_to_finish_ = false;
  1197. EXPECT_FATAL_FAILURE({ // NOLINT
  1198. ASSERT_PRED_FORMAT3(PredFormatFunctor3(),
  1199. Bool(n1_++),
  1200. Bool(n2_++),
  1201. Bool(n3_++));
  1202. finished_ = true;
  1203. }, "");
  1204. }
  1205. // Sample functions/functors for testing 4-ary predicate assertions.
  1206. // A 4-ary predicate function.
  1207. template <typename T1, typename T2, typename T3, typename T4>
  1208. bool PredFunction4(T1 v1, T2 v2, T3 v3, T4 v4) {
  1209. return v1 + v2 + v3 + v4 > 0;
  1210. }
  1211. // The following two functions are needed because a compiler doesn't have
  1212. // a context yet to know which template function must be instantiated.
  1213. bool PredFunction4Int(int v1, int v2, int v3, int v4) {
  1214. return v1 + v2 + v3 + v4 > 0;
  1215. }
  1216. bool PredFunction4Bool(Bool v1, Bool v2, Bool v3, Bool v4) {
  1217. return v1 + v2 + v3 + v4 > 0;
  1218. }
  1219. // A 4-ary predicate functor.
  1220. struct PredFunctor4 {
  1221. template <typename T1, typename T2, typename T3, typename T4>
  1222. bool operator()(const T1& v1,
  1223. const T2& v2,
  1224. const T3& v3,
  1225. const T4& v4) {
  1226. return v1 + v2 + v3 + v4 > 0;
  1227. }
  1228. };
  1229. // A 4-ary predicate-formatter function.
  1230. template <typename T1, typename T2, typename T3, typename T4>
  1231. testing::AssertionResult PredFormatFunction4(const char* e1,
  1232. const char* e2,
  1233. const char* e3,
  1234. const char* e4,
  1235. const T1& v1,
  1236. const T2& v2,
  1237. const T3& v3,
  1238. const T4& v4) {
  1239. if (PredFunction4(v1, v2, v3, v4))
  1240. return testing::AssertionSuccess();
  1241. return testing::AssertionFailure()
  1242. << e1 << " + " << e2 << " + " << e3 << " + " << e4
  1243. << " is expected to be positive, but evaluates to "
  1244. << v1 + v2 + v3 + v4 << ".";
  1245. }
  1246. // A 4-ary predicate-formatter functor.
  1247. struct PredFormatFunctor4 {
  1248. template <typename T1, typename T2, typename T3, typename T4>
  1249. testing::AssertionResult operator()(const char* e1,
  1250. const char* e2,
  1251. const char* e3,
  1252. const char* e4,
  1253. const T1& v1,
  1254. const T2& v2,
  1255. const T3& v3,
  1256. const T4& v4) const {
  1257. return PredFormatFunction4(e1, e2, e3, e4, v1, v2, v3, v4);
  1258. }
  1259. };
  1260. // Tests for {EXPECT|ASSERT}_PRED_FORMAT4.
  1261. class Predicate4Test : public testing::Test {
  1262. protected:
  1263. void SetUp() override {
  1264. expected_to_finish_ = true;
  1265. finished_ = false;
  1266. n1_ = n2_ = n3_ = n4_ = 0;
  1267. }
  1268. void TearDown() override {
  1269. // Verifies that each of the predicate's arguments was evaluated
  1270. // exactly once.
  1271. EXPECT_EQ(1, n1_) <<
  1272. "The predicate assertion didn't evaluate argument 2 "
  1273. "exactly once.";
  1274. EXPECT_EQ(1, n2_) <<
  1275. "The predicate assertion didn't evaluate argument 3 "
  1276. "exactly once.";
  1277. EXPECT_EQ(1, n3_) <<
  1278. "The predicate assertion didn't evaluate argument 4 "
  1279. "exactly once.";
  1280. EXPECT_EQ(1, n4_) <<
  1281. "The predicate assertion didn't evaluate argument 5 "
  1282. "exactly once.";
  1283. // Verifies that the control flow in the test function is expected.
  1284. if (expected_to_finish_ && !finished_) {
  1285. FAIL() << "The predicate assertion unexpactedly aborted the test.";
  1286. } else if (!expected_to_finish_ && finished_) {
  1287. FAIL() << "The failed predicate assertion didn't abort the test "
  1288. "as expected.";
  1289. }
  1290. }
  1291. // true if and only if the test function is expected to run to finish.
  1292. static bool expected_to_finish_;
  1293. // true if and only if the test function did run to finish.
  1294. static bool finished_;
  1295. static int n1_;
  1296. static int n2_;
  1297. static int n3_;
  1298. static int n4_;
  1299. };
  1300. bool Predicate4Test::expected_to_finish_;
  1301. bool Predicate4Test::finished_;
  1302. int Predicate4Test::n1_;
  1303. int Predicate4Test::n2_;
  1304. int Predicate4Test::n3_;
  1305. int Predicate4Test::n4_;
  1306. typedef Predicate4Test EXPECT_PRED_FORMAT4Test;
  1307. typedef Predicate4Test ASSERT_PRED_FORMAT4Test;
  1308. typedef Predicate4Test EXPECT_PRED4Test;
  1309. typedef Predicate4Test ASSERT_PRED4Test;
  1310. // Tests a successful EXPECT_PRED4 where the
  1311. // predicate-formatter is a function on a built-in type (int).
  1312. TEST_F(EXPECT_PRED4Test, FunctionOnBuiltInTypeSuccess) {
  1313. EXPECT_PRED4(PredFunction4Int,
  1314. ++n1_,
  1315. ++n2_,
  1316. ++n3_,
  1317. ++n4_);
  1318. finished_ = true;
  1319. }
  1320. // Tests a successful EXPECT_PRED4 where the
  1321. // predicate-formatter is a function on a user-defined type (Bool).
  1322. TEST_F(EXPECT_PRED4Test, FunctionOnUserTypeSuccess) {
  1323. EXPECT_PRED4(PredFunction4Bool,
  1324. Bool(++n1_),
  1325. Bool(++n2_),
  1326. Bool(++n3_),
  1327. Bool(++n4_));
  1328. finished_ = true;
  1329. }
  1330. // Tests a successful EXPECT_PRED4 where the
  1331. // predicate-formatter is a functor on a built-in type (int).
  1332. TEST_F(EXPECT_PRED4Test, FunctorOnBuiltInTypeSuccess) {
  1333. EXPECT_PRED4(PredFunctor4(),
  1334. ++n1_,
  1335. ++n2_,
  1336. ++n3_,
  1337. ++n4_);
  1338. finished_ = true;
  1339. }
  1340. // Tests a successful EXPECT_PRED4 where the
  1341. // predicate-formatter is a functor on a user-defined type (Bool).
  1342. TEST_F(EXPECT_PRED4Test, FunctorOnUserTypeSuccess) {
  1343. EXPECT_PRED4(PredFunctor4(),
  1344. Bool(++n1_),
  1345. Bool(++n2_),
  1346. Bool(++n3_),
  1347. Bool(++n4_));
  1348. finished_ = true;
  1349. }
  1350. // Tests a failed EXPECT_PRED4 where the
  1351. // predicate-formatter is a function on a built-in type (int).
  1352. TEST_F(EXPECT_PRED4Test, FunctionOnBuiltInTypeFailure) {
  1353. EXPECT_NONFATAL_FAILURE({ // NOLINT
  1354. EXPECT_PRED4(PredFunction4Int,
  1355. n1_++,
  1356. n2_++,
  1357. n3_++,
  1358. n4_++);
  1359. finished_ = true;
  1360. }, "");
  1361. }
  1362. // Tests a failed EXPECT_PRED4 where the
  1363. // predicate-formatter is a function on a user-defined type (Bool).
  1364. TEST_F(EXPECT_PRED4Test, FunctionOnUserTypeFailure) {
  1365. EXPECT_NONFATAL_FAILURE({ // NOLINT
  1366. EXPECT_PRED4(PredFunction4Bool,
  1367. Bool(n1_++),
  1368. Bool(n2_++),
  1369. Bool(n3_++),
  1370. Bool(n4_++));
  1371. finished_ = true;
  1372. }, "");
  1373. }
  1374. // Tests a failed EXPECT_PRED4 where the
  1375. // predicate-formatter is a functor on a built-in type (int).
  1376. TEST_F(EXPECT_PRED4Test, FunctorOnBuiltInTypeFailure) {
  1377. EXPECT_NONFATAL_FAILURE({ // NOLINT
  1378. EXPECT_PRED4(PredFunctor4(),
  1379. n1_++,
  1380. n2_++,
  1381. n3_++,
  1382. n4_++);
  1383. finished_ = true;
  1384. }, "");
  1385. }
  1386. // Tests a failed EXPECT_PRED4 where the
  1387. // predicate-formatter is a functor on a user-defined type (Bool).
  1388. TEST_F(EXPECT_PRED4Test, FunctorOnUserTypeFailure) {
  1389. EXPECT_NONFATAL_FAILURE({ // NOLINT
  1390. EXPECT_PRED4(PredFunctor4(),
  1391. Bool(n1_++),
  1392. Bool(n2_++),
  1393. Bool(n3_++),
  1394. Bool(n4_++));
  1395. finished_ = true;
  1396. }, "");
  1397. }
  1398. // Tests a successful ASSERT_PRED4 where the
  1399. // predicate-formatter is a function on a built-in type (int).
  1400. TEST_F(ASSERT_PRED4Test, FunctionOnBuiltInTypeSuccess) {
  1401. ASSERT_PRED4(PredFunction4Int,
  1402. ++n1_,
  1403. ++n2_,
  1404. ++n3_,
  1405. ++n4_);
  1406. finished_ = true;
  1407. }
  1408. // Tests a successful ASSERT_PRED4 where the
  1409. // predicate-formatter is a function on a user-defined type (Bool).
  1410. TEST_F(ASSERT_PRED4Test, FunctionOnUserTypeSuccess) {
  1411. ASSERT_PRED4(PredFunction4Bool,
  1412. Bool(++n1_),
  1413. Bool(++n2_),
  1414. Bool(++n3_),
  1415. Bool(++n4_));
  1416. finished_ = true;
  1417. }
  1418. // Tests a successful ASSERT_PRED4 where the
  1419. // predicate-formatter is a functor on a built-in type (int).
  1420. TEST_F(ASSERT_PRED4Test, FunctorOnBuiltInTypeSuccess) {
  1421. ASSERT_PRED4(PredFunctor4(),
  1422. ++n1_,
  1423. ++n2_,
  1424. ++n3_,
  1425. ++n4_);
  1426. finished_ = true;
  1427. }
  1428. // Tests a successful ASSERT_PRED4 where the
  1429. // predicate-formatter is a functor on a user-defined type (Bool).
  1430. TEST_F(ASSERT_PRED4Test, FunctorOnUserTypeSuccess) {
  1431. ASSERT_PRED4(PredFunctor4(),
  1432. Bool(++n1_),
  1433. Bool(++n2_),
  1434. Bool(++n3_),
  1435. Bool(++n4_));
  1436. finished_ = true;
  1437. }
  1438. // Tests a failed ASSERT_PRED4 where the
  1439. // predicate-formatter is a function on a built-in type (int).
  1440. TEST_F(ASSERT_PRED4Test, FunctionOnBuiltInTypeFailure) {
  1441. expected_to_finish_ = false;
  1442. EXPECT_FATAL_FAILURE({ // NOLINT
  1443. ASSERT_PRED4(PredFunction4Int,
  1444. n1_++,
  1445. n2_++,
  1446. n3_++,
  1447. n4_++);
  1448. finished_ = true;
  1449. }, "");
  1450. }
  1451. // Tests a failed ASSERT_PRED4 where the
  1452. // predicate-formatter is a function on a user-defined type (Bool).
  1453. TEST_F(ASSERT_PRED4Test, FunctionOnUserTypeFailure) {
  1454. expected_to_finish_ = false;
  1455. EXPECT_FATAL_FAILURE({ // NOLINT
  1456. ASSERT_PRED4(PredFunction4Bool,
  1457. Bool(n1_++),
  1458. Bool(n2_++),
  1459. Bool(n3_++),
  1460. Bool(n4_++));
  1461. finished_ = true;
  1462. }, "");
  1463. }
  1464. // Tests a failed ASSERT_PRED4 where the
  1465. // predicate-formatter is a functor on a built-in type (int).
  1466. TEST_F(ASSERT_PRED4Test, FunctorOnBuiltInTypeFailure) {
  1467. expected_to_finish_ = false;
  1468. EXPECT_FATAL_FAILURE({ // NOLINT
  1469. ASSERT_PRED4(PredFunctor4(),
  1470. n1_++,
  1471. n2_++,
  1472. n3_++,
  1473. n4_++);
  1474. finished_ = true;
  1475. }, "");
  1476. }
  1477. // Tests a failed ASSERT_PRED4 where the
  1478. // predicate-formatter is a functor on a user-defined type (Bool).
  1479. TEST_F(ASSERT_PRED4Test, FunctorOnUserTypeFailure) {
  1480. expected_to_finish_ = false;
  1481. EXPECT_FATAL_FAILURE({ // NOLINT
  1482. ASSERT_PRED4(PredFunctor4(),
  1483. Bool(n1_++),
  1484. Bool(n2_++),
  1485. Bool(n3_++),
  1486. Bool(n4_++));
  1487. finished_ = true;
  1488. }, "");
  1489. }
  1490. // Tests a successful EXPECT_PRED_FORMAT4 where the
  1491. // predicate-formatter is a function on a built-in type (int).
  1492. TEST_F(EXPECT_PRED_FORMAT4Test, FunctionOnBuiltInTypeSuccess) {
  1493. EXPECT_PRED_FORMAT4(PredFormatFunction4,
  1494. ++n1_,
  1495. ++n2_,
  1496. ++n3_,
  1497. ++n4_);
  1498. finished_ = true;
  1499. }
  1500. // Tests a successful EXPECT_PRED_FORMAT4 where the
  1501. // predicate-formatter is a function on a user-defined type (Bool).
  1502. TEST_F(EXPECT_PRED_FORMAT4Test, FunctionOnUserTypeSuccess) {
  1503. EXPECT_PRED_FORMAT4(PredFormatFunction4,
  1504. Bool(++n1_),
  1505. Bool(++n2_),
  1506. Bool(++n3_),
  1507. Bool(++n4_));
  1508. finished_ = true;
  1509. }
  1510. // Tests a successful EXPECT_PRED_FORMAT4 where the
  1511. // predicate-formatter is a functor on a built-in type (int).
  1512. TEST_F(EXPECT_PRED_FORMAT4Test, FunctorOnBuiltInTypeSuccess) {
  1513. EXPECT_PRED_FORMAT4(PredFormatFunctor4(),
  1514. ++n1_,
  1515. ++n2_,
  1516. ++n3_,
  1517. ++n4_);
  1518. finished_ = true;
  1519. }
  1520. // Tests a successful EXPECT_PRED_FORMAT4 where the
  1521. // predicate-formatter is a functor on a user-defined type (Bool).
  1522. TEST_F(EXPECT_PRED_FORMAT4Test, FunctorOnUserTypeSuccess) {
  1523. EXPECT_PRED_FORMAT4(PredFormatFunctor4(),
  1524. Bool(++n1_),
  1525. Bool(++n2_),
  1526. Bool(++n3_),
  1527. Bool(++n4_));
  1528. finished_ = true;
  1529. }
  1530. // Tests a failed EXPECT_PRED_FORMAT4 where the
  1531. // predicate-formatter is a function on a built-in type (int).
  1532. TEST_F(EXPECT_PRED_FORMAT4Test, FunctionOnBuiltInTypeFailure) {
  1533. EXPECT_NONFATAL_FAILURE({ // NOLINT
  1534. EXPECT_PRED_FORMAT4(PredFormatFunction4,
  1535. n1_++,
  1536. n2_++,
  1537. n3_++,
  1538. n4_++);
  1539. finished_ = true;
  1540. }, "");
  1541. }
  1542. // Tests a failed EXPECT_PRED_FORMAT4 where the
  1543. // predicate-formatter is a function on a user-defined type (Bool).
  1544. TEST_F(EXPECT_PRED_FORMAT4Test, FunctionOnUserTypeFailure) {
  1545. EXPECT_NONFATAL_FAILURE({ // NOLINT
  1546. EXPECT_PRED_FORMAT4(PredFormatFunction4,
  1547. Bool(n1_++),
  1548. Bool(n2_++),
  1549. Bool(n3_++),
  1550. Bool(n4_++));
  1551. finished_ = true;
  1552. }, "");
  1553. }
  1554. // Tests a failed EXPECT_PRED_FORMAT4 where the
  1555. // predicate-formatter is a functor on a built-in type (int).
  1556. TEST_F(EXPECT_PRED_FORMAT4Test, FunctorOnBuiltInTypeFailure) {
  1557. EXPECT_NONFATAL_FAILURE({ // NOLINT
  1558. EXPECT_PRED_FORMAT4(PredFormatFunctor4(),
  1559. n1_++,
  1560. n2_++,
  1561. n3_++,
  1562. n4_++);
  1563. finished_ = true;
  1564. }, "");
  1565. }
  1566. // Tests a failed EXPECT_PRED_FORMAT4 where the
  1567. // predicate-formatter is a functor on a user-defined type (Bool).
  1568. TEST_F(EXPECT_PRED_FORMAT4Test, FunctorOnUserTypeFailure) {
  1569. EXPECT_NONFATAL_FAILURE({ // NOLINT
  1570. EXPECT_PRED_FORMAT4(PredFormatFunctor4(),
  1571. Bool(n1_++),
  1572. Bool(n2_++),
  1573. Bool(n3_++),
  1574. Bool(n4_++));
  1575. finished_ = true;
  1576. }, "");
  1577. }
  1578. // Tests a successful ASSERT_PRED_FORMAT4 where the
  1579. // predicate-formatter is a function on a built-in type (int).
  1580. TEST_F(ASSERT_PRED_FORMAT4Test, FunctionOnBuiltInTypeSuccess) {
  1581. ASSERT_PRED_FORMAT4(PredFormatFunction4,
  1582. ++n1_,
  1583. ++n2_,
  1584. ++n3_,
  1585. ++n4_);
  1586. finished_ = true;
  1587. }
  1588. // Tests a successful ASSERT_PRED_FORMAT4 where the
  1589. // predicate-formatter is a function on a user-defined type (Bool).
  1590. TEST_F(ASSERT_PRED_FORMAT4Test, FunctionOnUserTypeSuccess) {
  1591. ASSERT_PRED_FORMAT4(PredFormatFunction4,
  1592. Bool(++n1_),
  1593. Bool(++n2_),
  1594. Bool(++n3_),
  1595. Bool(++n4_));
  1596. finished_ = true;
  1597. }
  1598. // Tests a successful ASSERT_PRED_FORMAT4 where the
  1599. // predicate-formatter is a functor on a built-in type (int).
  1600. TEST_F(ASSERT_PRED_FORMAT4Test, FunctorOnBuiltInTypeSuccess) {
  1601. ASSERT_PRED_FORMAT4(PredFormatFunctor4(),
  1602. ++n1_,
  1603. ++n2_,
  1604. ++n3_,
  1605. ++n4_);
  1606. finished_ = true;
  1607. }
  1608. // Tests a successful ASSERT_PRED_FORMAT4 where the
  1609. // predicate-formatter is a functor on a user-defined type (Bool).
  1610. TEST_F(ASSERT_PRED_FORMAT4Test, FunctorOnUserTypeSuccess) {
  1611. ASSERT_PRED_FORMAT4(PredFormatFunctor4(),
  1612. Bool(++n1_),
  1613. Bool(++n2_),
  1614. Bool(++n3_),
  1615. Bool(++n4_));
  1616. finished_ = true;
  1617. }
  1618. // Tests a failed ASSERT_PRED_FORMAT4 where the
  1619. // predicate-formatter is a function on a built-in type (int).
  1620. TEST_F(ASSERT_PRED_FORMAT4Test, FunctionOnBuiltInTypeFailure) {
  1621. expected_to_finish_ = false;
  1622. EXPECT_FATAL_FAILURE({ // NOLINT
  1623. ASSERT_PRED_FORMAT4(PredFormatFunction4,
  1624. n1_++,
  1625. n2_++,
  1626. n3_++,
  1627. n4_++);
  1628. finished_ = true;
  1629. }, "");
  1630. }
  1631. // Tests a failed ASSERT_PRED_FORMAT4 where the
  1632. // predicate-formatter is a function on a user-defined type (Bool).
  1633. TEST_F(ASSERT_PRED_FORMAT4Test, FunctionOnUserTypeFailure) {
  1634. expected_to_finish_ = false;
  1635. EXPECT_FATAL_FAILURE({ // NOLINT
  1636. ASSERT_PRED_FORMAT4(PredFormatFunction4,
  1637. Bool(n1_++),
  1638. Bool(n2_++),
  1639. Bool(n3_++),
  1640. Bool(n4_++));
  1641. finished_ = true;
  1642. }, "");
  1643. }
  1644. // Tests a failed ASSERT_PRED_FORMAT4 where the
  1645. // predicate-formatter is a functor on a built-in type (int).
  1646. TEST_F(ASSERT_PRED_FORMAT4Test, FunctorOnBuiltInTypeFailure) {
  1647. expected_to_finish_ = false;
  1648. EXPECT_FATAL_FAILURE({ // NOLINT
  1649. ASSERT_PRED_FORMAT4(PredFormatFunctor4(),
  1650. n1_++,
  1651. n2_++,
  1652. n3_++,
  1653. n4_++);
  1654. finished_ = true;
  1655. }, "");
  1656. }
  1657. // Tests a failed ASSERT_PRED_FORMAT4 where the
  1658. // predicate-formatter is a functor on a user-defined type (Bool).
  1659. TEST_F(ASSERT_PRED_FORMAT4Test, FunctorOnUserTypeFailure) {
  1660. expected_to_finish_ = false;
  1661. EXPECT_FATAL_FAILURE({ // NOLINT
  1662. ASSERT_PRED_FORMAT4(PredFormatFunctor4(),
  1663. Bool(n1_++),
  1664. Bool(n2_++),
  1665. Bool(n3_++),
  1666. Bool(n4_++));
  1667. finished_ = true;
  1668. }, "");
  1669. }
  1670. // Sample functions/functors for testing 5-ary predicate assertions.
  1671. // A 5-ary predicate function.
  1672. template <typename T1, typename T2, typename T3, typename T4, typename T5>
  1673. bool PredFunction5(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5) {
  1674. return v1 + v2 + v3 + v4 + v5 > 0;
  1675. }
  1676. // The following two functions are needed because a compiler doesn't have
  1677. // a context yet to know which template function must be instantiated.
  1678. bool PredFunction5Int(int v1, int v2, int v3, int v4, int v5) {
  1679. return v1 + v2 + v3 + v4 + v5 > 0;
  1680. }
  1681. bool PredFunction5Bool(Bool v1, Bool v2, Bool v3, Bool v4, Bool v5) {
  1682. return v1 + v2 + v3 + v4 + v5 > 0;
  1683. }
  1684. // A 5-ary predicate functor.
  1685. struct PredFunctor5 {
  1686. template <typename T1, typename T2, typename T3, typename T4, typename T5>
  1687. bool operator()(const T1& v1,
  1688. const T2& v2,
  1689. const T3& v3,
  1690. const T4& v4,
  1691. const T5& v5) {
  1692. return v1 + v2 + v3 + v4 + v5 > 0;
  1693. }
  1694. };
  1695. // A 5-ary predicate-formatter function.
  1696. template <typename T1, typename T2, typename T3, typename T4, typename T5>
  1697. testing::AssertionResult PredFormatFunction5(const char* e1,
  1698. const char* e2,
  1699. const char* e3,
  1700. const char* e4,
  1701. const char* e5,
  1702. const T1& v1,
  1703. const T2& v2,
  1704. const T3& v3,
  1705. const T4& v4,
  1706. const T5& v5) {
  1707. if (PredFunction5(v1, v2, v3, v4, v5))
  1708. return testing::AssertionSuccess();
  1709. return testing::AssertionFailure()
  1710. << e1 << " + " << e2 << " + " << e3 << " + " << e4 << " + " << e5
  1711. << " is expected to be positive, but evaluates to "
  1712. << v1 + v2 + v3 + v4 + v5 << ".";
  1713. }
  1714. // A 5-ary predicate-formatter functor.
  1715. struct PredFormatFunctor5 {
  1716. template <typename T1, typename T2, typename T3, typename T4, typename T5>
  1717. testing::AssertionResult operator()(const char* e1,
  1718. const char* e2,
  1719. const char* e3,
  1720. const char* e4,
  1721. const char* e5,
  1722. const T1& v1,
  1723. const T2& v2,
  1724. const T3& v3,
  1725. const T4& v4,
  1726. const T5& v5) const {
  1727. return PredFormatFunction5(e1, e2, e3, e4, e5, v1, v2, v3, v4, v5);
  1728. }
  1729. };
  1730. // Tests for {EXPECT|ASSERT}_PRED_FORMAT5.
  1731. class Predicate5Test : public testing::Test {
  1732. protected:
  1733. void SetUp() override {
  1734. expected_to_finish_ = true;
  1735. finished_ = false;
  1736. n1_ = n2_ = n3_ = n4_ = n5_ = 0;
  1737. }
  1738. void TearDown() override {
  1739. // Verifies that each of the predicate's arguments was evaluated
  1740. // exactly once.
  1741. EXPECT_EQ(1, n1_) <<
  1742. "The predicate assertion didn't evaluate argument 2 "
  1743. "exactly once.";
  1744. EXPECT_EQ(1, n2_) <<
  1745. "The predicate assertion didn't evaluate argument 3 "
  1746. "exactly once.";
  1747. EXPECT_EQ(1, n3_) <<
  1748. "The predicate assertion didn't evaluate argument 4 "
  1749. "exactly once.";
  1750. EXPECT_EQ(1, n4_) <<
  1751. "The predicate assertion didn't evaluate argument 5 "
  1752. "exactly once.";
  1753. EXPECT_EQ(1, n5_) <<
  1754. "The predicate assertion didn't evaluate argument 6 "
  1755. "exactly once.";
  1756. // Verifies that the control flow in the test function is expected.
  1757. if (expected_to_finish_ && !finished_) {
  1758. FAIL() << "The predicate assertion unexpactedly aborted the test.";
  1759. } else if (!expected_to_finish_ && finished_) {
  1760. FAIL() << "The failed predicate assertion didn't abort the test "
  1761. "as expected.";
  1762. }
  1763. }
  1764. // true if and only if the test function is expected to run to finish.
  1765. static bool expected_to_finish_;
  1766. // true if and only if the test function did run to finish.
  1767. static bool finished_;
  1768. static int n1_;
  1769. static int n2_;
  1770. static int n3_;
  1771. static int n4_;
  1772. static int n5_;
  1773. };
  1774. bool Predicate5Test::expected_to_finish_;
  1775. bool Predicate5Test::finished_;
  1776. int Predicate5Test::n1_;
  1777. int Predicate5Test::n2_;
  1778. int Predicate5Test::n3_;
  1779. int Predicate5Test::n4_;
  1780. int Predicate5Test::n5_;
  1781. typedef Predicate5Test EXPECT_PRED_FORMAT5Test;
  1782. typedef Predicate5Test ASSERT_PRED_FORMAT5Test;
  1783. typedef Predicate5Test EXPECT_PRED5Test;
  1784. typedef Predicate5Test ASSERT_PRED5Test;
  1785. // Tests a successful EXPECT_PRED5 where the
  1786. // predicate-formatter is a function on a built-in type (int).
  1787. TEST_F(EXPECT_PRED5Test, FunctionOnBuiltInTypeSuccess) {
  1788. EXPECT_PRED5(PredFunction5Int,
  1789. ++n1_,
  1790. ++n2_,
  1791. ++n3_,
  1792. ++n4_,
  1793. ++n5_);
  1794. finished_ = true;
  1795. }
  1796. // Tests a successful EXPECT_PRED5 where the
  1797. // predicate-formatter is a function on a user-defined type (Bool).
  1798. TEST_F(EXPECT_PRED5Test, FunctionOnUserTypeSuccess) {
  1799. EXPECT_PRED5(PredFunction5Bool,
  1800. Bool(++n1_),
  1801. Bool(++n2_),
  1802. Bool(++n3_),
  1803. Bool(++n4_),
  1804. Bool(++n5_));
  1805. finished_ = true;
  1806. }
  1807. // Tests a successful EXPECT_PRED5 where the
  1808. // predicate-formatter is a functor on a built-in type (int).
  1809. TEST_F(EXPECT_PRED5Test, FunctorOnBuiltInTypeSuccess) {
  1810. EXPECT_PRED5(PredFunctor5(),
  1811. ++n1_,
  1812. ++n2_,
  1813. ++n3_,
  1814. ++n4_,
  1815. ++n5_);
  1816. finished_ = true;
  1817. }
  1818. // Tests a successful EXPECT_PRED5 where the
  1819. // predicate-formatter is a functor on a user-defined type (Bool).
  1820. TEST_F(EXPECT_PRED5Test, FunctorOnUserTypeSuccess) {
  1821. EXPECT_PRED5(PredFunctor5(),
  1822. Bool(++n1_),
  1823. Bool(++n2_),
  1824. Bool(++n3_),
  1825. Bool(++n4_),
  1826. Bool(++n5_));
  1827. finished_ = true;
  1828. }
  1829. // Tests a failed EXPECT_PRED5 where the
  1830. // predicate-formatter is a function on a built-in type (int).
  1831. TEST_F(EXPECT_PRED5Test, FunctionOnBuiltInTypeFailure) {
  1832. EXPECT_NONFATAL_FAILURE({ // NOLINT
  1833. EXPECT_PRED5(PredFunction5Int,
  1834. n1_++,
  1835. n2_++,
  1836. n3_++,
  1837. n4_++,
  1838. n5_++);
  1839. finished_ = true;
  1840. }, "");
  1841. }
  1842. // Tests a failed EXPECT_PRED5 where the
  1843. // predicate-formatter is a function on a user-defined type (Bool).
  1844. TEST_F(EXPECT_PRED5Test, FunctionOnUserTypeFailure) {
  1845. EXPECT_NONFATAL_FAILURE({ // NOLINT
  1846. EXPECT_PRED5(PredFunction5Bool,
  1847. Bool(n1_++),
  1848. Bool(n2_++),
  1849. Bool(n3_++),
  1850. Bool(n4_++),
  1851. Bool(n5_++));
  1852. finished_ = true;
  1853. }, "");
  1854. }
  1855. // Tests a failed EXPECT_PRED5 where the
  1856. // predicate-formatter is a functor on a built-in type (int).
  1857. TEST_F(EXPECT_PRED5Test, FunctorOnBuiltInTypeFailure) {
  1858. EXPECT_NONFATAL_FAILURE({ // NOLINT
  1859. EXPECT_PRED5(PredFunctor5(),
  1860. n1_++,
  1861. n2_++,
  1862. n3_++,
  1863. n4_++,
  1864. n5_++);
  1865. finished_ = true;
  1866. }, "");
  1867. }
  1868. // Tests a failed EXPECT_PRED5 where the
  1869. // predicate-formatter is a functor on a user-defined type (Bool).
  1870. TEST_F(EXPECT_PRED5Test, FunctorOnUserTypeFailure) {
  1871. EXPECT_NONFATAL_FAILURE({ // NOLINT
  1872. EXPECT_PRED5(PredFunctor5(),
  1873. Bool(n1_++),
  1874. Bool(n2_++),
  1875. Bool(n3_++),
  1876. Bool(n4_++),
  1877. Bool(n5_++));
  1878. finished_ = true;
  1879. }, "");
  1880. }
  1881. // Tests a successful ASSERT_PRED5 where the
  1882. // predicate-formatter is a function on a built-in type (int).
  1883. TEST_F(ASSERT_PRED5Test, FunctionOnBuiltInTypeSuccess) {
  1884. ASSERT_PRED5(PredFunction5Int,
  1885. ++n1_,
  1886. ++n2_,
  1887. ++n3_,
  1888. ++n4_,
  1889. ++n5_);
  1890. finished_ = true;
  1891. }
  1892. // Tests a successful ASSERT_PRED5 where the
  1893. // predicate-formatter is a function on a user-defined type (Bool).
  1894. TEST_F(ASSERT_PRED5Test, FunctionOnUserTypeSuccess) {
  1895. ASSERT_PRED5(PredFunction5Bool,
  1896. Bool(++n1_),
  1897. Bool(++n2_),
  1898. Bool(++n3_),
  1899. Bool(++n4_),
  1900. Bool(++n5_));
  1901. finished_ = true;
  1902. }
  1903. // Tests a successful ASSERT_PRED5 where the
  1904. // predicate-formatter is a functor on a built-in type (int).
  1905. TEST_F(ASSERT_PRED5Test, FunctorOnBuiltInTypeSuccess) {
  1906. ASSERT_PRED5(PredFunctor5(),
  1907. ++n1_,
  1908. ++n2_,
  1909. ++n3_,
  1910. ++n4_,
  1911. ++n5_);
  1912. finished_ = true;
  1913. }
  1914. // Tests a successful ASSERT_PRED5 where the
  1915. // predicate-formatter is a functor on a user-defined type (Bool).
  1916. TEST_F(ASSERT_PRED5Test, FunctorOnUserTypeSuccess) {
  1917. ASSERT_PRED5(PredFunctor5(),
  1918. Bool(++n1_),
  1919. Bool(++n2_),
  1920. Bool(++n3_),
  1921. Bool(++n4_),
  1922. Bool(++n5_));
  1923. finished_ = true;
  1924. }
  1925. // Tests a failed ASSERT_PRED5 where the
  1926. // predicate-formatter is a function on a built-in type (int).
  1927. TEST_F(ASSERT_PRED5Test, FunctionOnBuiltInTypeFailure) {
  1928. expected_to_finish_ = false;
  1929. EXPECT_FATAL_FAILURE({ // NOLINT
  1930. ASSERT_PRED5(PredFunction5Int,
  1931. n1_++,
  1932. n2_++,
  1933. n3_++,
  1934. n4_++,
  1935. n5_++);
  1936. finished_ = true;
  1937. }, "");
  1938. }
  1939. // Tests a failed ASSERT_PRED5 where the
  1940. // predicate-formatter is a function on a user-defined type (Bool).
  1941. TEST_F(ASSERT_PRED5Test, FunctionOnUserTypeFailure) {
  1942. expected_to_finish_ = false;
  1943. EXPECT_FATAL_FAILURE({ // NOLINT
  1944. ASSERT_PRED5(PredFunction5Bool,
  1945. Bool(n1_++),
  1946. Bool(n2_++),
  1947. Bool(n3_++),
  1948. Bool(n4_++),
  1949. Bool(n5_++));
  1950. finished_ = true;
  1951. }, "");
  1952. }
  1953. // Tests a failed ASSERT_PRED5 where the
  1954. // predicate-formatter is a functor on a built-in type (int).
  1955. TEST_F(ASSERT_PRED5Test, FunctorOnBuiltInTypeFailure) {
  1956. expected_to_finish_ = false;
  1957. EXPECT_FATAL_FAILURE({ // NOLINT
  1958. ASSERT_PRED5(PredFunctor5(),
  1959. n1_++,
  1960. n2_++,
  1961. n3_++,
  1962. n4_++,
  1963. n5_++);
  1964. finished_ = true;
  1965. }, "");
  1966. }
  1967. // Tests a failed ASSERT_PRED5 where the
  1968. // predicate-formatter is a functor on a user-defined type (Bool).
  1969. TEST_F(ASSERT_PRED5Test, FunctorOnUserTypeFailure) {
  1970. expected_to_finish_ = false;
  1971. EXPECT_FATAL_FAILURE({ // NOLINT
  1972. ASSERT_PRED5(PredFunctor5(),
  1973. Bool(n1_++),
  1974. Bool(n2_++),
  1975. Bool(n3_++),
  1976. Bool(n4_++),
  1977. Bool(n5_++));
  1978. finished_ = true;
  1979. }, "");
  1980. }
  1981. // Tests a successful EXPECT_PRED_FORMAT5 where the
  1982. // predicate-formatter is a function on a built-in type (int).
  1983. TEST_F(EXPECT_PRED_FORMAT5Test, FunctionOnBuiltInTypeSuccess) {
  1984. EXPECT_PRED_FORMAT5(PredFormatFunction5,
  1985. ++n1_,
  1986. ++n2_,
  1987. ++n3_,
  1988. ++n4_,
  1989. ++n5_);
  1990. finished_ = true;
  1991. }
  1992. // Tests a successful EXPECT_PRED_FORMAT5 where the
  1993. // predicate-formatter is a function on a user-defined type (Bool).
  1994. TEST_F(EXPECT_PRED_FORMAT5Test, FunctionOnUserTypeSuccess) {
  1995. EXPECT_PRED_FORMAT5(PredFormatFunction5,
  1996. Bool(++n1_),
  1997. Bool(++n2_),
  1998. Bool(++n3_),
  1999. Bool(++n4_),
  2000. Bool(++n5_));
  2001. finished_ = true;
  2002. }
  2003. // Tests a successful EXPECT_PRED_FORMAT5 where the
  2004. // predicate-formatter is a functor on a built-in type (int).
  2005. TEST_F(EXPECT_PRED_FORMAT5Test, FunctorOnBuiltInTypeSuccess) {
  2006. EXPECT_PRED_FORMAT5(PredFormatFunctor5(),
  2007. ++n1_,
  2008. ++n2_,
  2009. ++n3_,
  2010. ++n4_,
  2011. ++n5_);
  2012. finished_ = true;
  2013. }
  2014. // Tests a successful EXPECT_PRED_FORMAT5 where the
  2015. // predicate-formatter is a functor on a user-defined type (Bool).
  2016. TEST_F(EXPECT_PRED_FORMAT5Test, FunctorOnUserTypeSuccess) {
  2017. EXPECT_PRED_FORMAT5(PredFormatFunctor5(),
  2018. Bool(++n1_),
  2019. Bool(++n2_),
  2020. Bool(++n3_),
  2021. Bool(++n4_),
  2022. Bool(++n5_));
  2023. finished_ = true;
  2024. }
  2025. // Tests a failed EXPECT_PRED_FORMAT5 where the
  2026. // predicate-formatter is a function on a built-in type (int).
  2027. TEST_F(EXPECT_PRED_FORMAT5Test, FunctionOnBuiltInTypeFailure) {
  2028. EXPECT_NONFATAL_FAILURE({ // NOLINT
  2029. EXPECT_PRED_FORMAT5(PredFormatFunction5,
  2030. n1_++,
  2031. n2_++,
  2032. n3_++,
  2033. n4_++,
  2034. n5_++);
  2035. finished_ = true;
  2036. }, "");
  2037. }
  2038. // Tests a failed EXPECT_PRED_FORMAT5 where the
  2039. // predicate-formatter is a function on a user-defined type (Bool).
  2040. TEST_F(EXPECT_PRED_FORMAT5Test, FunctionOnUserTypeFailure) {
  2041. EXPECT_NONFATAL_FAILURE({ // NOLINT
  2042. EXPECT_PRED_FORMAT5(PredFormatFunction5,
  2043. Bool(n1_++),
  2044. Bool(n2_++),
  2045. Bool(n3_++),
  2046. Bool(n4_++),
  2047. Bool(n5_++));
  2048. finished_ = true;
  2049. }, "");
  2050. }
  2051. // Tests a failed EXPECT_PRED_FORMAT5 where the
  2052. // predicate-formatter is a functor on a built-in type (int).
  2053. TEST_F(EXPECT_PRED_FORMAT5Test, FunctorOnBuiltInTypeFailure) {
  2054. EXPECT_NONFATAL_FAILURE({ // NOLINT
  2055. EXPECT_PRED_FORMAT5(PredFormatFunctor5(),
  2056. n1_++,
  2057. n2_++,
  2058. n3_++,
  2059. n4_++,
  2060. n5_++);
  2061. finished_ = true;
  2062. }, "");
  2063. }
  2064. // Tests a failed EXPECT_PRED_FORMAT5 where the
  2065. // predicate-formatter is a functor on a user-defined type (Bool).
  2066. TEST_F(EXPECT_PRED_FORMAT5Test, FunctorOnUserTypeFailure) {
  2067. EXPECT_NONFATAL_FAILURE({ // NOLINT
  2068. EXPECT_PRED_FORMAT5(PredFormatFunctor5(),
  2069. Bool(n1_++),
  2070. Bool(n2_++),
  2071. Bool(n3_++),
  2072. Bool(n4_++),
  2073. Bool(n5_++));
  2074. finished_ = true;
  2075. }, "");
  2076. }
  2077. // Tests a successful ASSERT_PRED_FORMAT5 where the
  2078. // predicate-formatter is a function on a built-in type (int).
  2079. TEST_F(ASSERT_PRED_FORMAT5Test, FunctionOnBuiltInTypeSuccess) {
  2080. ASSERT_PRED_FORMAT5(PredFormatFunction5,
  2081. ++n1_,
  2082. ++n2_,
  2083. ++n3_,
  2084. ++n4_,
  2085. ++n5_);
  2086. finished_ = true;
  2087. }
  2088. // Tests a successful ASSERT_PRED_FORMAT5 where the
  2089. // predicate-formatter is a function on a user-defined type (Bool).
  2090. TEST_F(ASSERT_PRED_FORMAT5Test, FunctionOnUserTypeSuccess) {
  2091. ASSERT_PRED_FORMAT5(PredFormatFunction5,
  2092. Bool(++n1_),
  2093. Bool(++n2_),
  2094. Bool(++n3_),
  2095. Bool(++n4_),
  2096. Bool(++n5_));
  2097. finished_ = true;
  2098. }
  2099. // Tests a successful ASSERT_PRED_FORMAT5 where the
  2100. // predicate-formatter is a functor on a built-in type (int).
  2101. TEST_F(ASSERT_PRED_FORMAT5Test, FunctorOnBuiltInTypeSuccess) {
  2102. ASSERT_PRED_FORMAT5(PredFormatFunctor5(),
  2103. ++n1_,
  2104. ++n2_,
  2105. ++n3_,
  2106. ++n4_,
  2107. ++n5_);
  2108. finished_ = true;
  2109. }
  2110. // Tests a successful ASSERT_PRED_FORMAT5 where the
  2111. // predicate-formatter is a functor on a user-defined type (Bool).
  2112. TEST_F(ASSERT_PRED_FORMAT5Test, FunctorOnUserTypeSuccess) {
  2113. ASSERT_PRED_FORMAT5(PredFormatFunctor5(),
  2114. Bool(++n1_),
  2115. Bool(++n2_),
  2116. Bool(++n3_),
  2117. Bool(++n4_),
  2118. Bool(++n5_));
  2119. finished_ = true;
  2120. }
  2121. // Tests a failed ASSERT_PRED_FORMAT5 where the
  2122. // predicate-formatter is a function on a built-in type (int).
  2123. TEST_F(ASSERT_PRED_FORMAT5Test, FunctionOnBuiltInTypeFailure) {
  2124. expected_to_finish_ = false;
  2125. EXPECT_FATAL_FAILURE({ // NOLINT
  2126. ASSERT_PRED_FORMAT5(PredFormatFunction5,
  2127. n1_++,
  2128. n2_++,
  2129. n3_++,
  2130. n4_++,
  2131. n5_++);
  2132. finished_ = true;
  2133. }, "");
  2134. }
  2135. // Tests a failed ASSERT_PRED_FORMAT5 where the
  2136. // predicate-formatter is a function on a user-defined type (Bool).
  2137. TEST_F(ASSERT_PRED_FORMAT5Test, FunctionOnUserTypeFailure) {
  2138. expected_to_finish_ = false;
  2139. EXPECT_FATAL_FAILURE({ // NOLINT
  2140. ASSERT_PRED_FORMAT5(PredFormatFunction5,
  2141. Bool(n1_++),
  2142. Bool(n2_++),
  2143. Bool(n3_++),
  2144. Bool(n4_++),
  2145. Bool(n5_++));
  2146. finished_ = true;
  2147. }, "");
  2148. }
  2149. // Tests a failed ASSERT_PRED_FORMAT5 where the
  2150. // predicate-formatter is a functor on a built-in type (int).
  2151. TEST_F(ASSERT_PRED_FORMAT5Test, FunctorOnBuiltInTypeFailure) {
  2152. expected_to_finish_ = false;
  2153. EXPECT_FATAL_FAILURE({ // NOLINT
  2154. ASSERT_PRED_FORMAT5(PredFormatFunctor5(),
  2155. n1_++,
  2156. n2_++,
  2157. n3_++,
  2158. n4_++,
  2159. n5_++);
  2160. finished_ = true;
  2161. }, "");
  2162. }
  2163. // Tests a failed ASSERT_PRED_FORMAT5 where the
  2164. // predicate-formatter is a functor on a user-defined type (Bool).
  2165. TEST_F(ASSERT_PRED_FORMAT5Test, FunctorOnUserTypeFailure) {
  2166. expected_to_finish_ = false;
  2167. EXPECT_FATAL_FAILURE({ // NOLINT
  2168. ASSERT_PRED_FORMAT5(PredFormatFunctor5(),
  2169. Bool(n1_++),
  2170. Bool(n2_++),
  2171. Bool(n3_++),
  2172. Bool(n4_++),
  2173. Bool(n5_++));
  2174. finished_ = true;
  2175. }, "");
  2176. }