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