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 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 CHECK_EQ(false, true); // Unreached. | 512 CHECK_EQ(false, true); // Unreached. |
513 } | 513 } |
514 | 514 |
515 TEST_F(LoggingTest, NestedLogAssertHandlers) { | 515 TEST_F(LoggingTest, NestedLogAssertHandlers) { |
516 ::testing::InSequence dummy; | 516 ::testing::InSequence dummy; |
517 ::testing::StrictMock<MockLogAssertHandler> handler_a, handler_b; | 517 ::testing::StrictMock<MockLogAssertHandler> handler_a, handler_b; |
518 | 518 |
519 EXPECT_CALL( | 519 EXPECT_CALL( |
520 handler_a, | 520 handler_a, |
521 HandleLogAssert( | 521 HandleLogAssert( |
522 _, _, base::StringPiece("First assert must be catched by handler_a"), | 522 _, _, base::StringPiece("First assert must be caught by handler_a"), |
523 _)); | 523 _)); |
524 EXPECT_CALL( | 524 EXPECT_CALL( |
525 handler_b, | 525 handler_b, |
526 HandleLogAssert( | 526 HandleLogAssert( |
527 _, _, base::StringPiece("Second assert must be catched by handler_b"), | 527 _, _, base::StringPiece("Second assert must be caught by handler_b"), |
528 _)); | 528 _)); |
529 EXPECT_CALL( | 529 EXPECT_CALL( |
530 handler_a, | 530 handler_a, |
531 HandleLogAssert( | 531 HandleLogAssert( |
532 _, _, | 532 _, _, |
533 base::StringPiece("Last assert must be catched by handler_a again"), | 533 base::StringPiece("Last assert must be caught by handler_a again"), |
534 _)); | 534 _)); |
535 | 535 |
536 logging::ScopedLogAssertHandler scoped_handler_a(base::Bind( | 536 logging::ScopedLogAssertHandler scoped_handler_a(base::Bind( |
537 &MockLogAssertHandler::HandleLogAssert, base::Unretained(&handler_a))); | 537 &MockLogAssertHandler::HandleLogAssert, base::Unretained(&handler_a))); |
538 | 538 |
539 LOG(FATAL) << "First assert must be catched by handler_a"; | 539 // Using LOG(FATAL) rather than CHECK(false) here since log messages aren't |
| 540 // preserved for CHECKs in official builds. |
| 541 LOG(FATAL) << "First assert must be caught by handler_a"; |
540 | 542 |
541 { | 543 { |
542 logging::ScopedLogAssertHandler scoped_handler_b(base::Bind( | 544 logging::ScopedLogAssertHandler scoped_handler_b(base::Bind( |
543 &MockLogAssertHandler::HandleLogAssert, base::Unretained(&handler_b))); | 545 &MockLogAssertHandler::HandleLogAssert, base::Unretained(&handler_b))); |
544 LOG(FATAL) << "Second assert must be catched by handler_b"; | 546 LOG(FATAL) << "Second assert must be caught by handler_b"; |
545 } | 547 } |
546 | 548 |
547 LOG(FATAL) << "Last assert must be catched by handler_a again"; | 549 LOG(FATAL) << "Last assert must be caught by handler_a again"; |
548 } | 550 } |
549 | 551 |
550 // Test that defining an operator<< for a type in a namespace doesn't prevent | 552 // Test that defining an operator<< for a type in a namespace doesn't prevent |
551 // other code in that namespace from calling the operator<<(ostream, wstring) | 553 // other code in that namespace from calling the operator<<(ostream, wstring) |
552 // defined by logging.h. This can fail if operator<<(ostream, wstring) can't be | 554 // defined by logging.h. This can fail if operator<<(ostream, wstring) can't be |
553 // found by ADL, since defining another operator<< prevents name lookup from | 555 // found by ADL, since defining another operator<< prevents name lookup from |
554 // looking in the global namespace. | 556 // looking in the global namespace. |
555 namespace nested_test { | 557 namespace nested_test { |
556 class Streamable {}; | 558 class Streamable {}; |
557 ALLOW_UNUSED_TYPE std::ostream& operator<<(std::ostream& out, | 559 ALLOW_UNUSED_TYPE std::ostream& operator<<(std::ostream& out, |
558 const Streamable&) { | 560 const Streamable&) { |
559 return out << "Streamable"; | 561 return out << "Streamable"; |
560 } | 562 } |
561 TEST_F(LoggingTest, StreamingWstringFindsCorrectOperator) { | 563 TEST_F(LoggingTest, StreamingWstringFindsCorrectOperator) { |
562 std::wstring wstr = L"Hello World"; | 564 std::wstring wstr = L"Hello World"; |
563 std::ostringstream ostr; | 565 std::ostringstream ostr; |
564 ostr << wstr; | 566 ostr << wstr; |
565 EXPECT_EQ("Hello World", ostr.str()); | 567 EXPECT_EQ("Hello World", ostr.str()); |
566 } | 568 } |
567 } // namespace nested_test | 569 } // namespace nested_test |
568 | 570 |
569 } // namespace | 571 } // namespace |
570 | 572 |
571 } // namespace logging | 573 } // namespace logging |
OLD | NEW |