Chromium Code Reviews| Index: net/test/gtest_util.h |
| diff --git a/net/test/gtest_util.h b/net/test/gtest_util.h |
| index f8b4cf573c287648c6e8be25c4e8ba05b304718b..e41f738c061ac5511c960cb3d1dc743e52af361f 100644 |
| --- a/net/test/gtest_util.h |
| +++ b/net/test/gtest_util.h |
| @@ -38,24 +38,24 @@ MATCHER(IsOk, |
| // Internal implementation for the EXPECT_DFATAL and ASSERT_DFATAL |
| // macros. Do not use this directly. |
| -#define GTEST_DFATAL_(statement, matcher, fail) \ |
| - GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ |
| - if (true) { \ |
| - ::base::test::MockLog gtest_log; \ |
| - ::net::test::ScopedDisableExitOnDFatal gtest_disable_exit; \ |
| - using ::testing::_; \ |
| - EXPECT_CALL(gtest_log, Log(_, _, _, _, _)) \ |
| - .WillRepeatedly(::testing::Return(false)); \ |
| - EXPECT_CALL(gtest_log, Log(logging::LOG_DFATAL, _, _, _, matcher)) \ |
| - .Times(::testing::AtLeast(1)) \ |
| - .WillOnce(::testing::Return(false)); \ |
| - gtest_log.StartCapturingLogs(); \ |
| - { statement; } \ |
| - gtest_log.StopCapturingLogs(); \ |
| - if (!testing::Mock::VerifyAndClear(>est_log)) { \ |
| - goto GTEST_CONCAT_TOKEN_(gtest_label_dfatal_, __LINE__); \ |
| - } \ |
| - } else \ |
| +#define GTEST_DFATAL_(statement, severity, matcher, fail) \ |
| + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ |
| + if (true) { \ |
| + ::base::test::MockLog gtest_log; \ |
| + ::net::test::ScopedDisableExitOnDFatal gtest_disable_exit; \ |
| + using ::testing::_; \ |
| + EXPECT_CALL(gtest_log, Log(_, _, _, _, _)) \ |
| + .WillRepeatedly(::testing::Return(false)); \ |
| + EXPECT_CALL(gtest_log, Log(::logging::LOG_##severity, _, _, _, matcher)) \ |
| + .Times(::testing::AtLeast(1)) \ |
| + .WillOnce(::testing::Return(false)); \ |
| + gtest_log.StartCapturingLogs(); \ |
| + { statement; } \ |
| + gtest_log.StopCapturingLogs(); \ |
| + if (!testing::Mock::VerifyAndClear(>est_log)) { \ |
| + goto GTEST_CONCAT_TOKEN_(gtest_label_dfatal_, __LINE__); \ |
| + } \ |
| + } else \ |
| GTEST_CONCAT_TOKEN_(gtest_label_dfatal_, __LINE__) : fail("") |
| // The EXPECT_DFATAL and ASSERT_DFATAL macros are lightweight |
| @@ -72,10 +72,10 @@ MATCHER(IsOk, |
| // DFATAL log message, whereas the other variants assume a regex. |
| #define EXPECT_DFATAL_WITH(statement, matcher) \ |
| - GTEST_DFATAL_(statement, matcher, GTEST_NONFATAL_FAILURE_) |
| + GTEST_DFATAL_(statement, DFATAL, matcher, GTEST_NONFATAL_FAILURE_) |
| #define ASSERT_DFATAL_WITH(statement, matcher) \ |
| - GTEST_DFATAL_(statement, matcher, GTEST_FATAL_FAILURE_) |
| + GTEST_DFATAL_(statement, DFATAL, matcher, GTEST_FATAL_FAILURE_) |
| #define EXPECT_DFATAL(statement, regex) \ |
| EXPECT_DFATAL_WITH(statement, ::testing::ContainsRegex(regex)) |
| @@ -113,6 +113,38 @@ MATCHER(IsOk, |
| #endif // NDEBUG |
| +// The EXPECT_DCHECK and ASSERT_DCHECK macros are similar to EXPECT_DFATAL and |
| +// ASSERT_DFATAL. Use them in conjunction with DCHECK that produces no-op in opt |
| +// build and LOG_DCHECK (FATAL) if DCHECK_IS_ON(). |
| + |
| +#if DCHECK_IS_ON() |
| + |
| +#define EXPECT_DCHECK(statement, regex) \ |
| + GTEST_DFATAL_(statement, DCHECK, ::testing::ContainsRegex(regex), \ |
| + GTEST_NONFATAL_FAILURE_) |
| +#define ASSERT_DCHECK(statement, regex) \ |
| + GTEST_DFATAL_(statement, DCHECK, ::testing::ContainsRegex(regex), \ |
| + GTEST_FATAL_FAILURE_) |
| + |
| +#else // DCHECK_IS_ON() |
| + |
| +#define EXPECT_DCHECK(statement, regex) \ |
| + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ |
| + if (true) { \ |
|
Paweł Hajdan Jr.
2016/08/05 14:35:07
Could you explain more this weird "if (true)" code
johnme
2016/08/05 16:57:37
I copy-pasted from EXPECT_DEBUG_DFATAL and ASSERT_
|
| + (void)(regex); \ |
| + statement; \ |
| + } else \ |
| + GTEST_NONFATAL_FAILURE_("") |
| +#define ASSERT_DCHECK(statement, regex) \ |
| + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ |
| + if (true) { \ |
| + (void)(regex); \ |
| + statement; \ |
| + } else \ |
| + GTEST_NONFATAL_FAILURE_("") |
| + |
| +#endif // DCHECK_IS_ON() |
| + |
| } // namespace test |
| } // namespace net |