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

Side by Side Diff: base/logging_unittest.cc

Issue 2638763004: Report CHECK/DCHECK to test launcher summary output. (Closed)
Patch Set: Use LazyIsntance and stl stack. Created 3 years, 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "base/bind.h"
6 #include "base/callback.h"
5 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
6 #include "base/logging.h" 8 #include "base/logging.h"
7 #include "base/macros.h" 9 #include "base/macros.h"
8 10
9 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
11 13
12 namespace logging { 14 namespace logging {
13 15
14 namespace { 16 namespace {
15 17
16 using ::testing::Return; 18 using ::testing::Return;
17 19
18 // Needs to be global since log assert handlers can't maintain state. 20 // Needs to be global since log assert handlers can't maintain state.
19 int log_sink_call_count = 0; 21 int log_sink_call_count = 0;
20 22
21 #if !defined(OFFICIAL_BUILD) || defined(DCHECK_ALWAYS_ON) || !defined(NDEBUG) 23 #if !defined(OFFICIAL_BUILD) || defined(DCHECK_ALWAYS_ON) || !defined(NDEBUG)
22 void LogSink(const std::string& str) { 24 void LogSink(const char* file,
25 int line,
26 const base::StringPiece& message,
27 const base::StringPiece& stack_trace) {
23 ++log_sink_call_count; 28 ++log_sink_call_count;
24 } 29 }
25 #endif 30 #endif
26 31
27 // Class to make sure any manipulations we do to the min log level are 32 // Class to make sure any manipulations we do to the min log level are
28 // contained (i.e., do not affect other unit tests). 33 // contained (i.e., do not affect other unit tests).
29 class LogStateSaver { 34 class LogStateSaver {
30 public: 35 public:
31 LogStateSaver() : old_min_log_level_(GetMinLogLevel()) {} 36 LogStateSaver() : old_min_log_level_(GetMinLogLevel()) {}
32 37
33 ~LogStateSaver() { 38 ~LogStateSaver() {
34 SetMinLogLevel(old_min_log_level_); 39 SetMinLogLevel(old_min_log_level_);
35 SetLogAssertHandler(NULL);
36 log_sink_call_count = 0; 40 log_sink_call_count = 0;
37 } 41 }
38 42
39 private: 43 private:
40 int old_min_log_level_; 44 int old_min_log_level_;
41 45
42 DISALLOW_COPY_AND_ASSIGN(LogStateSaver); 46 DISALLOW_COPY_AND_ASSIGN(LogStateSaver);
43 }; 47 };
44 48
45 class LoggingTest : public testing::Test { 49 class LoggingTest : public testing::Test {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 175
172 // Official builds have CHECKs directly call BreakDebugger. 176 // Official builds have CHECKs directly call BreakDebugger.
173 #if !defined(OFFICIAL_BUILD) 177 #if !defined(OFFICIAL_BUILD)
174 178
175 TEST_F(LoggingTest, CheckStreamsAreLazy) { 179 TEST_F(LoggingTest, CheckStreamsAreLazy) {
176 MockLogSource mock_log_source, uncalled_mock_log_source; 180 MockLogSource mock_log_source, uncalled_mock_log_source;
177 EXPECT_CALL(mock_log_source, Log()).Times(8). 181 EXPECT_CALL(mock_log_source, Log()).Times(8).
178 WillRepeatedly(Return("check message")); 182 WillRepeatedly(Return("check message"));
179 EXPECT_CALL(uncalled_mock_log_source, Log()).Times(0); 183 EXPECT_CALL(uncalled_mock_log_source, Log()).Times(0);
180 184
181 SetLogAssertHandler(&LogSink); 185 ScopedLogAssertHandler scoped_assert_handler(base::Bind(LogSink));
182 186
183 CHECK(mock_log_source.Log()) << uncalled_mock_log_source.Log(); 187 CHECK(mock_log_source.Log()) << uncalled_mock_log_source.Log();
184 PCHECK(!mock_log_source.Log()) << mock_log_source.Log(); 188 PCHECK(!mock_log_source.Log()) << mock_log_source.Log();
185 CHECK_EQ(mock_log_source.Log(), mock_log_source.Log()) 189 CHECK_EQ(mock_log_source.Log(), mock_log_source.Log())
186 << uncalled_mock_log_source.Log(); 190 << uncalled_mock_log_source.Log();
187 CHECK_NE(mock_log_source.Log(), mock_log_source.Log()) 191 CHECK_NE(mock_log_source.Log(), mock_log_source.Log())
188 << mock_log_source.Log(); 192 << mock_log_source.Log();
189 } 193 }
190 194
191 #endif 195 #endif
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 229 }
226 void DcheckEmptyFunction2() {} 230 void DcheckEmptyFunction2() {}
227 231
228 TEST_F(LoggingTest, Dcheck) { 232 TEST_F(LoggingTest, Dcheck) {
229 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 233 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
230 // Release build. 234 // Release build.
231 EXPECT_FALSE(DCHECK_IS_ON()); 235 EXPECT_FALSE(DCHECK_IS_ON());
232 EXPECT_FALSE(DLOG_IS_ON(DCHECK)); 236 EXPECT_FALSE(DLOG_IS_ON(DCHECK));
233 #elif defined(NDEBUG) && defined(DCHECK_ALWAYS_ON) 237 #elif defined(NDEBUG) && defined(DCHECK_ALWAYS_ON)
234 // Release build with real DCHECKS. 238 // Release build with real DCHECKS.
235 SetLogAssertHandler(&LogSink); 239 ScopedLogAssertHandler scoped_assert_handler(base::Bind(LogSink));
236 EXPECT_TRUE(DCHECK_IS_ON()); 240 EXPECT_TRUE(DCHECK_IS_ON());
237 EXPECT_TRUE(DLOG_IS_ON(DCHECK)); 241 EXPECT_TRUE(DLOG_IS_ON(DCHECK));
238 #else 242 #else
239 // Debug build. 243 // Debug build.
240 SetLogAssertHandler(&LogSink); 244 ScopedLogAssertHandler scoped_assert_handler(base::Bind(LogSink));
241 EXPECT_TRUE(DCHECK_IS_ON()); 245 EXPECT_TRUE(DCHECK_IS_ON());
242 EXPECT_TRUE(DLOG_IS_ON(DCHECK)); 246 EXPECT_TRUE(DLOG_IS_ON(DCHECK));
243 #endif 247 #endif
244 248
245 EXPECT_EQ(0, log_sink_call_count); 249 EXPECT_EQ(0, log_sink_call_count);
246 DCHECK(false); 250 DCHECK(false);
247 EXPECT_EQ(DCHECK_IS_ON() ? 1 : 0, log_sink_call_count); 251 EXPECT_EQ(DCHECK_IS_ON() ? 1 : 0, log_sink_call_count);
248 DPCHECK(false); 252 DPCHECK(false);
249 EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, log_sink_call_count); 253 EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, log_sink_call_count);
250 DCHECK_EQ(0, 1); 254 DCHECK_EQ(0, 1);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 std::wstring wstr = L"Hello World"; 345 std::wstring wstr = L"Hello World";
342 std::ostringstream ostr; 346 std::ostringstream ostr;
343 ostr << wstr; 347 ostr << wstr;
344 EXPECT_EQ("Hello World", ostr.str()); 348 EXPECT_EQ("Hello World", ostr.str());
345 } 349 }
346 } // namespace nested_test 350 } // namespace nested_test
347 351
348 } // namespace 352 } // namespace
349 353
350 } // namespace logging 354 } // namespace logging
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698