Index: base/logging_unittest.cc |
diff --git a/base/logging_unittest.cc b/base/logging_unittest.cc |
index 8a20c54fb4c605734bf45c4b8bb582a76276e104..87a357ab781e4bacfe52f27285ea37516b0cc2ef 100644 |
--- a/base/logging_unittest.cc |
+++ b/base/logging_unittest.cc |
@@ -217,6 +217,13 @@ TEST_F(LoggingTest, DcheckStreamsAreLazy) { |
#endif |
} |
+void DcheckEmptyFunction1() { |
+ // Provide a body so that Release builds do not cause the compiler to |
+ // optimize DcheckEmptyFunction1 and DcheckEmptyFunction2 as a single |
+ // function, which breaks the Dcheck tests below. |
+ LOG(INFO) << "DcheckEmptyFunction1"; |
+} |
+void DcheckEmptyFunction2() {} |
Nico
2016/11/23 18:09:26
nit: newline after this
|
TEST_F(LoggingTest, Dcheck) { |
#if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
// Release build. |
@@ -258,6 +265,26 @@ TEST_F(LoggingTest, Dcheck) { |
EXPECT_EQ(0, log_sink_call_count); |
DCHECK_EQ(Animal::DOG, Animal::CAT); |
EXPECT_EQ(DCHECK_IS_ON() ? 1 : 0, log_sink_call_count); |
+ |
+ // Test DCHECK on functions and function pointers. |
+ void (*fp1)() = DcheckEmptyFunction1; |
+ void (*fp2)() = DcheckEmptyFunction2; |
+ void (*fp3)() = DcheckEmptyFunction1; |
+ DCHECK_EQ(fp1, fp3); |
+ EXPECT_EQ(DCHECK_IS_ON() ? 1 : 0, log_sink_call_count); |
Nico
2016/11/23 18:09:26
This is super confusing – it looks like fp1 and fp
|
+ DCHECK_EQ(fp1, fp2); |
+ EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, log_sink_call_count); |
+ struct MemberFunctions { |
+ static void MemberFunction1(){}; |
+ static void TestDCHECK() { |
+ void (*fp)() = MemberFunction1; |
+ DCHECK_EQ(fp, MemberFunction1); |
+ EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, log_sink_call_count); |
+ DCHECK_EQ(fp, TestDCHECK); |
+ EXPECT_EQ(DCHECK_IS_ON() ? 3 : 0, log_sink_call_count); |
+ } |
+ }; |
+ MemberFunctions::TestDCHECK(); |
} |
TEST_F(LoggingTest, DcheckReleaseBehavior) { |