PageRenderTime 118ms CodeModel.GetById 12ms app.highlight 97ms RepoModel.GetById 1ms app.codeStats 1ms

/thirdparty/breakpad/third_party/protobuf/protobuf/gtest/test/gtest_pred_impl_unittest.cc

http://github.com/tomahawk-player/tomahawk
C++ | 2050 lines | 1449 code | 219 blank | 382 comment | 32 complexity | ce191bd144218e3af8586eedb56155e3 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   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

Large files files are truncated, but you can click here to view the full file