OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Testing utilities that extend gtest. | 5 // Testing utilities that extend gtest. |
6 | 6 |
7 #ifndef NET_QUIC_TEST_TOOLS_GTEST_UTIL_H_ | 7 #ifndef NET_QUIC_TEST_TOOLS_GTEST_UTIL_H_ |
8 #define NET_QUIC_TEST_TOOLS_GTEST_UTIL_H_ | 8 #define NET_QUIC_TEST_TOOLS_GTEST_UTIL_H_ |
9 | 9 |
| 10 #include "base/test/mock_log.h" |
10 #include "net/test/scoped_disable_exit_on_dfatal.h" | 11 #include "net/test/scoped_disable_exit_on_dfatal.h" |
11 #include "net/test/scoped_mock_log.h" | |
12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace net { | 15 namespace net { |
16 namespace test { | 16 namespace test { |
17 | 17 |
18 // Internal implementation for the EXPECT_DFATAL and ASSERT_DFATAL | 18 // Internal implementation for the EXPECT_DFATAL and ASSERT_DFATAL |
19 // macros. Do not use this directly. | 19 // macros. Do not use this directly. |
20 #define GTEST_DFATAL_(statement, matcher, fail) \ | 20 #define GTEST_DFATAL_(statement, matcher, fail) \ |
21 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ | 21 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ |
22 if (true) { \ | 22 if (true) { \ |
23 ::net::test::ScopedMockLog gtest_log; \ | 23 ::base::test::MockLog gtest_log; \ |
24 ::net::test::ScopedDisableExitOnDFatal gtest_disable_exit; \ | 24 ::net::test::ScopedDisableExitOnDFatal gtest_disable_exit; \ |
25 using ::testing::_; \ | 25 using ::testing::_; \ |
26 EXPECT_CALL(gtest_log, Log(_, _, _, _, _)) \ | 26 EXPECT_CALL(gtest_log, Log(_, _, _, _, _)) \ |
27 .WillRepeatedly(::testing::Return(false)); \ | 27 .WillRepeatedly(::testing::Return(false)); \ |
28 EXPECT_CALL(gtest_log, Log(logging::LOG_DFATAL, _, _, _, matcher)) \ | 28 EXPECT_CALL(gtest_log, Log(logging::LOG_DFATAL, _, _, _, matcher)) \ |
29 .Times(::testing::AtLeast(1)) \ | 29 .Times(::testing::AtLeast(1)) \ |
30 .WillOnce(::testing::Return(false)); \ | 30 .WillOnce(::testing::Return(false)); \ |
31 gtest_log.StartCapturingLogs(); \ | 31 gtest_log.StartCapturingLogs(); \ |
32 { statement; } \ | 32 { statement; } \ |
33 gtest_log.StopCapturingLogs(); \ | 33 gtest_log.StopCapturingLogs(); \ |
34 if (!testing::Mock::VerifyAndClear(>est_log)) { \ | 34 if (!testing::Mock::VerifyAndClear(>est_log)) { \ |
35 goto GTEST_CONCAT_TOKEN_(gtest_label_dfatal_, __LINE__); \ | 35 goto GTEST_CONCAT_TOKEN_(gtest_label_dfatal_, __LINE__); \ |
36 } \ | 36 } \ |
37 } else \ | 37 } else \ |
38 GTEST_CONCAT_TOKEN_(gtest_label_dfatal_, __LINE__): \ | 38 GTEST_CONCAT_TOKEN_(gtest_label_dfatal_, __LINE__) : fail("") |
39 fail("") | |
40 | 39 |
41 // The EXPECT_DFATAL and ASSERT_DFATAL macros are lightweight | 40 // The EXPECT_DFATAL and ASSERT_DFATAL macros are lightweight |
42 // alternatives to EXPECT_DEBUG_DEATH and ASSERT_DEBUG_DEATH. They | 41 // alternatives to EXPECT_DEBUG_DEATH and ASSERT_DEBUG_DEATH. They |
43 // are appropriate for testing that your code logs a message at the | 42 // are appropriate for testing that your code logs a message at the |
44 // DFATAL level. | 43 // DFATAL level. |
45 // | 44 // |
46 // Unlike EXPECT_DEBUG_DEATH and ASSERT_DEBUG_DEATH, these macros | 45 // Unlike EXPECT_DEBUG_DEATH and ASSERT_DEBUG_DEATH, these macros |
47 // execute the given statement in the current process, not a forked | 46 // execute the given statement in the current process, not a forked |
48 // one. This works because we disable exiting the program for | 47 // one. This works because we disable exiting the program for |
49 // LOG(DFATAL). This makes the tests run more quickly. | 48 // LOG(DFATAL). This makes the tests run more quickly. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 statement; \ | 89 statement; \ |
91 } else \ | 90 } else \ |
92 GTEST_NONFATAL_FAILURE_("") | 91 GTEST_NONFATAL_FAILURE_("") |
93 | 92 |
94 #endif // NDEBUG | 93 #endif // NDEBUG |
95 | 94 |
96 } // namespace test | 95 } // namespace test |
97 } // namespace net | 96 } // namespace net |
98 | 97 |
99 #endif // NET_QUIC_TEST_TOOLS_GTEST_UTIL_H_ | 98 #endif // NET_QUIC_TEST_TOOLS_GTEST_UTIL_H_ |
OLD | NEW |