You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2427 lines
76 KiB

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