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