media/webrtc/trunk/testing/gtest/test/gtest_pred_impl_unittest.cc

Wed, 31 Dec 2014 07:53:36 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:53:36 +0100
branch
TOR_BUG_3246
changeset 5
4ab42b5ab56c
permissions
-rw-r--r--

Correct small whitespace inconsistency, lost while renaming variables.

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

mercurial