Chromium Code Reviews| Index: base/logging_unittest.cc |
| diff --git a/base/logging_unittest.cc b/base/logging_unittest.cc |
| index 8a20c54fb4c605734bf45c4b8bb582a76276e104..5671626060fa6d6ac172dea3758196c4ca1a0371 100644 |
| --- a/base/logging_unittest.cc |
| +++ b/base/logging_unittest.cc |
| @@ -217,6 +217,14 @@ 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() {} |
| + |
| TEST_F(LoggingTest, Dcheck) { |
| #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) |
| // Release build. |
| @@ -258,6 +266,27 @@ 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. |
| + log_sink_call_count = 0; |
| + void (*fp1)() = DcheckEmptyFunction1; |
| + void (*fp2)() = DcheckEmptyFunction2; |
| + void (*fp3)() = DcheckEmptyFunction1; |
| + DCHECK_EQ(fp1, fp3); |
| + EXPECT_EQ(DCHECK_IS_ON() ? 0 : 0, log_sink_call_count); |
|
Nico
2016/11/23 18:21:10
Err, replace `DCHECK_IS_ON() ? 0 : 0` with `0`? :-
Raphael Kubo da Costa (rakuco)
2016/11/23 18:58:09
Brain fart :(
|
| + DCHECK_EQ(fp1, fp2); |
| + EXPECT_EQ(DCHECK_IS_ON() ? 1 : 0, log_sink_call_count); |
| + struct MemberFunctions { |
| + static void MemberFunction1(){}; |
|
Nico
2016/11/23 18:21:10
Actually, this isn't a member function, this is a
Raphael Kubo da Costa (rakuco)
2016/11/23 18:58:09
That works too; the reason I went for static funct
|
| + static void TestDCHECK() { |
| + void (*fp)() = MemberFunction1; |
| + DCHECK_EQ(fp, MemberFunction1); |
| + EXPECT_EQ(DCHECK_IS_ON() ? 1 : 0, log_sink_call_count); |
| + DCHECK_EQ(fp, TestDCHECK); |
| + EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, log_sink_call_count); |
| + } |
| + }; |
| + MemberFunctions::TestDCHECK(); |
| } |
| TEST_F(LoggingTest, DcheckReleaseBehavior) { |