| 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_TEST_GTEST_UTIL_H_ | 7 #ifndef NET_TEST_GTEST_UTIL_H_ |
| 8 #define NET_TEST_GTEST_UTIL_H_ | 8 #define NET_TEST_GTEST_UTIL_H_ |
| 9 | 9 |
| 10 #include "base/test/mock_log.h" | 10 #include "base/test/mock_log.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 // Usage: EXPECT_THAT(foo(), IsOk()); | 31 // Usage: EXPECT_THAT(foo(), IsOk()); |
| 32 MATCHER(IsOk, | 32 MATCHER(IsOk, |
| 33 std::string(negation ? "not " : "") + net::ErrorToString(net::OK)) { | 33 std::string(negation ? "not " : "") + net::ErrorToString(net::OK)) { |
| 34 if (arg <= 0) | 34 if (arg <= 0) |
| 35 *result_listener << net::ErrorToString(arg); | 35 *result_listener << net::ErrorToString(arg); |
| 36 return arg == net::OK; | 36 return arg == net::OK; |
| 37 } | 37 } |
| 38 | 38 |
| 39 // Internal implementation for the EXPECT_DFATAL and ASSERT_DFATAL | 39 // Internal implementation for the EXPECT_DFATAL and ASSERT_DFATAL |
| 40 // macros. Do not use this directly. | 40 // macros. Do not use this directly. |
| 41 #define GTEST_DFATAL_(statement, matcher, fail) \ | 41 #define GTEST_DFATAL_(statement, matcher, fail) \ |
| 42 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ | 42 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ |
| 43 if (true) { \ | 43 if (true) { \ |
| 44 ::base::test::MockLog gtest_log; \ | 44 ::base::test::MockLog gtest_log; \ |
| 45 ::net::test::ScopedDisableExitOnDFatal gtest_disable_exit; \ | 45 ::net::test::ScopedDisableExitOnDFatal gtest_disable_exit; \ |
| 46 using ::testing::_; \ | 46 using ::testing::_; \ |
| 47 EXPECT_CALL(gtest_log, Log(_, _, _, _, _)) \ | 47 EXPECT_CALL(gtest_log, Log(_, _, _, _, _)).Times(::testing::AtLeast(0)); \ |
| 48 .WillRepeatedly(::testing::Return(false)); \ | 48 EXPECT_CALL(gtest_log, Log(logging::LOG_DFATAL, _, _, _, matcher)) \ |
| 49 EXPECT_CALL(gtest_log, Log(logging::LOG_DFATAL, _, _, _, matcher)) \ | 49 .Times(::testing::AtLeast(1)); \ |
| 50 .Times(::testing::AtLeast(1)) \ | 50 gtest_log.StartCapturingLogs(); \ |
| 51 .WillOnce(::testing::Return(false)); \ | 51 { statement; } \ |
| 52 gtest_log.StartCapturingLogs(); \ | 52 gtest_log.StopCapturingLogs(); \ |
| 53 { statement; } \ | 53 if (!testing::Mock::VerifyAndClear(>est_log)) { \ |
| 54 gtest_log.StopCapturingLogs(); \ | 54 goto GTEST_CONCAT_TOKEN_(gtest_label_dfatal_, __LINE__); \ |
| 55 if (!testing::Mock::VerifyAndClear(>est_log)) { \ | 55 } \ |
| 56 goto GTEST_CONCAT_TOKEN_(gtest_label_dfatal_, __LINE__); \ | 56 } else \ |
| 57 } \ | |
| 58 } else \ | |
| 59 GTEST_CONCAT_TOKEN_(gtest_label_dfatal_, __LINE__) : fail("") | 57 GTEST_CONCAT_TOKEN_(gtest_label_dfatal_, __LINE__) : fail("") |
| 60 | 58 |
| 61 // The EXPECT_DFATAL and ASSERT_DFATAL macros are lightweight | 59 // The EXPECT_DFATAL and ASSERT_DFATAL macros are lightweight |
| 62 // alternatives to EXPECT_DEBUG_DEATH and ASSERT_DEBUG_DEATH. They | 60 // alternatives to EXPECT_DEBUG_DEATH and ASSERT_DEBUG_DEATH. They |
| 63 // are appropriate for testing that your code logs a message at the | 61 // are appropriate for testing that your code logs a message at the |
| 64 // DFATAL level. | 62 // DFATAL level. |
| 65 // | 63 // |
| 66 // Unlike EXPECT_DEBUG_DEATH and ASSERT_DEBUG_DEATH, these macros | 64 // Unlike EXPECT_DEBUG_DEATH and ASSERT_DEBUG_DEATH, these macros |
| 67 // execute the given statement in the current process, not a forked | 65 // execute the given statement in the current process, not a forked |
| 68 // one. This works because we disable exiting the program for | 66 // one. This works because we disable exiting the program for |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 statement; \ | 108 statement; \ |
| 111 } else \ | 109 } else \ |
| 112 GTEST_NONFATAL_FAILURE_("") | 110 GTEST_NONFATAL_FAILURE_("") |
| 113 | 111 |
| 114 #endif // NDEBUG | 112 #endif // NDEBUG |
| 115 | 113 |
| 116 } // namespace test | 114 } // namespace test |
| 117 } // namespace net | 115 } // namespace net |
| 118 | 116 |
| 119 #endif // NET_TEST_GTEST_UTIL_H_ | 117 #endif // NET_TEST_GTEST_UTIL_H_ |
| OLD | NEW |