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