| OLD | NEW |
| 1 // Copyright 2008, Google Inc. | 1 // Copyright 2008, 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 | 50 |
| 51 namespace testing { | 51 namespace testing { |
| 52 namespace gmock_nice_strict_test { | 52 namespace gmock_nice_strict_test { |
| 53 | 53 |
| 54 using testing::internal::string; | 54 using testing::internal::string; |
| 55 using testing::GMOCK_FLAG(verbose); | 55 using testing::GMOCK_FLAG(verbose); |
| 56 using testing::HasSubstr; | 56 using testing::HasSubstr; |
| 57 using testing::NiceMock; | 57 using testing::NiceMock; |
| 58 using testing::StrictMock; | 58 using testing::StrictMock; |
| 59 | 59 |
| 60 #if GTEST_HAS_STREAM_REDIRECTION_ |
| 61 using testing::internal::CaptureStdout; |
| 62 using testing::internal::GetCapturedStdout; |
| 63 #endif // GTEST_HAS_STREAM_REDIRECTION_ |
| 64 |
| 60 // Defines some mock classes needed by the tests. | 65 // Defines some mock classes needed by the tests. |
| 61 | 66 |
| 62 class Foo { | 67 class Foo { |
| 63 public: | 68 public: |
| 64 virtual ~Foo() {} | 69 virtual ~Foo() {} |
| 65 | 70 |
| 66 virtual void DoThis() = 0; | 71 virtual void DoThis() = 0; |
| 67 virtual int DoThat(bool flag) = 0; | 72 virtual int DoThat(bool flag) = 0; |
| 68 }; | 73 }; |
| 69 | 74 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 95 | 100 |
| 96 MOCK_METHOD0(This, int()); | 101 MOCK_METHOD0(This, int()); |
| 97 MOCK_METHOD2(That, string(int, bool)); | 102 MOCK_METHOD2(That, string(int, bool)); |
| 98 | 103 |
| 99 private: | 104 private: |
| 100 string str_; | 105 string str_; |
| 101 | 106 |
| 102 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockBar); | 107 GTEST_DISALLOW_COPY_AND_ASSIGN_(MockBar); |
| 103 }; | 108 }; |
| 104 | 109 |
| 105 // TODO(wan@google.com): find a way to re-enable these tests. | 110 #if GTEST_HAS_STREAM_REDIRECTION_ |
| 106 #if 0 | |
| 107 | 111 |
| 108 // Tests that a nice mock generates no warning for uninteresting calls. | 112 // Tests that a nice mock generates no warning for uninteresting calls. |
| 109 TEST(NiceMockTest, NoWarningForUninterestingCall) { | 113 TEST(NiceMockTest, NoWarningForUninterestingCall) { |
| 110 NiceMock<MockFoo> nice_foo; | 114 NiceMock<MockFoo> nice_foo; |
| 111 | 115 |
| 112 CaptureTestStdout(); | 116 CaptureStdout(); |
| 113 nice_foo.DoThis(); | 117 nice_foo.DoThis(); |
| 114 nice_foo.DoThat(true); | 118 nice_foo.DoThat(true); |
| 115 EXPECT_EQ("", GetCapturedTestStdout()); | 119 EXPECT_STREQ("", GetCapturedStdout().c_str()); |
| 116 } | 120 } |
| 117 | 121 |
| 118 // Tests that a nice mock generates no warning for uninteresting calls | 122 // Tests that a nice mock generates no warning for uninteresting calls |
| 119 // that delete the mock object. | 123 // that delete the mock object. |
| 120 TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) { | 124 TEST(NiceMockTest, NoWarningForUninterestingCallAfterDeath) { |
| 121 NiceMock<MockFoo>* const nice_foo = new NiceMock<MockFoo>; | 125 NiceMock<MockFoo>* const nice_foo = new NiceMock<MockFoo>; |
| 122 | 126 |
| 123 ON_CALL(*nice_foo, DoThis()) | 127 ON_CALL(*nice_foo, DoThis()) |
| 124 .WillByDefault(Invoke(nice_foo, &MockFoo::Delete)); | 128 .WillByDefault(Invoke(nice_foo, &MockFoo::Delete)); |
| 125 | 129 |
| 126 CaptureTestStdout(); | 130 CaptureStdout(); |
| 127 nice_foo->DoThis(); | 131 nice_foo->DoThis(); |
| 128 EXPECT_EQ("", GetCapturedTestStdout()); | 132 EXPECT_STREQ("", GetCapturedStdout().c_str()); |
| 129 } | 133 } |
| 130 | 134 |
| 131 // Tests that a nice mock generates informational logs for | 135 // Tests that a nice mock generates informational logs for |
| 132 // uninteresting calls. | 136 // uninteresting calls. |
| 133 TEST(NiceMockTest, InfoForUninterestingCall) { | 137 TEST(NiceMockTest, InfoForUninterestingCall) { |
| 134 NiceMock<MockFoo> nice_foo; | 138 NiceMock<MockFoo> nice_foo; |
| 135 | 139 |
| 136 GMOCK_FLAG(verbose) = "info"; | 140 GMOCK_FLAG(verbose) = "info"; |
| 137 CaptureTestStdout(); | 141 CaptureStdout(); |
| 138 nice_foo.DoThis(); | 142 nice_foo.DoThis(); |
| 139 EXPECT_THAT(GetCapturedTestStdout(), | 143 EXPECT_THAT(GetCapturedStdout(), |
| 140 HasSubstr("Uninteresting mock function call")); | 144 HasSubstr("Uninteresting mock function call")); |
| 141 | 145 |
| 142 CaptureTestStdout(); | 146 CaptureStdout(); |
| 143 nice_foo.DoThat(true); | 147 nice_foo.DoThat(true); |
| 144 EXPECT_THAT(GetCapturedTestStdout(), | 148 EXPECT_THAT(GetCapturedStdout(), |
| 145 HasSubstr("Uninteresting mock function call")); | 149 HasSubstr("Uninteresting mock function call")); |
| 146 } | 150 } |
| 147 | 151 |
| 148 #endif // 0 | 152 #endif // GTEST_HAS_STREAM_REDIRECTION_ |
| 149 | 153 |
| 150 // Tests that a nice mock allows expected calls. | 154 // Tests that a nice mock allows expected calls. |
| 151 TEST(NiceMockTest, AllowsExpectedCall) { | 155 TEST(NiceMockTest, AllowsExpectedCall) { |
| 152 NiceMock<MockFoo> nice_foo; | 156 NiceMock<MockFoo> nice_foo; |
| 153 | 157 |
| 154 EXPECT_CALL(nice_foo, DoThis()); | 158 EXPECT_CALL(nice_foo, DoThis()); |
| 155 nice_foo.DoThis(); | 159 nice_foo.DoThis(); |
| 156 } | 160 } |
| 157 | 161 |
| 158 // Tests that an unexpected call on a nice mock fails. | 162 // Tests that an unexpected call on a nice mock fails. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 // causes the program to crash there, for reasons unclear to us yet. | 273 // causes the program to crash there, for reasons unclear to us yet. |
| 270 TEST(StrictMockTest, AcceptsClassNamedMock) { | 274 TEST(StrictMockTest, AcceptsClassNamedMock) { |
| 271 StrictMock< ::Mock> strict; | 275 StrictMock< ::Mock> strict; |
| 272 EXPECT_CALL(strict, DoThis()); | 276 EXPECT_CALL(strict, DoThis()); |
| 273 strict.DoThis(); | 277 strict.DoThis(); |
| 274 } | 278 } |
| 275 #endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE | 279 #endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE |
| 276 | 280 |
| 277 } // namespace gmock_nice_strict_test | 281 } // namespace gmock_nice_strict_test |
| 278 } // namespace testing | 282 } // namespace testing |
| OLD | NEW |