Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: net/test/gtest_util.h

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "net/test/scoped_disable_exit_on_dfatal.h" 10 #include "net/test/scoped_disable_exit_on_dfatal.h"
11 #include "net/test/scoped_mock_log.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_ if (true) { \
22 if (true) { \ 22 ::net::test::ScopedMockLog gtest_log; \
23 ::net::test::ScopedMockLog gtest_log; \ 23 ::net::test::ScopedDisableExitOnDFatal gtest_disable_exit; \
24 ::net::test::ScopedDisableExitOnDFatal gtest_disable_exit; \ 24 using ::testing::_; \
25 using ::testing::_; \ 25 EXPECT_CALL(gtest_log, Log(_, _, _, _, _)) \
26 EXPECT_CALL(gtest_log, Log(_, _, _, _, _)) \ 26 .WillRepeatedly(::testing::Return(false)); \
27 .WillRepeatedly(::testing::Return(false)); \ 27 EXPECT_CALL(gtest_log, Log(logging::LOG_DFATAL, _, _, _, matcher)) \
28 EXPECT_CALL(gtest_log, Log(logging::LOG_DFATAL, _, _, _, matcher)) \ 28 .Times(::testing::AtLeast(1)) \
29 .Times(::testing::AtLeast(1)) \ 29 .WillOnce(::testing::Return(false)); \
30 .WillOnce(::testing::Return(false)); \ 30 gtest_log.StartCapturingLogs(); \
31 gtest_log.StartCapturingLogs(); \ 31 { statement; } \
32 { statement; } \ 32 gtest_log.StopCapturingLogs(); \
33 gtest_log.StopCapturingLogs(); \ 33 if (!testing::Mock::VerifyAndClear(&gtest_log)) { \
34 if (!testing::Mock::VerifyAndClear(&gtest_log)) { \ 34 goto GTEST_CONCAT_TOKEN_(gtest_label_dfatal_, __LINE__); \
35 goto GTEST_CONCAT_TOKEN_(gtest_label_dfatal_, __LINE__); \ 35 } \
36 } \ 36 } \
37 } else \ 37 else GTEST_CONCAT_TOKEN_(gtest_label_dfatal_, __LINE__) : fail("")
38 GTEST_CONCAT_TOKEN_(gtest_label_dfatal_, __LINE__): \
39 fail("")
40 38
41 // The EXPECT_DFATAL and ASSERT_DFATAL macros are lightweight 39 // The EXPECT_DFATAL and ASSERT_DFATAL macros are lightweight
42 // alternatives to EXPECT_DEBUG_DEATH and ASSERT_DEBUG_DEATH. They 40 // alternatives to EXPECT_DEBUG_DEATH and ASSERT_DEBUG_DEATH. They
43 // are appropriate for testing that your code logs a message at the 41 // are appropriate for testing that your code logs a message at the
44 // DFATAL level. 42 // DFATAL level.
45 // 43 //
46 // Unlike EXPECT_DEBUG_DEATH and ASSERT_DEBUG_DEATH, these macros 44 // Unlike EXPECT_DEBUG_DEATH and ASSERT_DEBUG_DEATH, these macros
47 // execute the given statement in the current process, not a forked 45 // execute the given statement in the current process, not a forked
48 // one. This works because we disable exiting the program for 46 // one. This works because we disable exiting the program for
49 // LOG(DFATAL). This makes the tests run more quickly. 47 // LOG(DFATAL). This makes the tests run more quickly.
(...skipping 12 matching lines...) Expand all
62 60
63 #define ASSERT_DFATAL(statement, regex) \ 61 #define ASSERT_DFATAL(statement, regex) \
64 ASSERT_DFATAL_WITH(statement, ::testing::ContainsRegex(regex)) 62 ASSERT_DFATAL_WITH(statement, ::testing::ContainsRegex(regex))
65 63
66 // The EXPECT_DEBUG_DFATAL and ASSERT_DEBUG_DFATAL macros are similar to 64 // The EXPECT_DEBUG_DFATAL and ASSERT_DEBUG_DFATAL macros are similar to
67 // EXPECT_DFATAL and ASSERT_DFATAL. Use them in conjunction with DLOG(DFATAL) 65 // EXPECT_DFATAL and ASSERT_DFATAL. Use them in conjunction with DLOG(DFATAL)
68 // or similar macros that produce no-op in opt build and DFATAL in dbg build. 66 // or similar macros that produce no-op in opt build and DFATAL in dbg build.
69 67
70 #ifndef NDEBUG 68 #ifndef NDEBUG
71 69
72 #define EXPECT_DEBUG_DFATAL(statement, regex) \ 70 #define EXPECT_DEBUG_DFATAL(statement, regex) EXPECT_DFATAL(statement, regex)
73 EXPECT_DFATAL(statement, regex) 71 #define ASSERT_DEBUG_DFATAL(statement, regex) ASSERT_DFATAL(statement, regex)
74 #define ASSERT_DEBUG_DFATAL(statement, regex) \
75 ASSERT_DFATAL(statement, regex)
76 72
77 #else // NDEBUG 73 #else // NDEBUG
78 74
79 #define EXPECT_DEBUG_DFATAL(statement, regex) \ 75 #define EXPECT_DEBUG_DFATAL(statement, regex) \
80 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 76 GTEST_AMBIGUOUS_ELSE_BLOCKER_ if (true) { \
81 if (true) { \
82 (void)(regex); \ 77 (void)(regex); \
83 statement; \ 78 statement; \
84 } else \ 79 } \
85 GTEST_NONFATAL_FAILURE_("") 80 else GTEST_NONFATAL_FAILURE_("")
86 #define ASSERT_DEBUG_DFATAL(statement, regex) \ 81 #define ASSERT_DEBUG_DFATAL(statement, regex) \
87 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 82 GTEST_AMBIGUOUS_ELSE_BLOCKER_ if (true) { \
88 if (true) { \
89 (void)(regex); \ 83 (void)(regex); \
90 statement; \ 84 statement; \
91 } else \ 85 } \
92 GTEST_NONFATAL_FAILURE_("") 86 else GTEST_NONFATAL_FAILURE_("")
93 87
94 #endif // NDEBUG 88 #endif // NDEBUG
95 89
96 } // namespace test 90 } // namespace test
97 } // namespace net 91 } // namespace net
98 92
99 #endif // NET_QUIC_TEST_TOOLS_GTEST_UTIL_H_ 93 #endif // NET_QUIC_TEST_TOOLS_GTEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698