1 // Copyright 2006, Google Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
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
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.
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.
30 // This file is AUTOMATICALLY GENERATED on 01/02/2018 by command
31 // 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
33 // Regression test for gtest_pred_impl.h
35 // This file is generated by a script and quite long. If you intend to
36 // learn how Google Test works by reading its unit tests, read
37 // gtest_unittest.cc instead.
39 // This is intended as a regression test for the Google Test predicate
40 // assertions. We compile it as part of the gtest_unittest target
41 // only to keep the implementation tidy and compact, as it is quite
42 // involved to set up the stage for testing Google Test using Google
45 // Currently, gtest_unittest takes ~11 seconds to run in the testing
46 // daemon. In the future, if it grows too large and needs much more
47 // time to finish, we should consider separating this file into a
48 // stand-alone regression test.
52 #include "gtest/gtest.h"
53 #include "gtest/gtest-spi.h"
55 // A user-defined data type.
57 explicit Bool(int val) : value(val != 0) {}
59 bool operator>(int n) const { return value > Bool(n).value; }
61 Bool operator+(const Bool& rhs) const { return Bool(value + rhs.value); }
63 bool operator==(const Bool& rhs) const { return value == rhs.value; }
68 // Enables Bool to be used in assertions.
69 std::ostream& operator<<(std::ostream& os, const Bool& x) {
70 return os << (x.value ? "true" : "false");
73 // Sample functions/functors for testing unary predicate assertions.
75 // A unary predicate function.
76 template <typename T1>
77 bool PredFunction1(T1 v1) {
81 // The following two functions are needed to circumvent a bug in
82 // gcc 2.95.3, which sometimes has problem with the above template
84 bool PredFunction1Int(int v1) {
87 bool PredFunction1Bool(Bool v1) {
91 // A unary predicate functor.
93 template <typename T1>
94 bool operator()(const T1& v1) {
99 // A unary predicate-formatter function.
100 template <typename T1>
101 testing::AssertionResult PredFormatFunction1(const char* e1,
103 if (PredFunction1(v1))
104 return testing::AssertionSuccess();
106 return testing::AssertionFailure()
108 << " is expected to be positive, but evaluates to "
112 // A unary predicate-formatter functor.
113 struct PredFormatFunctor1 {
114 template <typename T1>
115 testing::AssertionResult operator()(const char* e1,
116 const T1& v1) const {
117 return PredFormatFunction1(e1, v1);
121 // Tests for {EXPECT|ASSERT}_PRED_FORMAT1.
123 class Predicate1Test : public testing::Test {
125 virtual void SetUp() {
126 expected_to_finish_ = true;
131 virtual void TearDown() {
132 // Verifies that each of the predicate's arguments was evaluated
135 "The predicate assertion didn't evaluate argument 2 "
138 // Verifies that the control flow in the test function is expected.
139 if (expected_to_finish_ && !finished_) {
140 FAIL() << "The predicate assertion unexpactedly aborted the test.";
141 } else if (!expected_to_finish_ && finished_) {
142 FAIL() << "The failed predicate assertion didn't abort the test "
147 // true iff the test function is expected to run to finish.
148 static bool expected_to_finish_;
150 // true iff the test function did run to finish.
151 static bool finished_;
156 bool Predicate1Test::expected_to_finish_;
157 bool Predicate1Test::finished_;
158 int Predicate1Test::n1_;
160 typedef Predicate1Test EXPECT_PRED_FORMAT1Test;
161 typedef Predicate1Test ASSERT_PRED_FORMAT1Test;
162 typedef Predicate1Test EXPECT_PRED1Test;
163 typedef Predicate1Test ASSERT_PRED1Test;
165 // Tests a successful EXPECT_PRED1 where the
166 // predicate-formatter is a function on a built-in type (int).
167 TEST_F(EXPECT_PRED1Test, FunctionOnBuiltInTypeSuccess) {
168 EXPECT_PRED1(PredFunction1Int,
173 // Tests a successful EXPECT_PRED1 where the
174 // predicate-formatter is a function on a user-defined type (Bool).
175 TEST_F(EXPECT_PRED1Test, FunctionOnUserTypeSuccess) {
176 EXPECT_PRED1(PredFunction1Bool,
181 // Tests a successful EXPECT_PRED1 where the
182 // predicate-formatter is a functor on a built-in type (int).
183 TEST_F(EXPECT_PRED1Test, FunctorOnBuiltInTypeSuccess) {
184 EXPECT_PRED1(PredFunctor1(),
189 // Tests a successful EXPECT_PRED1 where the
190 // predicate-formatter is a functor on a user-defined type (Bool).
191 TEST_F(EXPECT_PRED1Test, FunctorOnUserTypeSuccess) {
192 EXPECT_PRED1(PredFunctor1(),
197 // Tests a failed EXPECT_PRED1 where the
198 // predicate-formatter is a function on a built-in type (int).
199 TEST_F(EXPECT_PRED1Test, FunctionOnBuiltInTypeFailure) {
200 EXPECT_NONFATAL_FAILURE({ // NOLINT
201 EXPECT_PRED1(PredFunction1Int,
207 // Tests a failed EXPECT_PRED1 where the
208 // predicate-formatter is a function on a user-defined type (Bool).
209 TEST_F(EXPECT_PRED1Test, FunctionOnUserTypeFailure) {
210 EXPECT_NONFATAL_FAILURE({ // NOLINT
211 EXPECT_PRED1(PredFunction1Bool,
217 // Tests a failed EXPECT_PRED1 where the
218 // predicate-formatter is a functor on a built-in type (int).
219 TEST_F(EXPECT_PRED1Test, FunctorOnBuiltInTypeFailure) {
220 EXPECT_NONFATAL_FAILURE({ // NOLINT
221 EXPECT_PRED1(PredFunctor1(),
227 // Tests a failed EXPECT_PRED1 where the
228 // predicate-formatter is a functor on a user-defined type (Bool).
229 TEST_F(EXPECT_PRED1Test, FunctorOnUserTypeFailure) {
230 EXPECT_NONFATAL_FAILURE({ // NOLINT
231 EXPECT_PRED1(PredFunctor1(),
237 // Tests a successful ASSERT_PRED1 where the
238 // predicate-formatter is a function on a built-in type (int).
239 TEST_F(ASSERT_PRED1Test, FunctionOnBuiltInTypeSuccess) {
240 ASSERT_PRED1(PredFunction1Int,
245 // Tests a successful ASSERT_PRED1 where the
246 // predicate-formatter is a function on a user-defined type (Bool).
247 TEST_F(ASSERT_PRED1Test, FunctionOnUserTypeSuccess) {
248 ASSERT_PRED1(PredFunction1Bool,
253 // Tests a successful ASSERT_PRED1 where the
254 // predicate-formatter is a functor on a built-in type (int).
255 TEST_F(ASSERT_PRED1Test, FunctorOnBuiltInTypeSuccess) {
256 ASSERT_PRED1(PredFunctor1(),
261 // Tests a successful ASSERT_PRED1 where the
262 // predicate-formatter is a functor on a user-defined type (Bool).
263 TEST_F(ASSERT_PRED1Test, FunctorOnUserTypeSuccess) {
264 ASSERT_PRED1(PredFunctor1(),
269 // Tests a failed ASSERT_PRED1 where the
270 // predicate-formatter is a function on a built-in type (int).
271 TEST_F(ASSERT_PRED1Test, FunctionOnBuiltInTypeFailure) {
272 expected_to_finish_ = false;
273 EXPECT_FATAL_FAILURE({ // NOLINT
274 ASSERT_PRED1(PredFunction1Int,
280 // Tests a failed ASSERT_PRED1 where the
281 // predicate-formatter is a function on a user-defined type (Bool).
282 TEST_F(ASSERT_PRED1Test, FunctionOnUserTypeFailure) {
283 expected_to_finish_ = false;
284 EXPECT_FATAL_FAILURE({ // NOLINT
285 ASSERT_PRED1(PredFunction1Bool,
291 // Tests a failed ASSERT_PRED1 where the
292 // predicate-formatter is a functor on a built-in type (int).
293 TEST_F(ASSERT_PRED1Test, FunctorOnBuiltInTypeFailure) {
294 expected_to_finish_ = false;
295 EXPECT_FATAL_FAILURE({ // NOLINT
296 ASSERT_PRED1(PredFunctor1(),
302 // Tests a failed ASSERT_PRED1 where the
303 // predicate-formatter is a functor on a user-defined type (Bool).
304 TEST_F(ASSERT_PRED1Test, FunctorOnUserTypeFailure) {
305 expected_to_finish_ = false;
306 EXPECT_FATAL_FAILURE({ // NOLINT
307 ASSERT_PRED1(PredFunctor1(),
313 // Tests a successful EXPECT_PRED_FORMAT1 where the
314 // predicate-formatter is a function on a built-in type (int).
315 TEST_F(EXPECT_PRED_FORMAT1Test, FunctionOnBuiltInTypeSuccess) {
316 EXPECT_PRED_FORMAT1(PredFormatFunction1,
321 // Tests a successful EXPECT_PRED_FORMAT1 where the
322 // predicate-formatter is a function on a user-defined type (Bool).
323 TEST_F(EXPECT_PRED_FORMAT1Test, FunctionOnUserTypeSuccess) {
324 EXPECT_PRED_FORMAT1(PredFormatFunction1,
329 // Tests a successful EXPECT_PRED_FORMAT1 where the
330 // predicate-formatter is a functor on a built-in type (int).
331 TEST_F(EXPECT_PRED_FORMAT1Test, FunctorOnBuiltInTypeSuccess) {
332 EXPECT_PRED_FORMAT1(PredFormatFunctor1(),
337 // Tests a successful EXPECT_PRED_FORMAT1 where the
338 // predicate-formatter is a functor on a user-defined type (Bool).
339 TEST_F(EXPECT_PRED_FORMAT1Test, FunctorOnUserTypeSuccess) {
340 EXPECT_PRED_FORMAT1(PredFormatFunctor1(),
345 // Tests a failed EXPECT_PRED_FORMAT1 where the
346 // predicate-formatter is a function on a built-in type (int).
347 TEST_F(EXPECT_PRED_FORMAT1Test, FunctionOnBuiltInTypeFailure) {
348 EXPECT_NONFATAL_FAILURE({ // NOLINT
349 EXPECT_PRED_FORMAT1(PredFormatFunction1,
355 // Tests a failed EXPECT_PRED_FORMAT1 where the
356 // predicate-formatter is a function on a user-defined type (Bool).
357 TEST_F(EXPECT_PRED_FORMAT1Test, FunctionOnUserTypeFailure) {
358 EXPECT_NONFATAL_FAILURE({ // NOLINT
359 EXPECT_PRED_FORMAT1(PredFormatFunction1,
365 // Tests a failed EXPECT_PRED_FORMAT1 where the
366 // predicate-formatter is a functor on a built-in type (int).
367 TEST_F(EXPECT_PRED_FORMAT1Test, FunctorOnBuiltInTypeFailure) {
368 EXPECT_NONFATAL_FAILURE({ // NOLINT
369 EXPECT_PRED_FORMAT1(PredFormatFunctor1(),
375 // Tests a failed EXPECT_PRED_FORMAT1 where the
376 // predicate-formatter is a functor on a user-defined type (Bool).
377 TEST_F(EXPECT_PRED_FORMAT1Test, FunctorOnUserTypeFailure) {
378 EXPECT_NONFATAL_FAILURE({ // NOLINT
379 EXPECT_PRED_FORMAT1(PredFormatFunctor1(),
385 // Tests a successful ASSERT_PRED_FORMAT1 where the
386 // predicate-formatter is a function on a built-in type (int).
387 TEST_F(ASSERT_PRED_FORMAT1Test, FunctionOnBuiltInTypeSuccess) {
388 ASSERT_PRED_FORMAT1(PredFormatFunction1,
393 // Tests a successful ASSERT_PRED_FORMAT1 where the
394 // predicate-formatter is a function on a user-defined type (Bool).
395 TEST_F(ASSERT_PRED_FORMAT1Test, FunctionOnUserTypeSuccess) {
396 ASSERT_PRED_FORMAT1(PredFormatFunction1,
401 // Tests a successful ASSERT_PRED_FORMAT1 where the
402 // predicate-formatter is a functor on a built-in type (int).
403 TEST_F(ASSERT_PRED_FORMAT1Test, FunctorOnBuiltInTypeSuccess) {
404 ASSERT_PRED_FORMAT1(PredFormatFunctor1(),
409 // Tests a successful ASSERT_PRED_FORMAT1 where the
410 // predicate-formatter is a functor on a user-defined type (Bool).
411 TEST_F(ASSERT_PRED_FORMAT1Test, FunctorOnUserTypeSuccess) {
412 ASSERT_PRED_FORMAT1(PredFormatFunctor1(),
417 // Tests a failed ASSERT_PRED_FORMAT1 where the
418 // predicate-formatter is a function on a built-in type (int).
419 TEST_F(ASSERT_PRED_FORMAT1Test, FunctionOnBuiltInTypeFailure) {
420 expected_to_finish_ = false;
421 EXPECT_FATAL_FAILURE({ // NOLINT
422 ASSERT_PRED_FORMAT1(PredFormatFunction1,
428 // Tests a failed ASSERT_PRED_FORMAT1 where the
429 // predicate-formatter is a function on a user-defined type (Bool).
430 TEST_F(ASSERT_PRED_FORMAT1Test, FunctionOnUserTypeFailure) {
431 expected_to_finish_ = false;
432 EXPECT_FATAL_FAILURE({ // NOLINT
433 ASSERT_PRED_FORMAT1(PredFormatFunction1,
439 // Tests a failed ASSERT_PRED_FORMAT1 where the
440 // predicate-formatter is a functor on a built-in type (int).
441 TEST_F(ASSERT_PRED_FORMAT1Test, FunctorOnBuiltInTypeFailure) {
442 expected_to_finish_ = false;
443 EXPECT_FATAL_FAILURE({ // NOLINT
444 ASSERT_PRED_FORMAT1(PredFormatFunctor1(),
450 // Tests a failed ASSERT_PRED_FORMAT1 where the
451 // predicate-formatter is a functor on a user-defined type (Bool).
452 TEST_F(ASSERT_PRED_FORMAT1Test, FunctorOnUserTypeFailure) {
453 expected_to_finish_ = false;
454 EXPECT_FATAL_FAILURE({ // NOLINT
455 ASSERT_PRED_FORMAT1(PredFormatFunctor1(),
460 // Sample functions/functors for testing binary predicate assertions.
462 // A binary predicate function.
463 template <typename T1, typename T2>
464 bool PredFunction2(T1 v1, T2 v2) {
468 // The following two functions are needed to circumvent a bug in
469 // gcc 2.95.3, which sometimes has problem with the above template
471 bool PredFunction2Int(int v1, int v2) {
474 bool PredFunction2Bool(Bool v1, Bool v2) {
478 // A binary predicate functor.
479 struct PredFunctor2 {
480 template <typename T1, typename T2>
481 bool operator()(const T1& v1,
487 // A binary predicate-formatter function.
488 template <typename T1, typename T2>
489 testing::AssertionResult PredFormatFunction2(const char* e1,
493 if (PredFunction2(v1, v2))
494 return testing::AssertionSuccess();
496 return testing::AssertionFailure()
498 << " is expected to be positive, but evaluates to "
502 // A binary predicate-formatter functor.
503 struct PredFormatFunctor2 {
504 template <typename T1, typename T2>
505 testing::AssertionResult operator()(const char* e1,
508 const T2& v2) const {
509 return PredFormatFunction2(e1, e2, v1, v2);
513 // Tests for {EXPECT|ASSERT}_PRED_FORMAT2.
515 class Predicate2Test : public testing::Test {
517 virtual void SetUp() {
518 expected_to_finish_ = true;
523 virtual void TearDown() {
524 // Verifies that each of the predicate's arguments was evaluated
527 "The predicate assertion didn't evaluate argument 2 "
530 "The predicate assertion didn't evaluate argument 3 "
533 // Verifies that the control flow in the test function is expected.
534 if (expected_to_finish_ && !finished_) {
535 FAIL() << "The predicate assertion unexpactedly aborted the test.";
536 } else if (!expected_to_finish_ && finished_) {
537 FAIL() << "The failed predicate assertion didn't abort the test "
542 // true iff the test function is expected to run to finish.
543 static bool expected_to_finish_;
545 // true iff the test function did run to finish.
546 static bool finished_;
552 bool Predicate2Test::expected_to_finish_;
553 bool Predicate2Test::finished_;
554 int Predicate2Test::n1_;
555 int Predicate2Test::n2_;
557 typedef Predicate2Test EXPECT_PRED_FORMAT2Test;
558 typedef Predicate2Test ASSERT_PRED_FORMAT2Test;
559 typedef Predicate2Test EXPECT_PRED2Test;
560 typedef Predicate2Test ASSERT_PRED2Test;
562 // Tests a successful EXPECT_PRED2 where the
563 // predicate-formatter is a function on a built-in type (int).
564 TEST_F(EXPECT_PRED2Test, FunctionOnBuiltInTypeSuccess) {
565 EXPECT_PRED2(PredFunction2Int,
571 // Tests a successful EXPECT_PRED2 where the
572 // predicate-formatter is a function on a user-defined type (Bool).
573 TEST_F(EXPECT_PRED2Test, FunctionOnUserTypeSuccess) {
574 EXPECT_PRED2(PredFunction2Bool,
580 // Tests a successful EXPECT_PRED2 where the
581 // predicate-formatter is a functor on a built-in type (int).
582 TEST_F(EXPECT_PRED2Test, FunctorOnBuiltInTypeSuccess) {
583 EXPECT_PRED2(PredFunctor2(),
589 // Tests a successful EXPECT_PRED2 where the
590 // predicate-formatter is a functor on a user-defined type (Bool).
591 TEST_F(EXPECT_PRED2Test, FunctorOnUserTypeSuccess) {
592 EXPECT_PRED2(PredFunctor2(),
598 // Tests a failed EXPECT_PRED2 where the
599 // predicate-formatter is a function on a built-in type (int).
600 TEST_F(EXPECT_PRED2Test, FunctionOnBuiltInTypeFailure) {
601 EXPECT_NONFATAL_FAILURE({ // NOLINT
602 EXPECT_PRED2(PredFunction2Int,
609 // Tests a failed EXPECT_PRED2 where the
610 // predicate-formatter is a function on a user-defined type (Bool).
611 TEST_F(EXPECT_PRED2Test, FunctionOnUserTypeFailure) {
612 EXPECT_NONFATAL_FAILURE({ // NOLINT
613 EXPECT_PRED2(PredFunction2Bool,
620 // Tests a failed EXPECT_PRED2 where the
621 // predicate-formatter is a functor on a built-in type (int).
622 TEST_F(EXPECT_PRED2Test, FunctorOnBuiltInTypeFailure) {
623 EXPECT_NONFATAL_FAILURE({ // NOLINT
624 EXPECT_PRED2(PredFunctor2(),
631 // Tests a failed EXPECT_PRED2 where the
632 // predicate-formatter is a functor on a user-defined type (Bool).
633 TEST_F(EXPECT_PRED2Test, FunctorOnUserTypeFailure) {
634 EXPECT_NONFATAL_FAILURE({ // NOLINT
635 EXPECT_PRED2(PredFunctor2(),
642 // Tests a successful ASSERT_PRED2 where the
643 // predicate-formatter is a function on a built-in type (int).
644 TEST_F(ASSERT_PRED2Test, FunctionOnBuiltInTypeSuccess) {
645 ASSERT_PRED2(PredFunction2Int,
651 // Tests a successful ASSERT_PRED2 where the
652 // predicate-formatter is a function on a user-defined type (Bool).
653 TEST_F(ASSERT_PRED2Test, FunctionOnUserTypeSuccess) {
654 ASSERT_PRED2(PredFunction2Bool,
660 // Tests a successful ASSERT_PRED2 where the
661 // predicate-formatter is a functor on a built-in type (int).
662 TEST_F(ASSERT_PRED2Test, FunctorOnBuiltInTypeSuccess) {
663 ASSERT_PRED2(PredFunctor2(),
669 // Tests a successful ASSERT_PRED2 where the
670 // predicate-formatter is a functor on a user-defined type (Bool).
671 TEST_F(ASSERT_PRED2Test, FunctorOnUserTypeSuccess) {
672 ASSERT_PRED2(PredFunctor2(),
678 // Tests a failed ASSERT_PRED2 where the
679 // predicate-formatter is a function on a built-in type (int).
680 TEST_F(ASSERT_PRED2Test, FunctionOnBuiltInTypeFailure) {
681 expected_to_finish_ = false;
682 EXPECT_FATAL_FAILURE({ // NOLINT
683 ASSERT_PRED2(PredFunction2Int,
690 // Tests a failed ASSERT_PRED2 where the
691 // predicate-formatter is a function on a user-defined type (Bool).
692 TEST_F(ASSERT_PRED2Test, FunctionOnUserTypeFailure) {
693 expected_to_finish_ = false;
694 EXPECT_FATAL_FAILURE({ // NOLINT
695 ASSERT_PRED2(PredFunction2Bool,
702 // Tests a failed ASSERT_PRED2 where the
703 // predicate-formatter is a functor on a built-in type (int).
704 TEST_F(ASSERT_PRED2Test, FunctorOnBuiltInTypeFailure) {
705 expected_to_finish_ = false;
706 EXPECT_FATAL_FAILURE({ // NOLINT
707 ASSERT_PRED2(PredFunctor2(),
714 // Tests a failed ASSERT_PRED2 where the
715 // predicate-formatter is a functor on a user-defined type (Bool).
716 TEST_F(ASSERT_PRED2Test, FunctorOnUserTypeFailure) {
717 expected_to_finish_ = false;
718 EXPECT_FATAL_FAILURE({ // NOLINT
719 ASSERT_PRED2(PredFunctor2(),
726 // Tests a successful EXPECT_PRED_FORMAT2 where the
727 // predicate-formatter is a function on a built-in type (int).
728 TEST_F(EXPECT_PRED_FORMAT2Test, FunctionOnBuiltInTypeSuccess) {
729 EXPECT_PRED_FORMAT2(PredFormatFunction2,
735 // Tests a successful EXPECT_PRED_FORMAT2 where the
736 // predicate-formatter is a function on a user-defined type (Bool).
737 TEST_F(EXPECT_PRED_FORMAT2Test, FunctionOnUserTypeSuccess) {
738 EXPECT_PRED_FORMAT2(PredFormatFunction2,
744 // Tests a successful EXPECT_PRED_FORMAT2 where the
745 // predicate-formatter is a functor on a built-in type (int).
746 TEST_F(EXPECT_PRED_FORMAT2Test, FunctorOnBuiltInTypeSuccess) {
747 EXPECT_PRED_FORMAT2(PredFormatFunctor2(),
753 // Tests a successful EXPECT_PRED_FORMAT2 where the
754 // predicate-formatter is a functor on a user-defined type (Bool).
755 TEST_F(EXPECT_PRED_FORMAT2Test, FunctorOnUserTypeSuccess) {
756 EXPECT_PRED_FORMAT2(PredFormatFunctor2(),
762 // Tests a failed EXPECT_PRED_FORMAT2 where the
763 // predicate-formatter is a function on a built-in type (int).
764 TEST_F(EXPECT_PRED_FORMAT2Test, FunctionOnBuiltInTypeFailure) {
765 EXPECT_NONFATAL_FAILURE({ // NOLINT
766 EXPECT_PRED_FORMAT2(PredFormatFunction2,
773 // Tests a failed EXPECT_PRED_FORMAT2 where the
774 // predicate-formatter is a function on a user-defined type (Bool).
775 TEST_F(EXPECT_PRED_FORMAT2Test, FunctionOnUserTypeFailure) {
776 EXPECT_NONFATAL_FAILURE({ // NOLINT
777 EXPECT_PRED_FORMAT2(PredFormatFunction2,
784 // Tests a failed EXPECT_PRED_FORMAT2 where the
785 // predicate-formatter is a functor on a built-in type (int).
786 TEST_F(EXPECT_PRED_FORMAT2Test, FunctorOnBuiltInTypeFailure) {
787 EXPECT_NONFATAL_FAILURE({ // NOLINT
788 EXPECT_PRED_FORMAT2(PredFormatFunctor2(),
795 // Tests a failed EXPECT_PRED_FORMAT2 where the
796 // predicate-formatter is a functor on a user-defined type (Bool).
797 TEST_F(EXPECT_PRED_FORMAT2Test, FunctorOnUserTypeFailure) {
798 EXPECT_NONFATAL_FAILURE({ // NOLINT
799 EXPECT_PRED_FORMAT2(PredFormatFunctor2(),
806 // Tests a successful ASSERT_PRED_FORMAT2 where the
807 // predicate-formatter is a function on a built-in type (int).
808 TEST_F(ASSERT_PRED_FORMAT2Test, FunctionOnBuiltInTypeSuccess) {
809 ASSERT_PRED_FORMAT2(PredFormatFunction2,
815 // Tests a successful ASSERT_PRED_FORMAT2 where the
816 // predicate-formatter is a function on a user-defined type (Bool).
817 TEST_F(ASSERT_PRED_FORMAT2Test, FunctionOnUserTypeSuccess) {
818 ASSERT_PRED_FORMAT2(PredFormatFunction2,
824 // Tests a successful ASSERT_PRED_FORMAT2 where the
825 // predicate-formatter is a functor on a built-in type (int).
826 TEST_F(ASSERT_PRED_FORMAT2Test, FunctorOnBuiltInTypeSuccess) {
827 ASSERT_PRED_FORMAT2(PredFormatFunctor2(),
833 // Tests a successful ASSERT_PRED_FORMAT2 where the
834 // predicate-formatter is a functor on a user-defined type (Bool).
835 TEST_F(ASSERT_PRED_FORMAT2Test, FunctorOnUserTypeSuccess) {
836 ASSERT_PRED_FORMAT2(PredFormatFunctor2(),
842 // Tests a failed ASSERT_PRED_FORMAT2 where the
843 // predicate-formatter is a function on a built-in type (int).
844 TEST_F(ASSERT_PRED_FORMAT2Test, FunctionOnBuiltInTypeFailure) {
845 expected_to_finish_ = false;
846 EXPECT_FATAL_FAILURE({ // NOLINT
847 ASSERT_PRED_FORMAT2(PredFormatFunction2,
854 // Tests a failed ASSERT_PRED_FORMAT2 where the
855 // predicate-formatter is a function on a user-defined type (Bool).
856 TEST_F(ASSERT_PRED_FORMAT2Test, FunctionOnUserTypeFailure) {
857 expected_to_finish_ = false;
858 EXPECT_FATAL_FAILURE({ // NOLINT
859 ASSERT_PRED_FORMAT2(PredFormatFunction2,
866 // Tests a failed ASSERT_PRED_FORMAT2 where the
867 // predicate-formatter is a functor on a built-in type (int).
868 TEST_F(ASSERT_PRED_FORMAT2Test, FunctorOnBuiltInTypeFailure) {
869 expected_to_finish_ = false;
870 EXPECT_FATAL_FAILURE({ // NOLINT
871 ASSERT_PRED_FORMAT2(PredFormatFunctor2(),
878 // Tests a failed ASSERT_PRED_FORMAT2 where the
879 // predicate-formatter is a functor on a user-defined type (Bool).
880 TEST_F(ASSERT_PRED_FORMAT2Test, FunctorOnUserTypeFailure) {
881 expected_to_finish_ = false;
882 EXPECT_FATAL_FAILURE({ // NOLINT
883 ASSERT_PRED_FORMAT2(PredFormatFunctor2(),
889 // Sample functions/functors for testing ternary predicate assertions.
891 // A ternary predicate function.
892 template <typename T1, typename T2, typename T3>
893 bool PredFunction3(T1 v1, T2 v2, T3 v3) {
894 return v1 + v2 + v3 > 0;
897 // The following two functions are needed to circumvent a bug in
898 // gcc 2.95.3, which sometimes has problem with the above template
900 bool PredFunction3Int(int v1, int v2, int v3) {
901 return v1 + v2 + v3 > 0;
903 bool PredFunction3Bool(Bool v1, Bool v2, Bool v3) {
904 return v1 + v2 + v3 > 0;
907 // A ternary predicate functor.
908 struct PredFunctor3 {
909 template <typename T1, typename T2, typename T3>
910 bool operator()(const T1& v1,
913 return v1 + v2 + v3 > 0;
917 // A ternary predicate-formatter function.
918 template <typename T1, typename T2, typename T3>
919 testing::AssertionResult PredFormatFunction3(const char* e1,
925 if (PredFunction3(v1, v2, v3))
926 return testing::AssertionSuccess();
928 return testing::AssertionFailure()
929 << e1 << " + " << e2 << " + " << e3
930 << " is expected to be positive, but evaluates to "
931 << v1 + v2 + v3 << ".";
934 // A ternary predicate-formatter functor.
935 struct PredFormatFunctor3 {
936 template <typename T1, typename T2, typename T3>
937 testing::AssertionResult operator()(const char* e1,
942 const T3& v3) const {
943 return PredFormatFunction3(e1, e2, e3, v1, v2, v3);
947 // Tests for {EXPECT|ASSERT}_PRED_FORMAT3.
949 class Predicate3Test : public testing::Test {
951 virtual void SetUp() {
952 expected_to_finish_ = true;
957 virtual void TearDown() {
958 // Verifies that each of the predicate's arguments was evaluated
961 "The predicate assertion didn't evaluate argument 2 "
964 "The predicate assertion didn't evaluate argument 3 "
967 "The predicate assertion didn't evaluate argument 4 "
970 // Verifies that the control flow in the test function is expected.
971 if (expected_to_finish_ && !finished_) {
972 FAIL() << "The predicate assertion unexpactedly aborted the test.";
973 } else if (!expected_to_finish_ && finished_) {
974 FAIL() << "The failed predicate assertion didn't abort the test "
979 // true iff the test function is expected to run to finish.
980 static bool expected_to_finish_;
982 // true iff the test function did run to finish.
983 static bool finished_;
990 bool Predicate3Test::expected_to_finish_;
991 bool Predicate3Test::finished_;
992 int Predicate3Test::n1_;
993 int Predicate3Test::n2_;
994 int Predicate3Test::n3_;
996 typedef Predicate3Test EXPECT_PRED_FORMAT3Test;
997 typedef Predicate3Test ASSERT_PRED_FORMAT3Test;
998 typedef Predicate3Test EXPECT_PRED3Test;
999 typedef Predicate3Test ASSERT_PRED3Test;
1001 // Tests a successful EXPECT_PRED3 where the
1002 // predicate-formatter is a function on a built-in type (int).
1003 TEST_F(EXPECT_PRED3Test, FunctionOnBuiltInTypeSuccess) {
1004 EXPECT_PRED3(PredFunction3Int,
1011 // Tests a successful EXPECT_PRED3 where the
1012 // predicate-formatter is a function on a user-defined type (Bool).
1013 TEST_F(EXPECT_PRED3Test, FunctionOnUserTypeSuccess) {
1014 EXPECT_PRED3(PredFunction3Bool,
1021 // Tests a successful EXPECT_PRED3 where the
1022 // predicate-formatter is a functor on a built-in type (int).
1023 TEST_F(EXPECT_PRED3Test, FunctorOnBuiltInTypeSuccess) {
1024 EXPECT_PRED3(PredFunctor3(),
1031 // Tests a successful EXPECT_PRED3 where the
1032 // predicate-formatter is a functor on a user-defined type (Bool).
1033 TEST_F(EXPECT_PRED3Test, FunctorOnUserTypeSuccess) {
1034 EXPECT_PRED3(PredFunctor3(),
1041 // Tests a failed EXPECT_PRED3 where the
1042 // predicate-formatter is a function on a built-in type (int).
1043 TEST_F(EXPECT_PRED3Test, FunctionOnBuiltInTypeFailure) {
1044 EXPECT_NONFATAL_FAILURE({ // NOLINT
1045 EXPECT_PRED3(PredFunction3Int,
1053 // Tests a failed EXPECT_PRED3 where the
1054 // predicate-formatter is a function on a user-defined type (Bool).
1055 TEST_F(EXPECT_PRED3Test, FunctionOnUserTypeFailure) {
1056 EXPECT_NONFATAL_FAILURE({ // NOLINT
1057 EXPECT_PRED3(PredFunction3Bool,
1065 // Tests a failed EXPECT_PRED3 where the
1066 // predicate-formatter is a functor on a built-in type (int).
1067 TEST_F(EXPECT_PRED3Test, FunctorOnBuiltInTypeFailure) {
1068 EXPECT_NONFATAL_FAILURE({ // NOLINT
1069 EXPECT_PRED3(PredFunctor3(),
1077 // Tests a failed EXPECT_PRED3 where the
1078 // predicate-formatter is a functor on a user-defined type (Bool).
1079 TEST_F(EXPECT_PRED3Test, FunctorOnUserTypeFailure) {
1080 EXPECT_NONFATAL_FAILURE({ // NOLINT
1081 EXPECT_PRED3(PredFunctor3(),
1089 // Tests a successful ASSERT_PRED3 where the
1090 // predicate-formatter is a function on a built-in type (int).
1091 TEST_F(ASSERT_PRED3Test, FunctionOnBuiltInTypeSuccess) {
1092 ASSERT_PRED3(PredFunction3Int,
1099 // Tests a successful ASSERT_PRED3 where the
1100 // predicate-formatter is a function on a user-defined type (Bool).
1101 TEST_F(ASSERT_PRED3Test, FunctionOnUserTypeSuccess) {
1102 ASSERT_PRED3(PredFunction3Bool,
1109 // Tests a successful ASSERT_PRED3 where the
1110 // predicate-formatter is a functor on a built-in type (int).
1111 TEST_F(ASSERT_PRED3Test, FunctorOnBuiltInTypeSuccess) {
1112 ASSERT_PRED3(PredFunctor3(),
1119 // Tests a successful ASSERT_PRED3 where the
1120 // predicate-formatter is a functor on a user-defined type (Bool).
1121 TEST_F(ASSERT_PRED3Test, FunctorOnUserTypeSuccess) {
1122 ASSERT_PRED3(PredFunctor3(),
1129 // Tests a failed ASSERT_PRED3 where the
1130 // predicate-formatter is a function on a built-in type (int).
1131 TEST_F(ASSERT_PRED3Test, FunctionOnBuiltInTypeFailure) {
1132 expected_to_finish_ = false;
1133 EXPECT_FATAL_FAILURE({ // NOLINT
1134 ASSERT_PRED3(PredFunction3Int,
1142 // Tests a failed ASSERT_PRED3 where the
1143 // predicate-formatter is a function on a user-defined type (Bool).
1144 TEST_F(ASSERT_PRED3Test, FunctionOnUserTypeFailure) {
1145 expected_to_finish_ = false;
1146 EXPECT_FATAL_FAILURE({ // NOLINT
1147 ASSERT_PRED3(PredFunction3Bool,
1155 // Tests a failed ASSERT_PRED3 where the
1156 // predicate-formatter is a functor on a built-in type (int).
1157 TEST_F(ASSERT_PRED3Test, FunctorOnBuiltInTypeFailure) {
1158 expected_to_finish_ = false;
1159 EXPECT_FATAL_FAILURE({ // NOLINT
1160 ASSERT_PRED3(PredFunctor3(),
1168 // Tests a failed ASSERT_PRED3 where the
1169 // predicate-formatter is a functor on a user-defined type (Bool).
1170 TEST_F(ASSERT_PRED3Test, FunctorOnUserTypeFailure) {
1171 expected_to_finish_ = false;
1172 EXPECT_FATAL_FAILURE({ // NOLINT
1173 ASSERT_PRED3(PredFunctor3(),
1181 // Tests a successful EXPECT_PRED_FORMAT3 where the
1182 // predicate-formatter is a function on a built-in type (int).
1183 TEST_F(EXPECT_PRED_FORMAT3Test, FunctionOnBuiltInTypeSuccess) {
1184 EXPECT_PRED_FORMAT3(PredFormatFunction3,
1191 // Tests a successful EXPECT_PRED_FORMAT3 where the
1192 // predicate-formatter is a function on a user-defined type (Bool).
1193 TEST_F(EXPECT_PRED_FORMAT3Test, FunctionOnUserTypeSuccess) {
1194 EXPECT_PRED_FORMAT3(PredFormatFunction3,
1201 // Tests a successful EXPECT_PRED_FORMAT3 where the
1202 // predicate-formatter is a functor on a built-in type (int).
1203 TEST_F(EXPECT_PRED_FORMAT3Test, FunctorOnBuiltInTypeSuccess) {
1204 EXPECT_PRED_FORMAT3(PredFormatFunctor3(),
1211 // Tests a successful EXPECT_PRED_FORMAT3 where the
1212 // predicate-formatter is a functor on a user-defined type (Bool).
1213 TEST_F(EXPECT_PRED_FORMAT3Test, FunctorOnUserTypeSuccess) {
1214 EXPECT_PRED_FORMAT3(PredFormatFunctor3(),
1221 // Tests a failed EXPECT_PRED_FORMAT3 where the
1222 // predicate-formatter is a function on a built-in type (int).
1223 TEST_F(EXPECT_PRED_FORMAT3Test, FunctionOnBuiltInTypeFailure) {
1224 EXPECT_NONFATAL_FAILURE({ // NOLINT
1225 EXPECT_PRED_FORMAT3(PredFormatFunction3,
1233 // Tests a failed EXPECT_PRED_FORMAT3 where the
1234 // predicate-formatter is a function on a user-defined type (Bool).
1235 TEST_F(EXPECT_PRED_FORMAT3Test, FunctionOnUserTypeFailure) {
1236 EXPECT_NONFATAL_FAILURE({ // NOLINT
1237 EXPECT_PRED_FORMAT3(PredFormatFunction3,
1245 // Tests a failed EXPECT_PRED_FORMAT3 where the
1246 // predicate-formatter is a functor on a built-in type (int).
1247 TEST_F(EXPECT_PRED_FORMAT3Test, FunctorOnBuiltInTypeFailure) {
1248 EXPECT_NONFATAL_FAILURE({ // NOLINT
1249 EXPECT_PRED_FORMAT3(PredFormatFunctor3(),
1257 // Tests a failed EXPECT_PRED_FORMAT3 where the
1258 // predicate-formatter is a functor on a user-defined type (Bool).
1259 TEST_F(EXPECT_PRED_FORMAT3Test, FunctorOnUserTypeFailure) {
1260 EXPECT_NONFATAL_FAILURE({ // NOLINT
1261 EXPECT_PRED_FORMAT3(PredFormatFunctor3(),
1269 // Tests a successful ASSERT_PRED_FORMAT3 where the
1270 // predicate-formatter is a function on a built-in type (int).
1271 TEST_F(ASSERT_PRED_FORMAT3Test, FunctionOnBuiltInTypeSuccess) {
1272 ASSERT_PRED_FORMAT3(PredFormatFunction3,
1279 // Tests a successful ASSERT_PRED_FORMAT3 where the
1280 // predicate-formatter is a function on a user-defined type (Bool).
1281 TEST_F(ASSERT_PRED_FORMAT3Test, FunctionOnUserTypeSuccess) {
1282 ASSERT_PRED_FORMAT3(PredFormatFunction3,
1289 // Tests a successful ASSERT_PRED_FORMAT3 where the
1290 // predicate-formatter is a functor on a built-in type (int).
1291 TEST_F(ASSERT_PRED_FORMAT3Test, FunctorOnBuiltInTypeSuccess) {
1292 ASSERT_PRED_FORMAT3(PredFormatFunctor3(),
1299 // Tests a successful ASSERT_PRED_FORMAT3 where the
1300 // predicate-formatter is a functor on a user-defined type (Bool).
1301 TEST_F(ASSERT_PRED_FORMAT3Test, FunctorOnUserTypeSuccess) {
1302 ASSERT_PRED_FORMAT3(PredFormatFunctor3(),
1309 // Tests a failed ASSERT_PRED_FORMAT3 where the
1310 // predicate-formatter is a function on a built-in type (int).
1311 TEST_F(ASSERT_PRED_FORMAT3Test, FunctionOnBuiltInTypeFailure) {
1312 expected_to_finish_ = false;
1313 EXPECT_FATAL_FAILURE({ // NOLINT
1314 ASSERT_PRED_FORMAT3(PredFormatFunction3,
1322 // Tests a failed ASSERT_PRED_FORMAT3 where the
1323 // predicate-formatter is a function on a user-defined type (Bool).
1324 TEST_F(ASSERT_PRED_FORMAT3Test, FunctionOnUserTypeFailure) {
1325 expected_to_finish_ = false;
1326 EXPECT_FATAL_FAILURE({ // NOLINT
1327 ASSERT_PRED_FORMAT3(PredFormatFunction3,
1335 // Tests a failed ASSERT_PRED_FORMAT3 where the
1336 // predicate-formatter is a functor on a built-in type (int).
1337 TEST_F(ASSERT_PRED_FORMAT3Test, FunctorOnBuiltInTypeFailure) {
1338 expected_to_finish_ = false;
1339 EXPECT_FATAL_FAILURE({ // NOLINT
1340 ASSERT_PRED_FORMAT3(PredFormatFunctor3(),
1348 // Tests a failed ASSERT_PRED_FORMAT3 where the
1349 // predicate-formatter is a functor on a user-defined type (Bool).
1350 TEST_F(ASSERT_PRED_FORMAT3Test, FunctorOnUserTypeFailure) {
1351 expected_to_finish_ = false;
1352 EXPECT_FATAL_FAILURE({ // NOLINT
1353 ASSERT_PRED_FORMAT3(PredFormatFunctor3(),
1360 // Sample functions/functors for testing 4-ary predicate assertions.
1362 // A 4-ary predicate function.
1363 template <typename T1, typename T2, typename T3, typename T4>
1364 bool PredFunction4(T1 v1, T2 v2, T3 v3, T4 v4) {
1365 return v1 + v2 + v3 + v4 > 0;
1368 // The following two functions are needed to circumvent a bug in
1369 // gcc 2.95.3, which sometimes has problem with the above template
1371 bool PredFunction4Int(int v1, int v2, int v3, int v4) {
1372 return v1 + v2 + v3 + v4 > 0;
1374 bool PredFunction4Bool(Bool v1, Bool v2, Bool v3, Bool v4) {
1375 return v1 + v2 + v3 + v4 > 0;
1378 // A 4-ary predicate functor.
1379 struct PredFunctor4 {
1380 template <typename T1, typename T2, typename T3, typename T4>
1381 bool operator()(const T1& v1,
1385 return v1 + v2 + v3 + v4 > 0;
1389 // A 4-ary predicate-formatter function.
1390 template <typename T1, typename T2, typename T3, typename T4>
1391 testing::AssertionResult PredFormatFunction4(const char* e1,
1399 if (PredFunction4(v1, v2, v3, v4))
1400 return testing::AssertionSuccess();
1402 return testing::AssertionFailure()
1403 << e1 << " + " << e2 << " + " << e3 << " + " << e4
1404 << " is expected to be positive, but evaluates to "
1405 << v1 + v2 + v3 + v4 << ".";
1408 // A 4-ary predicate-formatter functor.
1409 struct PredFormatFunctor4 {
1410 template <typename T1, typename T2, typename T3, typename T4>
1411 testing::AssertionResult operator()(const char* e1,
1418 const T4& v4) const {
1419 return PredFormatFunction4(e1, e2, e3, e4, v1, v2, v3, v4);
1423 // Tests for {EXPECT|ASSERT}_PRED_FORMAT4.
1425 class Predicate4Test : public testing::Test {
1427 virtual void SetUp() {
1428 expected_to_finish_ = true;
1430 n1_ = n2_ = n3_ = n4_ = 0;
1433 virtual void TearDown() {
1434 // Verifies that each of the predicate's arguments was evaluated
1436 EXPECT_EQ(1, n1_) <<
1437 "The predicate assertion didn't evaluate argument 2 "
1439 EXPECT_EQ(1, n2_) <<
1440 "The predicate assertion didn't evaluate argument 3 "
1442 EXPECT_EQ(1, n3_) <<
1443 "The predicate assertion didn't evaluate argument 4 "
1445 EXPECT_EQ(1, n4_) <<
1446 "The predicate assertion didn't evaluate argument 5 "
1449 // Verifies that the control flow in the test function is expected.
1450 if (expected_to_finish_ && !finished_) {
1451 FAIL() << "The predicate assertion unexpactedly aborted the test.";
1452 } else if (!expected_to_finish_ && finished_) {
1453 FAIL() << "The failed predicate assertion didn't abort the test "
1458 // true iff the test function is expected to run to finish.
1459 static bool expected_to_finish_;
1461 // true iff the test function did run to finish.
1462 static bool finished_;
1470 bool Predicate4Test::expected_to_finish_;
1471 bool Predicate4Test::finished_;
1472 int Predicate4Test::n1_;
1473 int Predicate4Test::n2_;
1474 int Predicate4Test::n3_;
1475 int Predicate4Test::n4_;
1477 typedef Predicate4Test EXPECT_PRED_FORMAT4Test;
1478 typedef Predicate4Test ASSERT_PRED_FORMAT4Test;
1479 typedef Predicate4Test EXPECT_PRED4Test;
1480 typedef Predicate4Test ASSERT_PRED4Test;
1482 // Tests a successful EXPECT_PRED4 where the
1483 // predicate-formatter is a function on a built-in type (int).
1484 TEST_F(EXPECT_PRED4Test, FunctionOnBuiltInTypeSuccess) {
1485 EXPECT_PRED4(PredFunction4Int,
1493 // Tests a successful EXPECT_PRED4 where the
1494 // predicate-formatter is a function on a user-defined type (Bool).
1495 TEST_F(EXPECT_PRED4Test, FunctionOnUserTypeSuccess) {
1496 EXPECT_PRED4(PredFunction4Bool,
1504 // Tests a successful EXPECT_PRED4 where the
1505 // predicate-formatter is a functor on a built-in type (int).
1506 TEST_F(EXPECT_PRED4Test, FunctorOnBuiltInTypeSuccess) {
1507 EXPECT_PRED4(PredFunctor4(),
1515 // Tests a successful EXPECT_PRED4 where the
1516 // predicate-formatter is a functor on a user-defined type (Bool).
1517 TEST_F(EXPECT_PRED4Test, FunctorOnUserTypeSuccess) {
1518 EXPECT_PRED4(PredFunctor4(),
1526 // Tests a failed EXPECT_PRED4 where the
1527 // predicate-formatter is a function on a built-in type (int).
1528 TEST_F(EXPECT_PRED4Test, FunctionOnBuiltInTypeFailure) {
1529 EXPECT_NONFATAL_FAILURE({ // NOLINT
1530 EXPECT_PRED4(PredFunction4Int,
1539 // Tests a failed EXPECT_PRED4 where the
1540 // predicate-formatter is a function on a user-defined type (Bool).
1541 TEST_F(EXPECT_PRED4Test, FunctionOnUserTypeFailure) {
1542 EXPECT_NONFATAL_FAILURE({ // NOLINT
1543 EXPECT_PRED4(PredFunction4Bool,
1552 // Tests a failed EXPECT_PRED4 where the
1553 // predicate-formatter is a functor on a built-in type (int).
1554 TEST_F(EXPECT_PRED4Test, FunctorOnBuiltInTypeFailure) {
1555 EXPECT_NONFATAL_FAILURE({ // NOLINT
1556 EXPECT_PRED4(PredFunctor4(),
1565 // Tests a failed EXPECT_PRED4 where the
1566 // predicate-formatter is a functor on a user-defined type (Bool).
1567 TEST_F(EXPECT_PRED4Test, FunctorOnUserTypeFailure) {
1568 EXPECT_NONFATAL_FAILURE({ // NOLINT
1569 EXPECT_PRED4(PredFunctor4(),
1578 // Tests a successful ASSERT_PRED4 where the
1579 // predicate-formatter is a function on a built-in type (int).
1580 TEST_F(ASSERT_PRED4Test, FunctionOnBuiltInTypeSuccess) {
1581 ASSERT_PRED4(PredFunction4Int,
1589 // Tests a successful ASSERT_PRED4 where the
1590 // predicate-formatter is a function on a user-defined type (Bool).
1591 TEST_F(ASSERT_PRED4Test, FunctionOnUserTypeSuccess) {
1592 ASSERT_PRED4(PredFunction4Bool,
1600 // Tests a successful ASSERT_PRED4 where the
1601 // predicate-formatter is a functor on a built-in type (int).
1602 TEST_F(ASSERT_PRED4Test, FunctorOnBuiltInTypeSuccess) {
1603 ASSERT_PRED4(PredFunctor4(),
1611 // Tests a successful ASSERT_PRED4 where the
1612 // predicate-formatter is a functor on a user-defined type (Bool).
1613 TEST_F(ASSERT_PRED4Test, FunctorOnUserTypeSuccess) {
1614 ASSERT_PRED4(PredFunctor4(),
1622 // Tests a failed ASSERT_PRED4 where the
1623 // predicate-formatter is a function on a built-in type (int).
1624 TEST_F(ASSERT_PRED4Test, FunctionOnBuiltInTypeFailure) {
1625 expected_to_finish_ = false;
1626 EXPECT_FATAL_FAILURE({ // NOLINT
1627 ASSERT_PRED4(PredFunction4Int,
1636 // Tests a failed ASSERT_PRED4 where the
1637 // predicate-formatter is a function on a user-defined type (Bool).
1638 TEST_F(ASSERT_PRED4Test, FunctionOnUserTypeFailure) {
1639 expected_to_finish_ = false;
1640 EXPECT_FATAL_FAILURE({ // NOLINT
1641 ASSERT_PRED4(PredFunction4Bool,
1650 // Tests a failed ASSERT_PRED4 where the
1651 // predicate-formatter is a functor on a built-in type (int).
1652 TEST_F(ASSERT_PRED4Test, FunctorOnBuiltInTypeFailure) {
1653 expected_to_finish_ = false;
1654 EXPECT_FATAL_FAILURE({ // NOLINT
1655 ASSERT_PRED4(PredFunctor4(),
1664 // Tests a failed ASSERT_PRED4 where the
1665 // predicate-formatter is a functor on a user-defined type (Bool).
1666 TEST_F(ASSERT_PRED4Test, FunctorOnUserTypeFailure) {
1667 expected_to_finish_ = false;
1668 EXPECT_FATAL_FAILURE({ // NOLINT
1669 ASSERT_PRED4(PredFunctor4(),
1678 // Tests a successful EXPECT_PRED_FORMAT4 where the
1679 // predicate-formatter is a function on a built-in type (int).
1680 TEST_F(EXPECT_PRED_FORMAT4Test, FunctionOnBuiltInTypeSuccess) {
1681 EXPECT_PRED_FORMAT4(PredFormatFunction4,
1689 // Tests a successful EXPECT_PRED_FORMAT4 where the
1690 // predicate-formatter is a function on a user-defined type (Bool).
1691 TEST_F(EXPECT_PRED_FORMAT4Test, FunctionOnUserTypeSuccess) {
1692 EXPECT_PRED_FORMAT4(PredFormatFunction4,
1700 // Tests a successful EXPECT_PRED_FORMAT4 where the
1701 // predicate-formatter is a functor on a built-in type (int).
1702 TEST_F(EXPECT_PRED_FORMAT4Test, FunctorOnBuiltInTypeSuccess) {
1703 EXPECT_PRED_FORMAT4(PredFormatFunctor4(),
1711 // Tests a successful EXPECT_PRED_FORMAT4 where the
1712 // predicate-formatter is a functor on a user-defined type (Bool).
1713 TEST_F(EXPECT_PRED_FORMAT4Test, FunctorOnUserTypeSuccess) {
1714 EXPECT_PRED_FORMAT4(PredFormatFunctor4(),
1722 // Tests a failed EXPECT_PRED_FORMAT4 where the
1723 // predicate-formatter is a function on a built-in type (int).
1724 TEST_F(EXPECT_PRED_FORMAT4Test, FunctionOnBuiltInTypeFailure) {
1725 EXPECT_NONFATAL_FAILURE({ // NOLINT
1726 EXPECT_PRED_FORMAT4(PredFormatFunction4,
1735 // Tests a failed EXPECT_PRED_FORMAT4 where the
1736 // predicate-formatter is a function on a user-defined type (Bool).
1737 TEST_F(EXPECT_PRED_FORMAT4Test, FunctionOnUserTypeFailure) {
1738 EXPECT_NONFATAL_FAILURE({ // NOLINT
1739 EXPECT_PRED_FORMAT4(PredFormatFunction4,
1748 // Tests a failed EXPECT_PRED_FORMAT4 where the
1749 // predicate-formatter is a functor on a built-in type (int).
1750 TEST_F(EXPECT_PRED_FORMAT4Test, FunctorOnBuiltInTypeFailure) {
1751 EXPECT_NONFATAL_FAILURE({ // NOLINT
1752 EXPECT_PRED_FORMAT4(PredFormatFunctor4(),
1761 // Tests a failed EXPECT_PRED_FORMAT4 where the
1762 // predicate-formatter is a functor on a user-defined type (Bool).
1763 TEST_F(EXPECT_PRED_FORMAT4Test, FunctorOnUserTypeFailure) {
1764 EXPECT_NONFATAL_FAILURE({ // NOLINT
1765 EXPECT_PRED_FORMAT4(PredFormatFunctor4(),
1774 // Tests a successful ASSERT_PRED_FORMAT4 where the
1775 // predicate-formatter is a function on a built-in type (int).
1776 TEST_F(ASSERT_PRED_FORMAT4Test, FunctionOnBuiltInTypeSuccess) {
1777 ASSERT_PRED_FORMAT4(PredFormatFunction4,
1785 // Tests a successful ASSERT_PRED_FORMAT4 where the
1786 // predicate-formatter is a function on a user-defined type (Bool).
1787 TEST_F(ASSERT_PRED_FORMAT4Test, FunctionOnUserTypeSuccess) {
1788 ASSERT_PRED_FORMAT4(PredFormatFunction4,
1796 // Tests a successful ASSERT_PRED_FORMAT4 where the
1797 // predicate-formatter is a functor on a built-in type (int).
1798 TEST_F(ASSERT_PRED_FORMAT4Test, FunctorOnBuiltInTypeSuccess) {
1799 ASSERT_PRED_FORMAT4(PredFormatFunctor4(),
1807 // Tests a successful ASSERT_PRED_FORMAT4 where the
1808 // predicate-formatter is a functor on a user-defined type (Bool).
1809 TEST_F(ASSERT_PRED_FORMAT4Test, FunctorOnUserTypeSuccess) {
1810 ASSERT_PRED_FORMAT4(PredFormatFunctor4(),
1818 // Tests a failed ASSERT_PRED_FORMAT4 where the
1819 // predicate-formatter is a function on a built-in type (int).
1820 TEST_F(ASSERT_PRED_FORMAT4Test, FunctionOnBuiltInTypeFailure) {
1821 expected_to_finish_ = false;
1822 EXPECT_FATAL_FAILURE({ // NOLINT
1823 ASSERT_PRED_FORMAT4(PredFormatFunction4,
1832 // Tests a failed ASSERT_PRED_FORMAT4 where the
1833 // predicate-formatter is a function on a user-defined type (Bool).
1834 TEST_F(ASSERT_PRED_FORMAT4Test, FunctionOnUserTypeFailure) {
1835 expected_to_finish_ = false;
1836 EXPECT_FATAL_FAILURE({ // NOLINT
1837 ASSERT_PRED_FORMAT4(PredFormatFunction4,
1846 // Tests a failed ASSERT_PRED_FORMAT4 where the
1847 // predicate-formatter is a functor on a built-in type (int).
1848 TEST_F(ASSERT_PRED_FORMAT4Test, FunctorOnBuiltInTypeFailure) {
1849 expected_to_finish_ = false;
1850 EXPECT_FATAL_FAILURE({ // NOLINT
1851 ASSERT_PRED_FORMAT4(PredFormatFunctor4(),
1860 // Tests a failed ASSERT_PRED_FORMAT4 where the
1861 // predicate-formatter is a functor on a user-defined type (Bool).
1862 TEST_F(ASSERT_PRED_FORMAT4Test, FunctorOnUserTypeFailure) {
1863 expected_to_finish_ = false;
1864 EXPECT_FATAL_FAILURE({ // NOLINT
1865 ASSERT_PRED_FORMAT4(PredFormatFunctor4(),
1873 // Sample functions/functors for testing 5-ary predicate assertions.
1875 // A 5-ary predicate function.
1876 template <typename T1, typename T2, typename T3, typename T4, typename T5>
1877 bool PredFunction5(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5) {
1878 return v1 + v2 + v3 + v4 + v5 > 0;
1881 // The following two functions are needed to circumvent a bug in
1882 // gcc 2.95.3, which sometimes has problem with the above template
1884 bool PredFunction5Int(int v1, int v2, int v3, int v4, int v5) {
1885 return v1 + v2 + v3 + v4 + v5 > 0;
1887 bool PredFunction5Bool(Bool v1, Bool v2, Bool v3, Bool v4, Bool v5) {
1888 return v1 + v2 + v3 + v4 + v5 > 0;
1891 // A 5-ary predicate functor.
1892 struct PredFunctor5 {
1893 template <typename T1, typename T2, typename T3, typename T4, typename T5>
1894 bool operator()(const T1& v1,
1899 return v1 + v2 + v3 + v4 + v5 > 0;
1903 // A 5-ary predicate-formatter function.
1904 template <typename T1, typename T2, typename T3, typename T4, typename T5>
1905 testing::AssertionResult PredFormatFunction5(const char* e1,
1915 if (PredFunction5(v1, v2, v3, v4, v5))
1916 return testing::AssertionSuccess();
1918 return testing::AssertionFailure()
1919 << e1 << " + " << e2 << " + " << e3 << " + " << e4 << " + " << e5
1920 << " is expected to be positive, but evaluates to "
1921 << v1 + v2 + v3 + v4 + v5 << ".";
1924 // A 5-ary predicate-formatter functor.
1925 struct PredFormatFunctor5 {
1926 template <typename T1, typename T2, typename T3, typename T4, typename T5>
1927 testing::AssertionResult operator()(const char* e1,
1936 const T5& v5) const {
1937 return PredFormatFunction5(e1, e2, e3, e4, e5, v1, v2, v3, v4, v5);
1941 // Tests for {EXPECT|ASSERT}_PRED_FORMAT5.
1943 class Predicate5Test : public testing::Test {
1945 virtual void SetUp() {
1946 expected_to_finish_ = true;
1948 n1_ = n2_ = n3_ = n4_ = n5_ = 0;
1951 virtual void TearDown() {
1952 // Verifies that each of the predicate's arguments was evaluated
1954 EXPECT_EQ(1, n1_) <<
1955 "The predicate assertion didn't evaluate argument 2 "
1957 EXPECT_EQ(1, n2_) <<
1958 "The predicate assertion didn't evaluate argument 3 "
1960 EXPECT_EQ(1, n3_) <<
1961 "The predicate assertion didn't evaluate argument 4 "
1963 EXPECT_EQ(1, n4_) <<
1964 "The predicate assertion didn't evaluate argument 5 "
1966 EXPECT_EQ(1, n5_) <<
1967 "The predicate assertion didn't evaluate argument 6 "
1970 // Verifies that the control flow in the test function is expected.
1971 if (expected_to_finish_ && !finished_) {
1972 FAIL() << "The predicate assertion unexpactedly aborted the test.";
1973 } else if (!expected_to_finish_ && finished_) {
1974 FAIL() << "The failed predicate assertion didn't abort the test "
1979 // true iff the test function is expected to run to finish.
1980 static bool expected_to_finish_;
1982 // true iff the test function did run to finish.
1983 static bool finished_;
1992 bool Predicate5Test::expected_to_finish_;
1993 bool Predicate5Test::finished_;
1994 int Predicate5Test::n1_;
1995 int Predicate5Test::n2_;
1996 int Predicate5Test::n3_;
1997 int Predicate5Test::n4_;
1998 int Predicate5Test::n5_;
2000 typedef Predicate5Test EXPECT_PRED_FORMAT5Test;
2001 typedef Predicate5Test ASSERT_PRED_FORMAT5Test;
2002 typedef Predicate5Test EXPECT_PRED5Test;
2003 typedef Predicate5Test ASSERT_PRED5Test;
2005 // Tests a successful EXPECT_PRED5 where the
2006 // predicate-formatter is a function on a built-in type (int).
2007 TEST_F(EXPECT_PRED5Test, FunctionOnBuiltInTypeSuccess) {
2008 EXPECT_PRED5(PredFunction5Int,
2017 // Tests a successful EXPECT_PRED5 where the
2018 // predicate-formatter is a function on a user-defined type (Bool).
2019 TEST_F(EXPECT_PRED5Test, FunctionOnUserTypeSuccess) {
2020 EXPECT_PRED5(PredFunction5Bool,
2029 // Tests a successful EXPECT_PRED5 where the
2030 // predicate-formatter is a functor on a built-in type (int).
2031 TEST_F(EXPECT_PRED5Test, FunctorOnBuiltInTypeSuccess) {
2032 EXPECT_PRED5(PredFunctor5(),
2041 // Tests a successful EXPECT_PRED5 where the
2042 // predicate-formatter is a functor on a user-defined type (Bool).
2043 TEST_F(EXPECT_PRED5Test, FunctorOnUserTypeSuccess) {
2044 EXPECT_PRED5(PredFunctor5(),
2053 // Tests a failed EXPECT_PRED5 where the
2054 // predicate-formatter is a function on a built-in type (int).
2055 TEST_F(EXPECT_PRED5Test, FunctionOnBuiltInTypeFailure) {
2056 EXPECT_NONFATAL_FAILURE({ // NOLINT
2057 EXPECT_PRED5(PredFunction5Int,
2067 // Tests a failed EXPECT_PRED5 where the
2068 // predicate-formatter is a function on a user-defined type (Bool).
2069 TEST_F(EXPECT_PRED5Test, FunctionOnUserTypeFailure) {
2070 EXPECT_NONFATAL_FAILURE({ // NOLINT
2071 EXPECT_PRED5(PredFunction5Bool,
2081 // Tests a failed EXPECT_PRED5 where the
2082 // predicate-formatter is a functor on a built-in type (int).
2083 TEST_F(EXPECT_PRED5Test, FunctorOnBuiltInTypeFailure) {
2084 EXPECT_NONFATAL_FAILURE({ // NOLINT
2085 EXPECT_PRED5(PredFunctor5(),
2095 // Tests a failed EXPECT_PRED5 where the
2096 // predicate-formatter is a functor on a user-defined type (Bool).
2097 TEST_F(EXPECT_PRED5Test, FunctorOnUserTypeFailure) {
2098 EXPECT_NONFATAL_FAILURE({ // NOLINT
2099 EXPECT_PRED5(PredFunctor5(),
2109 // Tests a successful ASSERT_PRED5 where the
2110 // predicate-formatter is a function on a built-in type (int).
2111 TEST_F(ASSERT_PRED5Test, FunctionOnBuiltInTypeSuccess) {
2112 ASSERT_PRED5(PredFunction5Int,
2121 // Tests a successful ASSERT_PRED5 where the
2122 // predicate-formatter is a function on a user-defined type (Bool).
2123 TEST_F(ASSERT_PRED5Test, FunctionOnUserTypeSuccess) {
2124 ASSERT_PRED5(PredFunction5Bool,
2133 // Tests a successful ASSERT_PRED5 where the
2134 // predicate-formatter is a functor on a built-in type (int).
2135 TEST_F(ASSERT_PRED5Test, FunctorOnBuiltInTypeSuccess) {
2136 ASSERT_PRED5(PredFunctor5(),
2145 // Tests a successful ASSERT_PRED5 where the
2146 // predicate-formatter is a functor on a user-defined type (Bool).
2147 TEST_F(ASSERT_PRED5Test, FunctorOnUserTypeSuccess) {
2148 ASSERT_PRED5(PredFunctor5(),
2157 // Tests a failed ASSERT_PRED5 where the
2158 // predicate-formatter is a function on a built-in type (int).
2159 TEST_F(ASSERT_PRED5Test, FunctionOnBuiltInTypeFailure) {
2160 expected_to_finish_ = false;
2161 EXPECT_FATAL_FAILURE({ // NOLINT
2162 ASSERT_PRED5(PredFunction5Int,
2172 // Tests a failed ASSERT_PRED5 where the
2173 // predicate-formatter is a function on a user-defined type (Bool).
2174 TEST_F(ASSERT_PRED5Test, FunctionOnUserTypeFailure) {
2175 expected_to_finish_ = false;
2176 EXPECT_FATAL_FAILURE({ // NOLINT
2177 ASSERT_PRED5(PredFunction5Bool,
2187 // Tests a failed ASSERT_PRED5 where the
2188 // predicate-formatter is a functor on a built-in type (int).
2189 TEST_F(ASSERT_PRED5Test, FunctorOnBuiltInTypeFailure) {
2190 expected_to_finish_ = false;
2191 EXPECT_FATAL_FAILURE({ // NOLINT
2192 ASSERT_PRED5(PredFunctor5(),
2202 // Tests a failed ASSERT_PRED5 where the
2203 // predicate-formatter is a functor on a user-defined type (Bool).
2204 TEST_F(ASSERT_PRED5Test, FunctorOnUserTypeFailure) {
2205 expected_to_finish_ = false;
2206 EXPECT_FATAL_FAILURE({ // NOLINT
2207 ASSERT_PRED5(PredFunctor5(),
2217 // Tests a successful EXPECT_PRED_FORMAT5 where the
2218 // predicate-formatter is a function on a built-in type (int).
2219 TEST_F(EXPECT_PRED_FORMAT5Test, FunctionOnBuiltInTypeSuccess) {
2220 EXPECT_PRED_FORMAT5(PredFormatFunction5,
2229 // Tests a successful EXPECT_PRED_FORMAT5 where the
2230 // predicate-formatter is a function on a user-defined type (Bool).
2231 TEST_F(EXPECT_PRED_FORMAT5Test, FunctionOnUserTypeSuccess) {
2232 EXPECT_PRED_FORMAT5(PredFormatFunction5,
2241 // Tests a successful EXPECT_PRED_FORMAT5 where the
2242 // predicate-formatter is a functor on a built-in type (int).
2243 TEST_F(EXPECT_PRED_FORMAT5Test, FunctorOnBuiltInTypeSuccess) {
2244 EXPECT_PRED_FORMAT5(PredFormatFunctor5(),
2253 // Tests a successful EXPECT_PRED_FORMAT5 where the
2254 // predicate-formatter is a functor on a user-defined type (Bool).
2255 TEST_F(EXPECT_PRED_FORMAT5Test, FunctorOnUserTypeSuccess) {
2256 EXPECT_PRED_FORMAT5(PredFormatFunctor5(),
2265 // Tests a failed EXPECT_PRED_FORMAT5 where the
2266 // predicate-formatter is a function on a built-in type (int).
2267 TEST_F(EXPECT_PRED_FORMAT5Test, FunctionOnBuiltInTypeFailure) {
2268 EXPECT_NONFATAL_FAILURE({ // NOLINT
2269 EXPECT_PRED_FORMAT5(PredFormatFunction5,
2279 // Tests a failed EXPECT_PRED_FORMAT5 where the
2280 // predicate-formatter is a function on a user-defined type (Bool).
2281 TEST_F(EXPECT_PRED_FORMAT5Test, FunctionOnUserTypeFailure) {
2282 EXPECT_NONFATAL_FAILURE({ // NOLINT
2283 EXPECT_PRED_FORMAT5(PredFormatFunction5,
2293 // Tests a failed EXPECT_PRED_FORMAT5 where the
2294 // predicate-formatter is a functor on a built-in type (int).
2295 TEST_F(EXPECT_PRED_FORMAT5Test, FunctorOnBuiltInTypeFailure) {
2296 EXPECT_NONFATAL_FAILURE({ // NOLINT
2297 EXPECT_PRED_FORMAT5(PredFormatFunctor5(),
2307 // Tests a failed EXPECT_PRED_FORMAT5 where the
2308 // predicate-formatter is a functor on a user-defined type (Bool).
2309 TEST_F(EXPECT_PRED_FORMAT5Test, FunctorOnUserTypeFailure) {
2310 EXPECT_NONFATAL_FAILURE({ // NOLINT
2311 EXPECT_PRED_FORMAT5(PredFormatFunctor5(),
2321 // Tests a successful ASSERT_PRED_FORMAT5 where the
2322 // predicate-formatter is a function on a built-in type (int).
2323 TEST_F(ASSERT_PRED_FORMAT5Test, FunctionOnBuiltInTypeSuccess) {
2324 ASSERT_PRED_FORMAT5(PredFormatFunction5,
2333 // Tests a successful ASSERT_PRED_FORMAT5 where the
2334 // predicate-formatter is a function on a user-defined type (Bool).
2335 TEST_F(ASSERT_PRED_FORMAT5Test, FunctionOnUserTypeSuccess) {
2336 ASSERT_PRED_FORMAT5(PredFormatFunction5,
2345 // Tests a successful ASSERT_PRED_FORMAT5 where the
2346 // predicate-formatter is a functor on a built-in type (int).
2347 TEST_F(ASSERT_PRED_FORMAT5Test, FunctorOnBuiltInTypeSuccess) {
2348 ASSERT_PRED_FORMAT5(PredFormatFunctor5(),
2357 // Tests a successful ASSERT_PRED_FORMAT5 where the
2358 // predicate-formatter is a functor on a user-defined type (Bool).
2359 TEST_F(ASSERT_PRED_FORMAT5Test, FunctorOnUserTypeSuccess) {
2360 ASSERT_PRED_FORMAT5(PredFormatFunctor5(),
2369 // Tests a failed ASSERT_PRED_FORMAT5 where the
2370 // predicate-formatter is a function on a built-in type (int).
2371 TEST_F(ASSERT_PRED_FORMAT5Test, FunctionOnBuiltInTypeFailure) {
2372 expected_to_finish_ = false;
2373 EXPECT_FATAL_FAILURE({ // NOLINT
2374 ASSERT_PRED_FORMAT5(PredFormatFunction5,
2384 // Tests a failed ASSERT_PRED_FORMAT5 where the
2385 // predicate-formatter is a function on a user-defined type (Bool).
2386 TEST_F(ASSERT_PRED_FORMAT5Test, FunctionOnUserTypeFailure) {
2387 expected_to_finish_ = false;
2388 EXPECT_FATAL_FAILURE({ // NOLINT
2389 ASSERT_PRED_FORMAT5(PredFormatFunction5,
2399 // Tests a failed ASSERT_PRED_FORMAT5 where the
2400 // predicate-formatter is a functor on a built-in type (int).
2401 TEST_F(ASSERT_PRED_FORMAT5Test, FunctorOnBuiltInTypeFailure) {
2402 expected_to_finish_ = false;
2403 EXPECT_FATAL_FAILURE({ // NOLINT
2404 ASSERT_PRED_FORMAT5(PredFormatFunctor5(),
2414 // Tests a failed ASSERT_PRED_FORMAT5 where the
2415 // predicate-formatter is a functor on a user-defined type (Bool).
2416 TEST_F(ASSERT_PRED_FORMAT5Test, FunctorOnUserTypeFailure) {
2417 expected_to_finish_ = false;
2418 EXPECT_FATAL_FAILURE({ // NOLINT
2419 ASSERT_PRED_FORMAT5(PredFormatFunctor5(),