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

Unified Diff: base/logging_unittest.cc

Issue 2515283002: logging: Provide a specific MakeCheckOpValueString overload for functions (Closed)
Patch Set: Use actual member functions Created 4 years, 1 month 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
« no previous file with comments | « base/logging.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/logging_unittest.cc
diff --git a/base/logging_unittest.cc b/base/logging_unittest.cc
index 8a20c54fb4c605734bf45c4b8bb582a76276e104..f41cce2f43b390fa9603a14f3f689fe87d0dcb33 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,31 @@ 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;
+ struct MemberFunctions {
+ void MemberFunction1() {
+ // See the comment in DcheckEmptyFunction1().
+ LOG(INFO) << "Do not merge with MemberFunction2.";
+ }
+ void MemberFunction2() {}
+ };
+ void (MemberFunctions::*mp1)() = &MemberFunctions::MemberFunction1;
+ void (MemberFunctions::*mp2)() = &MemberFunctions::MemberFunction2;
+ void (*fp1)() = DcheckEmptyFunction1;
+ void (*fp2)() = DcheckEmptyFunction2;
+ void (*fp3)() = DcheckEmptyFunction1;
+ DCHECK_EQ(fp1, fp3);
+ EXPECT_EQ(0, log_sink_call_count);
+ DCHECK_EQ(mp1, &MemberFunctions::MemberFunction1);
+ EXPECT_EQ(0, log_sink_call_count);
+ DCHECK_EQ(mp2, &MemberFunctions::MemberFunction2);
+ EXPECT_EQ(0, log_sink_call_count);
+ DCHECK_EQ(fp1, fp2);
+ EXPECT_EQ(DCHECK_IS_ON() ? 1 : 0, log_sink_call_count);
+ DCHECK_EQ(mp2, &MemberFunctions::MemberFunction1);
+ EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, log_sink_call_count);
}
TEST_F(LoggingTest, DcheckReleaseBehavior) {
« no previous file with comments | « base/logging.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698