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"), | |
hans
2017/04/20 17:28:39
Since you're changing this anyway, s/catched/caugh
| |
523 _)); | |
524 EXPECT_CALL( | |
525 handler_b, | |
526 HandleLogAssert( | |
527 _, _, base::StringPiece("Second assert must be catched by handler_b"), | |
528 _)); | |
529 EXPECT_CALL( | |
530 handler_a, | |
531 HandleLogAssert( | |
522 _, _, | 532 _, _, |
523 base::StringPiece( | 533 base::StringPiece("Last assert must be catched by handler_a again"), |
524 "Check failed: false. First assert must be catched by handler_a"), | |
525 _)); | 534 _)); |
526 EXPECT_CALL( | |
527 handler_b, | |
528 HandleLogAssert(_, _, | |
529 base::StringPiece("Check failed: false. Second assert " | |
530 "must be catched by handler_b"), | |
531 _)); | |
532 EXPECT_CALL( | |
533 handler_a, | |
534 HandleLogAssert(_, _, | |
535 base::StringPiece("Check failed: false. Last assert " | |
536 "must be catched by handler_a again"), | |
537 _)); | |
538 | 535 |
539 logging::ScopedLogAssertHandler scoped_handler_a(base::Bind( | 536 logging::ScopedLogAssertHandler scoped_handler_a(base::Bind( |
540 &MockLogAssertHandler::HandleLogAssert, base::Unretained(&handler_a))); | 537 &MockLogAssertHandler::HandleLogAssert, base::Unretained(&handler_a))); |
541 | 538 |
542 CHECK(false) << "First assert must be catched by handler_a"; | 539 LOG(FATAL) << "First assert must be catched by handler_a"; |
543 | 540 |
544 { | 541 { |
545 logging::ScopedLogAssertHandler scoped_handler_b(base::Bind( | 542 logging::ScopedLogAssertHandler scoped_handler_b(base::Bind( |
546 &MockLogAssertHandler::HandleLogAssert, base::Unretained(&handler_b))); | 543 &MockLogAssertHandler::HandleLogAssert, base::Unretained(&handler_b))); |
547 CHECK(false) << "Second assert must be catched by handler_b"; | 544 LOG(FATAL) << "Second assert must be catched by handler_b"; |
548 } | 545 } |
549 | 546 |
550 CHECK(false) << "Last assert must be catched by handler_a again"; | 547 LOG(FATAL) << "Last assert must be catched by handler_a again"; |
551 } | 548 } |
552 | 549 |
553 // Test that defining an operator<< for a type in a namespace doesn't prevent | 550 // Test that defining an operator<< for a type in a namespace doesn't prevent |
554 // other code in that namespace from calling the operator<<(ostream, wstring) | 551 // other code in that namespace from calling the operator<<(ostream, wstring) |
555 // defined by logging.h. This can fail if operator<<(ostream, wstring) can't be | 552 // defined by logging.h. This can fail if operator<<(ostream, wstring) can't be |
556 // found by ADL, since defining another operator<< prevents name lookup from | 553 // found by ADL, since defining another operator<< prevents name lookup from |
557 // looking in the global namespace. | 554 // looking in the global namespace. |
558 namespace nested_test { | 555 namespace nested_test { |
559 class Streamable {}; | 556 class Streamable {}; |
560 ALLOW_UNUSED_TYPE std::ostream& operator<<(std::ostream& out, | 557 ALLOW_UNUSED_TYPE std::ostream& operator<<(std::ostream& out, |
561 const Streamable&) { | 558 const Streamable&) { |
562 return out << "Streamable"; | 559 return out << "Streamable"; |
563 } | 560 } |
564 TEST_F(LoggingTest, StreamingWstringFindsCorrectOperator) { | 561 TEST_F(LoggingTest, StreamingWstringFindsCorrectOperator) { |
565 std::wstring wstr = L"Hello World"; | 562 std::wstring wstr = L"Hello World"; |
566 std::ostringstream ostr; | 563 std::ostringstream ostr; |
567 ostr << wstr; | 564 ostr << wstr; |
568 EXPECT_EQ("Hello World", ostr.str()); | 565 EXPECT_EQ("Hello World", ostr.str()); |
569 } | 566 } |
570 } // namespace nested_test | 567 } // namespace nested_test |
571 | 568 |
572 } // namespace | 569 } // namespace |
573 | 570 |
574 } // namespace logging | 571 } // namespace logging |
OLD | NEW |