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