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" |
| 11 #include "net/base/net_errors.h" |
11 #include "net/test/scoped_disable_exit_on_dfatal.h" | 12 #include "net/test/scoped_disable_exit_on_dfatal.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
14 | 15 |
15 namespace net { | 16 namespace net { |
16 namespace test { | 17 namespace test { |
17 | 18 |
| 19 // A GMock matcher that checks whether the argument is the expected net::Error. |
| 20 // On failure, the expected and actual net::Error names will be printed. |
| 21 // Usage: EXPECT_THAT(foo(), IsError(net::ERR_INVALID_ARGUMENT)); |
| 22 MATCHER_P(IsError, |
| 23 expected, |
| 24 std::string(negation ? "not " : "") + net::ErrorToString(expected)) { |
| 25 if (arg <= 0) |
| 26 *result_listener << net::ErrorToString(arg); |
| 27 return arg == expected; |
| 28 } |
| 29 |
| 30 // Shorthand for IsError(net::OK). |
| 31 // Usage: EXPECT_THAT(foo(), IsOk()); |
| 32 MATCHER(IsOk, |
| 33 std::string(negation ? "not " : "") + net::ErrorToString(net::OK)) { |
| 34 if (arg <= 0) |
| 35 *result_listener << net::ErrorToString(arg); |
| 36 return arg == net::OK; |
| 37 } |
| 38 |
18 // Internal implementation for the EXPECT_DFATAL and ASSERT_DFATAL | 39 // Internal implementation for the EXPECT_DFATAL and ASSERT_DFATAL |
19 // macros. Do not use this directly. | 40 // macros. Do not use this directly. |
20 #define GTEST_DFATAL_(statement, matcher, fail) \ | 41 #define GTEST_DFATAL_(statement, matcher, fail) \ |
21 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ | 42 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ |
22 if (true) { \ | 43 if (true) { \ |
23 ::base::test::MockLog gtest_log; \ | 44 ::base::test::MockLog gtest_log; \ |
24 ::net::test::ScopedDisableExitOnDFatal gtest_disable_exit; \ | 45 ::net::test::ScopedDisableExitOnDFatal gtest_disable_exit; \ |
25 using ::testing::_; \ | 46 using ::testing::_; \ |
26 EXPECT_CALL(gtest_log, Log(_, _, _, _, _)) \ | 47 EXPECT_CALL(gtest_log, Log(_, _, _, _, _)) \ |
27 .WillRepeatedly(::testing::Return(false)); \ | 48 .WillRepeatedly(::testing::Return(false)); \ |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 statement; \ | 110 statement; \ |
90 } else \ | 111 } else \ |
91 GTEST_NONFATAL_FAILURE_("") | 112 GTEST_NONFATAL_FAILURE_("") |
92 | 113 |
93 #endif // NDEBUG | 114 #endif // NDEBUG |
94 | 115 |
95 } // namespace test | 116 } // namespace test |
96 } // namespace net | 117 } // namespace net |
97 | 118 |
98 #endif // NET_TEST_GTEST_UTIL_H_ | 119 #endif // NET_TEST_GTEST_UTIL_H_ |
OLD | NEW |