Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(270)

Unified Diff: net/test/gtest_util.h

Issue 2111973002: Add support for GCM subtypes to desktop Instance ID implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@iid9push
Patch Set: Address review comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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(&gtest_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(&gtest_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) { \
+ (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

Powered by Google App Engine
This is Rietveld 408576698