| OLD | NEW |
| 1 // Copyright 2007, Google Inc. | 1 // Copyright 2007, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 EXPECT_FALSE(LogIsVisible(INFO)); | 531 EXPECT_FALSE(LogIsVisible(INFO)); |
| 532 EXPECT_FALSE(LogIsVisible(WARNING)); | 532 EXPECT_FALSE(LogIsVisible(WARNING)); |
| 533 } | 533 } |
| 534 | 534 |
| 535 TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) { | 535 TEST_F(LogIsVisibleTest, WorksWhenVerbosityIsWarning) { |
| 536 GMOCK_FLAG(verbose) = kWarningVerbosity; | 536 GMOCK_FLAG(verbose) = kWarningVerbosity; |
| 537 EXPECT_FALSE(LogIsVisible(INFO)); | 537 EXPECT_FALSE(LogIsVisible(INFO)); |
| 538 EXPECT_TRUE(LogIsVisible(WARNING)); | 538 EXPECT_TRUE(LogIsVisible(WARNING)); |
| 539 } | 539 } |
| 540 | 540 |
| 541 // TODO(wan@google.com): find a way to re-enable these tests. | 541 #if GTEST_HAS_STREAM_REDIRECTION_ |
| 542 #if 0 | |
| 543 | 542 |
| 544 // Tests the Log() function. | 543 // Tests the Log() function. |
| 545 | 544 |
| 546 // Verifies that Log() behaves correctly for the given verbosity level | 545 // Verifies that Log() behaves correctly for the given verbosity level |
| 547 // and log severity. | 546 // and log severity. |
| 548 void TestLogWithSeverity(const string& verbosity, LogSeverity severity, | 547 void TestLogWithSeverity(const string& verbosity, LogSeverity severity, |
| 549 bool should_print) { | 548 bool should_print) { |
| 550 const string old_flag = GMOCK_FLAG(verbose); | 549 const string old_flag = GMOCK_FLAG(verbose); |
| 551 GMOCK_FLAG(verbose) = verbosity; | 550 GMOCK_FLAG(verbose) = verbosity; |
| 552 CaptureTestStdout(); | 551 CaptureStdout(); |
| 553 Log(severity, "Test log.\n", 0); | 552 Log(severity, "Test log.\n", 0); |
| 554 if (should_print) { | 553 if (should_print) { |
| 555 EXPECT_PRED2(RE::FullMatch, | 554 EXPECT_THAT(GetCapturedStdout().c_str(), |
| 556 GetCapturedTestStdout(), | 555 ContainsRegex( |
| 557 severity == WARNING ? | 556 severity == WARNING ? |
| 558 "\nGMOCK WARNING:\nTest log\\.\nStack trace:\n[\\s\\S]*" : | 557 "^\nGMOCK WARNING:\nTest log\\.\nStack trace:\n" : |
| 559 "\nTest log\\.\nStack trace:\n[\\s\\S]*"); | 558 "^\nTest log\\.\nStack trace:\n")); |
| 560 } else { | 559 } else { |
| 561 EXPECT_EQ("", GetCapturedTestStdout()); | 560 EXPECT_STREQ("", GetCapturedStdout().c_str()); |
| 562 } | 561 } |
| 563 GMOCK_FLAG(verbose) = old_flag; | 562 GMOCK_FLAG(verbose) = old_flag; |
| 564 } | 563 } |
| 565 | 564 |
| 566 // Tests that when the stack_frames_to_skip parameter is negative, | 565 // Tests that when the stack_frames_to_skip parameter is negative, |
| 567 // Log() doesn't include the stack trace in the output. | 566 // Log() doesn't include the stack trace in the output. |
| 568 TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) { | 567 TEST(LogTest, NoStackTraceWhenStackFramesToSkipIsNegative) { |
| 569 GMOCK_FLAG(verbose) = kInfoVerbosity; | 568 GMOCK_FLAG(verbose) = kInfoVerbosity; |
| 570 CaptureTestStdout(); | 569 CaptureStdout(); |
| 571 Log(INFO, "Test log.\n", -1); | 570 Log(INFO, "Test log.\n", -1); |
| 572 EXPECT_EQ("\nTest log.\n", GetCapturedTestStdout()); | 571 EXPECT_STREQ("\nTest log.\n", GetCapturedStdout().c_str()); |
| 573 } | 572 } |
| 574 | 573 |
| 575 // Tests that in opt mode, a positive stack_frames_to_skip argument is | 574 // Tests that in opt mode, a positive stack_frames_to_skip argument is |
| 576 // treated as 0. | 575 // treated as 0. |
| 577 TEST(LogTest, NoSkippingStackFrameInOptMode) { | 576 TEST(LogTest, NoSkippingStackFrameInOptMode) { |
| 578 CaptureTestStdout(); | 577 CaptureStdout(); |
| 579 Log(WARNING, "Test log.\n", 100); | 578 Log(WARNING, "Test log.\n", 100); |
| 580 const string log = GetCapturedTestStdout(); | 579 const String log = GetCapturedStdout(); |
| 581 #ifdef NDEBUG | 580 #if defined(NDEBUG) && GTEST_GOOGLE3_MODE_ |
| 582 // In opt mode, no stack frame should be skipped. | 581 // In opt mode, no stack frame should be skipped. |
| 583 EXPECT_THAT(log, ContainsRegex("\nGMOCK WARNING:\n" | 582 EXPECT_THAT(log, ContainsRegex("\nGMOCK WARNING:\n" |
| 584 "Test log\\.\n" | 583 "Test log\\.\n" |
| 585 "Stack trace:\n" | 584 "Stack trace:\n" |
| 586 ".+")); | 585 ".+")); |
| 587 #else | 586 #else |
| 588 // In dbg mode, the stack frames should be skipped. | 587 // In dbg mode, the stack frames should be skipped. |
| 589 EXPECT_EQ("\nGMOCK WARNING:\n" | 588 EXPECT_STREQ("\nGMOCK WARNING:\n" |
| 590 "Test log.\n" | 589 "Test log.\n" |
| 591 "Stack trace:\n", log); | 590 "Stack trace:\n", log.c_str()); |
| 592 #endif // NDEBUG | 591 #endif |
| 593 } | 592 } |
| 594 | 593 |
| 595 // Tests that all logs are printed when the value of the | 594 // Tests that all logs are printed when the value of the |
| 596 // --gmock_verbose flag is "info". | 595 // --gmock_verbose flag is "info". |
| 597 TEST(LogTest, AllLogsArePrintedWhenVerbosityIsInfo) { | 596 TEST(LogTest, AllLogsArePrintedWhenVerbosityIsInfo) { |
| 598 TestLogWithSeverity(kInfoVerbosity, INFO, true); | 597 TestLogWithSeverity(kInfoVerbosity, INFO, true); |
| 599 TestLogWithSeverity(kInfoVerbosity, WARNING, true); | 598 TestLogWithSeverity(kInfoVerbosity, WARNING, true); |
| 600 } | 599 } |
| 601 | 600 |
| 602 // Tests that only warnings are printed when the value of the | 601 // Tests that only warnings are printed when the value of the |
| (...skipping 10 matching lines...) Expand all Loading... |
| 613 TestLogWithSeverity(kErrorVerbosity, WARNING, false); | 612 TestLogWithSeverity(kErrorVerbosity, WARNING, false); |
| 614 } | 613 } |
| 615 | 614 |
| 616 // Tests that only warnings are printed when the value of the | 615 // Tests that only warnings are printed when the value of the |
| 617 // --gmock_verbose flag is invalid. | 616 // --gmock_verbose flag is invalid. |
| 618 TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) { | 617 TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) { |
| 619 TestLogWithSeverity("invalid", INFO, false); | 618 TestLogWithSeverity("invalid", INFO, false); |
| 620 TestLogWithSeverity("invalid", WARNING, true); | 619 TestLogWithSeverity("invalid", WARNING, true); |
| 621 } | 620 } |
| 622 | 621 |
| 623 #endif // 0 | 622 #endif // GTEST_HAS_STREAM_REDIRECTION_ |
| 624 | 623 |
| 625 TEST(TypeTraitsTest, true_type) { | 624 TEST(TypeTraitsTest, true_type) { |
| 626 EXPECT_TRUE(true_type::value); | 625 EXPECT_TRUE(true_type::value); |
| 627 } | 626 } |
| 628 | 627 |
| 629 TEST(TypeTraitsTest, false_type) { | 628 TEST(TypeTraitsTest, false_type) { |
| 630 EXPECT_FALSE(false_type::value); | 629 EXPECT_FALSE(false_type::value); |
| 631 } | 630 } |
| 632 | 631 |
| 633 TEST(TypeTraitsTest, is_reference) { | 632 TEST(TypeTraitsTest, is_reference) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 650 } | 649 } |
| 651 | 650 |
| 652 TEST(TypeTraitsTest, remove_reference) { | 651 TEST(TypeTraitsTest, remove_reference) { |
| 653 EXPECT_TRUE((type_equals<char, remove_reference<char&>::type>::value)); | 652 EXPECT_TRUE((type_equals<char, remove_reference<char&>::type>::value)); |
| 654 EXPECT_TRUE((type_equals<const int, | 653 EXPECT_TRUE((type_equals<const int, |
| 655 remove_reference<const int&>::type>::value)); | 654 remove_reference<const int&>::type>::value)); |
| 656 EXPECT_TRUE((type_equals<int, remove_reference<int>::type>::value)); | 655 EXPECT_TRUE((type_equals<int, remove_reference<int>::type>::value)); |
| 657 EXPECT_TRUE((type_equals<double*, remove_reference<double*>::type>::value)); | 656 EXPECT_TRUE((type_equals<double*, remove_reference<double*>::type>::value)); |
| 658 } | 657 } |
| 659 | 658 |
| 660 // TODO(wan@google.com): find a way to re-enable these tests. | 659 #if GTEST_HAS_STREAM_REDIRECTION_ |
| 661 #if 0 | |
| 662 | 660 |
| 663 // Verifies that Log() behaves correctly for the given verbosity level | 661 // Verifies that Log() behaves correctly for the given verbosity level |
| 664 // and log severity. | 662 // and log severity. |
| 665 string GrabOutput(void(*logger)(), const char* verbosity) { | 663 String GrabOutput(void(*logger)(), const char* verbosity) { |
| 666 const string saved_flag = GMOCK_FLAG(verbose); | 664 const string saved_flag = GMOCK_FLAG(verbose); |
| 667 GMOCK_FLAG(verbose) = verbosity; | 665 GMOCK_FLAG(verbose) = verbosity; |
| 668 CaptureTestStdout(); | 666 CaptureStdout(); |
| 669 logger(); | 667 logger(); |
| 670 GMOCK_FLAG(verbose) = saved_flag; | 668 GMOCK_FLAG(verbose) = saved_flag; |
| 671 return GetCapturedTestStdout(); | 669 return GetCapturedStdout(); |
| 672 } | 670 } |
| 673 | 671 |
| 674 class DummyMock { | 672 class DummyMock { |
| 675 public: | 673 public: |
| 676 MOCK_METHOD0(TestMethod, void()); | 674 MOCK_METHOD0(TestMethod, void()); |
| 677 MOCK_METHOD1(TestMethodArg, void(int dummy)); | 675 MOCK_METHOD1(TestMethodArg, void(int dummy)); |
| 678 }; | 676 }; |
| 679 | 677 |
| 680 void ExpectCallLogger() { | 678 void ExpectCallLogger() { |
| 681 DummyMock mock; | 679 DummyMock mock; |
| 682 EXPECT_CALL(mock, TestMethod()); | 680 EXPECT_CALL(mock, TestMethod()); |
| 683 mock.TestMethod(); | 681 mock.TestMethod(); |
| 684 }; | 682 }; |
| 685 | 683 |
| 686 // Verifies that EXPECT_CALL logs if the --gmock_verbose flag is set to "info". | 684 // Verifies that EXPECT_CALL logs if the --gmock_verbose flag is set to "info". |
| 687 TEST(ExpectCallTest, LogsWhenVerbosityIsInfo) { | 685 TEST(ExpectCallTest, LogsWhenVerbosityIsInfo) { |
| 688 EXPECT_THAT(GrabOutput(ExpectCallLogger, kInfoVerbosity), | 686 EXPECT_THAT(GrabOutput(ExpectCallLogger, kInfoVerbosity), |
| 689 HasSubstr("EXPECT_CALL(mock, TestMethod())")); | 687 HasSubstr("EXPECT_CALL(mock, TestMethod())")); |
| 690 } | 688 } |
| 691 | 689 |
| 692 // Verifies that EXPECT_CALL doesn't log | 690 // Verifies that EXPECT_CALL doesn't log |
| 693 // if the --gmock_verbose flag is set to "warning". | 691 // if the --gmock_verbose flag is set to "warning". |
| 694 TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) { | 692 TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsWarning) { |
| 695 EXPECT_EQ("", GrabOutput(ExpectCallLogger, kWarningVerbosity)); | 693 EXPECT_STREQ("", GrabOutput(ExpectCallLogger, kWarningVerbosity).c_str()); |
| 696 } | 694 } |
| 697 | 695 |
| 698 // Verifies that EXPECT_CALL doesn't log | 696 // Verifies that EXPECT_CALL doesn't log |
| 699 // if the --gmock_verbose flag is set to "error". | 697 // if the --gmock_verbose flag is set to "error". |
| 700 TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) { | 698 TEST(ExpectCallTest, DoesNotLogWhenVerbosityIsError) { |
| 701 EXPECT_EQ("", GrabOutput(ExpectCallLogger, kErrorVerbosity)); | 699 EXPECT_STREQ("", GrabOutput(ExpectCallLogger, kErrorVerbosity).c_str()); |
| 702 } | 700 } |
| 703 | 701 |
| 704 void OnCallLogger() { | 702 void OnCallLogger() { |
| 705 DummyMock mock; | 703 DummyMock mock; |
| 706 ON_CALL(mock, TestMethod()); | 704 ON_CALL(mock, TestMethod()); |
| 707 }; | 705 }; |
| 708 | 706 |
| 709 // Verifies that ON_CALL logs if the --gmock_verbose flag is set to "info". | 707 // Verifies that ON_CALL logs if the --gmock_verbose flag is set to "info". |
| 710 TEST(OnCallTest, LogsWhenVerbosityIsInfo) { | 708 TEST(OnCallTest, LogsWhenVerbosityIsInfo) { |
| 711 EXPECT_THAT(GrabOutput(OnCallLogger, kInfoVerbosity), | 709 EXPECT_THAT(GrabOutput(OnCallLogger, kInfoVerbosity), |
| 712 HasSubstr("ON_CALL(mock, TestMethod())")); | 710 HasSubstr("ON_CALL(mock, TestMethod())")); |
| 713 } | 711 } |
| 714 | 712 |
| 715 // Verifies that ON_CALL doesn't log | 713 // Verifies that ON_CALL doesn't log |
| 716 // if the --gmock_verbose flag is set to "warning". | 714 // if the --gmock_verbose flag is set to "warning". |
| 717 TEST(OnCallTest, DoesNotLogWhenVerbosityIsWarning) { | 715 TEST(OnCallTest, DoesNotLogWhenVerbosityIsWarning) { |
| 718 EXPECT_EQ("", GrabOutput(OnCallLogger, kWarningVerbosity)); | 716 EXPECT_STREQ("", GrabOutput(OnCallLogger, kWarningVerbosity).c_str()); |
| 719 } | 717 } |
| 720 | 718 |
| 721 // Verifies that ON_CALL doesn't log if | 719 // Verifies that ON_CALL doesn't log if |
| 722 // the --gmock_verbose flag is set to "error". | 720 // the --gmock_verbose flag is set to "error". |
| 723 TEST(OnCallTest, DoesNotLogWhenVerbosityIsError) { | 721 TEST(OnCallTest, DoesNotLogWhenVerbosityIsError) { |
| 724 EXPECT_EQ("", GrabOutput(OnCallLogger, kErrorVerbosity)); | 722 EXPECT_STREQ("", GrabOutput(OnCallLogger, kErrorVerbosity).c_str()); |
| 725 } | 723 } |
| 726 | 724 |
| 727 void OnCallAnyArgumentLogger() { | 725 void OnCallAnyArgumentLogger() { |
| 728 DummyMock mock; | 726 DummyMock mock; |
| 729 ON_CALL(mock, TestMethodArg(_)); | 727 ON_CALL(mock, TestMethodArg(_)); |
| 730 } | 728 } |
| 731 | 729 |
| 732 // Verifies that ON_CALL prints provided _ argument. | 730 // Verifies that ON_CALL prints provided _ argument. |
| 733 TEST(OnCallTest, LogsAnythingArgument) { | 731 TEST(OnCallTest, LogsAnythingArgument) { |
| 734 EXPECT_THAT(GrabOutput(OnCallAnyArgumentLogger, kInfoVerbosity), | 732 EXPECT_THAT(GrabOutput(OnCallAnyArgumentLogger, kInfoVerbosity), |
| 735 HasSubstr("ON_CALL(mock, TestMethodArg(_)")); | 733 HasSubstr("ON_CALL(mock, TestMethodArg(_)")); |
| 736 } | 734 } |
| 737 | 735 |
| 738 #endif // 0 | 736 #endif // GTEST_HAS_STREAM_REDIRECTION_ |
| 739 | 737 |
| 740 // Tests ArrayEq(). | 738 // Tests ArrayEq(). |
| 741 | 739 |
| 742 TEST(ArrayEqTest, WorksForDegeneratedArrays) { | 740 TEST(ArrayEqTest, WorksForDegeneratedArrays) { |
| 743 EXPECT_TRUE(ArrayEq(5, 5L)); | 741 EXPECT_TRUE(ArrayEq(5, 5L)); |
| 744 EXPECT_FALSE(ArrayEq('a', 0)); | 742 EXPECT_FALSE(ArrayEq('a', 0)); |
| 745 } | 743 } |
| 746 | 744 |
| 747 TEST(ArrayEqTest, WorksForOneDimensionalArrays) { | 745 TEST(ArrayEqTest, WorksForOneDimensionalArrays) { |
| 748 const int a[] = { 0, 1 }; | 746 const int a[] = { 0, 1 }; |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 EXPECT_EQ(2, a3.begin()[2]); | 946 EXPECT_EQ(2, a3.begin()[2]); |
| 949 | 947 |
| 950 // Makes sure a1 and a3 aren't aliases. | 948 // Makes sure a1 and a3 aren't aliases. |
| 951 a1[0] = 3; | 949 a1[0] = 3; |
| 952 EXPECT_EQ(0, a3.begin()[0]); | 950 EXPECT_EQ(0, a3.begin()[0]); |
| 953 } | 951 } |
| 954 | 952 |
| 955 } // namespace | 953 } // namespace |
| 956 } // namespace internal | 954 } // namespace internal |
| 957 } // namespace testing | 955 } // namespace testing |
| OLD | NEW |