OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/string_piece.h" | 10 #include "base/strings/string_piece.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 class MockLogAssertHandler { | 76 class MockLogAssertHandler { |
77 public: | 77 public: |
78 MOCK_METHOD4( | 78 MOCK_METHOD4( |
79 HandleLogAssert, | 79 HandleLogAssert, |
80 void(const char*, int, const base::StringPiece, const base::StringPiece)); | 80 void(const char*, int, const base::StringPiece, const base::StringPiece)); |
81 }; | 81 }; |
82 | 82 |
83 TEST_F(LoggingTest, BasicLogging) { | 83 TEST_F(LoggingTest, BasicLogging) { |
84 MockLogSource mock_log_source; | 84 MockLogSource mock_log_source; |
85 EXPECT_CALL(mock_log_source, Log()) | 85 EXPECT_CALL(mock_log_source, Log()) |
86 .Times(DCHECK_IS_ON() ? 16 : 8) | 86 .Times(DCHECK_IS_ON() || DVLOG_IS_ON() ? 16 : 8) |
87 .WillRepeatedly(Return("log message")); | 87 .WillRepeatedly(Return("log message")); |
88 | 88 |
89 SetMinLogLevel(LOG_INFO); | 89 SetMinLogLevel(LOG_INFO); |
90 | 90 |
91 EXPECT_TRUE(LOG_IS_ON(INFO)); | 91 EXPECT_TRUE(LOG_IS_ON(INFO)); |
92 EXPECT_TRUE((DCHECK_IS_ON() != 0) == DLOG_IS_ON(INFO)); | 92 EXPECT_TRUE((DCHECK_IS_ON() != 0) == DLOG_IS_ON(INFO)); |
93 EXPECT_TRUE(VLOG_IS_ON(0)); | 93 EXPECT_TRUE(VLOG_IS_ON(0)); |
94 | 94 |
95 LOG(INFO) << mock_log_source.Log(); | 95 LOG(INFO) << mock_log_source.Log(); |
96 LOG_IF(INFO, true) << mock_log_source.Log(); | 96 LOG_IF(INFO, true) << mock_log_source.Log(); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 ASSERT_NE(0u, child_crash_addr_1); | 364 ASSERT_NE(0u, child_crash_addr_1); |
365 ASSERT_NE(0u, child_crash_addr_2); | 365 ASSERT_NE(0u, child_crash_addr_2); |
366 ASSERT_NE(0u, child_crash_addr_3); | 366 ASSERT_NE(0u, child_crash_addr_3); |
367 ASSERT_NE(child_crash_addr_1, child_crash_addr_2); | 367 ASSERT_NE(child_crash_addr_1, child_crash_addr_2); |
368 ASSERT_NE(child_crash_addr_1, child_crash_addr_3); | 368 ASSERT_NE(child_crash_addr_1, child_crash_addr_3); |
369 ASSERT_NE(child_crash_addr_2, child_crash_addr_3); | 369 ASSERT_NE(child_crash_addr_2, child_crash_addr_3); |
370 } | 370 } |
371 #endif // OS_POSIX | 371 #endif // OS_POSIX |
372 | 372 |
373 TEST_F(LoggingTest, DebugLoggingReleaseBehavior) { | 373 TEST_F(LoggingTest, DebugLoggingReleaseBehavior) { |
374 #if DCHECK_IS_ON() | 374 #if DCHECK_IS_ON() || DVLOG_IS_ON() |
375 int debug_only_variable = 1; | 375 int debug_only_variable = 1; |
376 #endif | 376 #endif |
377 // These should avoid emitting references to |debug_only_variable| | 377 // These should avoid emitting references to |debug_only_variable| |
378 // in release mode. | 378 // in release mode. |
379 DLOG_IF(INFO, debug_only_variable) << "test"; | 379 DLOG_IF(INFO, debug_only_variable) << "test"; |
380 DLOG_ASSERT(debug_only_variable) << "test"; | 380 DLOG_ASSERT(debug_only_variable) << "test"; |
381 DPLOG_IF(INFO, debug_only_variable) << "test"; | 381 DPLOG_IF(INFO, debug_only_variable) << "test"; |
382 DVLOG_IF(1, debug_only_variable) << "test"; | 382 DVLOG_IF(1, debug_only_variable) << "test"; |
383 } | 383 } |
384 | 384 |
385 TEST_F(LoggingTest, DcheckStreamsAreLazy) { | 385 TEST_F(LoggingTest, DcheckStreamsAreLazy) { |
386 MockLogSource mock_log_source; | 386 MockLogSource mock_log_source; |
387 EXPECT_CALL(mock_log_source, Log()).Times(0); | 387 EXPECT_CALL(mock_log_source, Log()).Times(0); |
388 #if DCHECK_IS_ON() | 388 #if DCHECK_IS_ON() || DVLOG_IS_ON() |
389 DCHECK(true) << mock_log_source.Log(); | 389 DCHECK(true) << mock_log_source.Log(); |
390 DCHECK_EQ(0, 0) << mock_log_source.Log(); | 390 DCHECK_EQ(0, 0) << mock_log_source.Log(); |
391 #else | 391 #else |
392 DCHECK(mock_log_source.Log()) << mock_log_source.Log(); | 392 DCHECK(mock_log_source.Log()) << mock_log_source.Log(); |
393 DPCHECK(mock_log_source.Log()) << mock_log_source.Log(); | 393 DPCHECK(mock_log_source.Log()) << mock_log_source.Log(); |
394 DCHECK_EQ(0, 0) << mock_log_source.Log(); | 394 DCHECK_EQ(0, 0) << mock_log_source.Log(); |
395 DCHECK_EQ(mock_log_source.Log(), static_cast<const char*>(NULL)) | 395 DCHECK_EQ(mock_log_source.Log(), static_cast<const char*>(NULL)) |
396 << mock_log_source.Log(); | 396 << mock_log_source.Log(); |
397 #endif | 397 #endif |
398 } | 398 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 DCHECK_EQ(mp1, &MemberFunctions::MemberFunction1); | 472 DCHECK_EQ(mp1, &MemberFunctions::MemberFunction1); |
473 EXPECT_EQ(0, g_log_sink_call_count); | 473 EXPECT_EQ(0, g_log_sink_call_count); |
474 DCHECK_EQ(mp2, &MemberFunctions::MemberFunction2); | 474 DCHECK_EQ(mp2, &MemberFunctions::MemberFunction2); |
475 EXPECT_EQ(0, g_log_sink_call_count); | 475 EXPECT_EQ(0, g_log_sink_call_count); |
476 DCHECK_EQ(fp1, fp2); | 476 DCHECK_EQ(fp1, fp2); |
477 EXPECT_EQ(DCHECK_IS_ON() ? 1 : 0, g_log_sink_call_count); | 477 EXPECT_EQ(DCHECK_IS_ON() ? 1 : 0, g_log_sink_call_count); |
478 DCHECK_EQ(mp2, &MemberFunctions::MemberFunction1); | 478 DCHECK_EQ(mp2, &MemberFunctions::MemberFunction1); |
479 EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, g_log_sink_call_count); | 479 EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, g_log_sink_call_count); |
480 } | 480 } |
481 | 481 |
| 482 TEST_F(LoggingTest, Dvlog) { |
| 483 #if defined(NDEBUG) && !defined(DVLOG_ALWAYS_ON) |
| 484 // Release build. |
| 485 EXPECT_FALSE(DVLOG_IS_ON()); |
| 486 #elif defined(NDEBUG) && defined(DVLOG_ALWAYS_ON) |
| 487 // Release build with real DVLOGs |
| 488 EXPECT_TRUE(DVLOG_IS_ON()); |
| 489 #else |
| 490 // Debug build. |
| 491 EXPECT_TRUE(DVLOG_IS_ON()); |
| 492 #endif |
| 493 } |
| 494 |
482 TEST_F(LoggingTest, DcheckReleaseBehavior) { | 495 TEST_F(LoggingTest, DcheckReleaseBehavior) { |
483 int some_variable = 1; | 496 int some_variable = 1; |
484 // These should still reference |some_variable| so we don't get | 497 // These should still reference |some_variable| so we don't get |
485 // unused variable warnings. | 498 // unused variable warnings. |
486 DCHECK(some_variable) << "test"; | 499 DCHECK(some_variable) << "test"; |
487 DPCHECK(some_variable) << "test"; | 500 DPCHECK(some_variable) << "test"; |
488 DCHECK_EQ(some_variable, 1) << "test"; | 501 DCHECK_EQ(some_variable, 1) << "test"; |
489 } | 502 } |
490 | 503 |
491 TEST_F(LoggingTest, DCheckEqStatements) { | 504 TEST_F(LoggingTest, DCheckEqStatements) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 std::wstring wstr = L"Hello World"; | 577 std::wstring wstr = L"Hello World"; |
565 std::ostringstream ostr; | 578 std::ostringstream ostr; |
566 ostr << wstr; | 579 ostr << wstr; |
567 EXPECT_EQ("Hello World", ostr.str()); | 580 EXPECT_EQ("Hello World", ostr.str()); |
568 } | 581 } |
569 } // namespace nested_test | 582 } // namespace nested_test |
570 | 583 |
571 } // namespace | 584 } // namespace |
572 | 585 |
573 } // namespace logging | 586 } // namespace logging |
OLD | NEW |