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

Side by Side Diff: base/logging_unittest.cc

Issue 2638763004: Report CHECK/DCHECK to test launcher summary output. (Closed)
Patch Set: Fix segmentation fault on android. Created 3 years, 8 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/logging.h"
6 #include "base/bind.h"
7 #include "base/callback.h"
5 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
6 #include "base/logging.h"
7 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_piece.h"
8 11
9 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
11 14
12 #if defined(OS_POSIX) 15 #if defined(OS_POSIX)
13 #include <signal.h> 16 #include <signal.h>
14 #include <unistd.h> 17 #include <unistd.h>
15 #include "base/posix/eintr_wrapper.h" 18 #include "base/posix/eintr_wrapper.h"
16 #endif // OS_POSIX 19 #endif // OS_POSIX
17 20
18 #if defined(OS_LINUX) || defined(OS_ANDROID) 21 #if defined(OS_LINUX) || defined(OS_ANDROID)
19 #include <ucontext.h> 22 #include <ucontext.h>
20 #endif 23 #endif
21 24
22 #if defined(OS_WIN) 25 #if defined(OS_WIN)
23 #include <excpt.h> 26 #include <excpt.h>
24 #include <windows.h> 27 #include <windows.h>
25 #endif // OS_WIN 28 #endif // OS_WIN
26 29
27 namespace logging { 30 namespace logging {
28 31
29 namespace { 32 namespace {
30 33
31 using ::testing::Return; 34 using ::testing::Return;
32 35
33 // Needs to be global since log assert handlers can't maintain state. 36 // Needs to be global since log assert handlers can't maintain state.
34 int log_sink_call_count = 0; 37 int log_sink_call_count = 0;
35 38
36 #if !defined(OFFICIAL_BUILD) || defined(DCHECK_ALWAYS_ON) || !defined(NDEBUG) 39 #if !defined(OFFICIAL_BUILD) || defined(DCHECK_ALWAYS_ON) || !defined(NDEBUG)
37 void LogSink(const std::string& str) { 40 void LogSink(const char* file,
brettw 2017/04/17 22:20:34 Now that we have a stack, is there a test for the
alex-ac 2017/04/18 06:34:21 Done.
41 int line,
42 const base::StringPiece message,
43 const base::StringPiece stack_trace) {
38 ++log_sink_call_count; 44 ++log_sink_call_count;
39 } 45 }
40 #endif 46 #endif
41 47
42 // Class to make sure any manipulations we do to the min log level are 48 // Class to make sure any manipulations we do to the min log level are
43 // contained (i.e., do not affect other unit tests). 49 // contained (i.e., do not affect other unit tests).
44 class LogStateSaver { 50 class LogStateSaver {
45 public: 51 public:
46 LogStateSaver() : old_min_log_level_(GetMinLogLevel()) {} 52 LogStateSaver() : old_min_log_level_(GetMinLogLevel()) {}
47 53
48 ~LogStateSaver() { 54 ~LogStateSaver() {
49 SetMinLogLevel(old_min_log_level_); 55 SetMinLogLevel(old_min_log_level_);
50 SetLogAssertHandler(NULL);
51 log_sink_call_count = 0; 56 log_sink_call_count = 0;
52 } 57 }
53 58
54 private: 59 private:
55 int old_min_log_level_; 60 int old_min_log_level_;
56 61
57 DISALLOW_COPY_AND_ASSIGN(LogStateSaver); 62 DISALLOW_COPY_AND_ASSIGN(LogStateSaver);
58 }; 63 };
59 64
60 class LoggingTest : public testing::Test { 65 class LoggingTest : public testing::Test {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 #define MAYBE_CheckStreamsAreLazy DISABLED_CheckStreamsAreLazy 195 #define MAYBE_CheckStreamsAreLazy DISABLED_CheckStreamsAreLazy
191 #else 196 #else
192 #define MAYBE_CheckStreamsAreLazy CheckStreamsAreLazy 197 #define MAYBE_CheckStreamsAreLazy CheckStreamsAreLazy
193 #endif 198 #endif
194 TEST_F(LoggingTest, MAYBE_CheckStreamsAreLazy) { 199 TEST_F(LoggingTest, MAYBE_CheckStreamsAreLazy) {
195 MockLogSource mock_log_source, uncalled_mock_log_source; 200 MockLogSource mock_log_source, uncalled_mock_log_source;
196 EXPECT_CALL(mock_log_source, Log()).Times(8). 201 EXPECT_CALL(mock_log_source, Log()).Times(8).
197 WillRepeatedly(Return("check message")); 202 WillRepeatedly(Return("check message"));
198 EXPECT_CALL(uncalled_mock_log_source, Log()).Times(0); 203 EXPECT_CALL(uncalled_mock_log_source, Log()).Times(0);
199 204
200 SetLogAssertHandler(&LogSink); 205 ScopedLogAssertHandler scoped_assert_handler(base::Bind(LogSink));
201 206
202 CHECK(mock_log_source.Log()) << uncalled_mock_log_source.Log(); 207 CHECK(mock_log_source.Log()) << uncalled_mock_log_source.Log();
203 PCHECK(!mock_log_source.Log()) << mock_log_source.Log(); 208 PCHECK(!mock_log_source.Log()) << mock_log_source.Log();
204 CHECK_EQ(mock_log_source.Log(), mock_log_source.Log()) 209 CHECK_EQ(mock_log_source.Log(), mock_log_source.Log())
205 << uncalled_mock_log_source.Log(); 210 << uncalled_mock_log_source.Log();
206 CHECK_NE(mock_log_source.Log(), mock_log_source.Log()) 211 CHECK_NE(mock_log_source.Log(), mock_log_source.Log())
207 << mock_log_source.Log(); 212 << mock_log_source.Log();
208 } 213 }
209 214
210 #endif 215 #endif
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 #else 403 #else
399 #define MAYBE_Dcheck Dcheck 404 #define MAYBE_Dcheck Dcheck
400 #endif 405 #endif
401 TEST_F(LoggingTest, MAYBE_Dcheck) { 406 TEST_F(LoggingTest, MAYBE_Dcheck) {
402 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 407 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
403 // Release build. 408 // Release build.
404 EXPECT_FALSE(DCHECK_IS_ON()); 409 EXPECT_FALSE(DCHECK_IS_ON());
405 EXPECT_FALSE(DLOG_IS_ON(DCHECK)); 410 EXPECT_FALSE(DLOG_IS_ON(DCHECK));
406 #elif defined(NDEBUG) && defined(DCHECK_ALWAYS_ON) 411 #elif defined(NDEBUG) && defined(DCHECK_ALWAYS_ON)
407 // Release build with real DCHECKS. 412 // Release build with real DCHECKS.
408 SetLogAssertHandler(&LogSink); 413 ScopedLogAssertHandler scoped_assert_handler(base::Bind(LogSink));
409 EXPECT_TRUE(DCHECK_IS_ON()); 414 EXPECT_TRUE(DCHECK_IS_ON());
410 EXPECT_TRUE(DLOG_IS_ON(DCHECK)); 415 EXPECT_TRUE(DLOG_IS_ON(DCHECK));
411 #else 416 #else
412 // Debug build. 417 // Debug build.
413 SetLogAssertHandler(&LogSink); 418 ScopedLogAssertHandler scoped_assert_handler(base::Bind(LogSink));
414 EXPECT_TRUE(DCHECK_IS_ON()); 419 EXPECT_TRUE(DCHECK_IS_ON());
415 EXPECT_TRUE(DLOG_IS_ON(DCHECK)); 420 EXPECT_TRUE(DLOG_IS_ON(DCHECK));
416 #endif 421 #endif
417 422
418 EXPECT_EQ(0, log_sink_call_count); 423 EXPECT_EQ(0, log_sink_call_count);
419 DCHECK(false); 424 DCHECK(false);
420 EXPECT_EQ(DCHECK_IS_ON() ? 1 : 0, log_sink_call_count); 425 EXPECT_EQ(DCHECK_IS_ON() ? 1 : 0, log_sink_call_count);
421 DPCHECK(false); 426 DPCHECK(false);
422 EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, log_sink_call_count); 427 EXPECT_EQ(DCHECK_IS_ON() ? 2 : 0, log_sink_call_count);
423 DCHECK_EQ(0, 1); 428 DCHECK_EQ(0, 1);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 std::wstring wstr = L"Hello World"; 519 std::wstring wstr = L"Hello World";
515 std::ostringstream ostr; 520 std::ostringstream ostr;
516 ostr << wstr; 521 ostr << wstr;
517 EXPECT_EQ("Hello World", ostr.str()); 522 EXPECT_EQ("Hello World", ostr.str());
518 } 523 }
519 } // namespace nested_test 524 } // namespace nested_test
520 525
521 } // namespace 526 } // namespace
522 527
523 } // namespace logging 528 } // namespace logging
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698